问题描述
我正在尝试使用dot-net core 2.0设置Facebook身份验证,但是在我的ExternalLoginCallbackAsync方法中,作为响应,我一直得到null,我已经按照文档进行了操作,到目前为止,这是我已经完成的事情:
I'm trying to setup Facebook authentication with dot-net core 2.0, but in my ExternalLoginCallbackAsync method, I'm always getting null as a response I have followed the documentation and so far this is what I've done:
services.AddAuthentication(
options => options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme);
services.AddAuthentication().AddFacebook(
f => {
f.AppId = Configuration["facebook-app-id"];
f.AppSecret = Configuration["facebook-app-secret"];
});
在我的登录控制器中:
public IActionResult ExternalLogin(string provider)
{
var authProperties = new AuthenticationProperties
{
RedirectUri = Url.Action("ExternalLoginCallbackAsync", "Login")
};
return Challenge(authProperties,provider);
}
在我执行我的ExternalLoginCallbackAsync方法
时
in my ExternalLoginCallbackAsync methodwhen I do
var info = await _signInManager.GetExternalLoginInfoAsync();
任何提示为什么我总是空值?
any hint why am I always getting null?
感谢
推荐答案
我查看了Lasse Vabe Rolstad建议的SignInManager代码,对我来说, auth属性,因此我必须像这样手动添加它:
I looked at the SignInManager code as Lasse Vabe Rolstad suggested and for me, a key was missing in the auth properties so I had to add it manually like this:
var authProperties = new AuthenticationProperties
{
RedirectUri = Url.Action("ExternalLoginCallbackAsync", "Login"),
Items = { new KeyValuePair<string, string>("LoginProvider",provider) }
};
这篇关于GetExternalLoginInfoAsync返回空的dotnet core 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!