jac*_*per 3 facebook-oauth asp.net-core-mvc .net-core asp.net-core-2.0 .net-core-2.0
我正在尝试使用dot-net core 2.0设置Facebook身份验证,但是在我的ExternalLoginCallbackAsync方法中,作为响应,我一直得到null,因为我已经遵循了文档,到目前为止,这是我已经完成的工作:
在启动文件中的ConfigureServices中:
services.AddAuthentication(
options => options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme);
services.AddAuthentication().AddFacebook(
f => {
f.AppId = Configuration["facebook-app-id"];
f.AppSecret = Configuration["facebook-app-secret"];
});
Run Code Online (Sandbox Code Playgroud)
在我的登录控制器中:
public IActionResult ExternalLogin(string provider)
{
var authProperties = new AuthenticationProperties
{
RedirectUri = Url.Action("ExternalLoginCallbackAsync", "Login")
};
return Challenge(authProperties,provider);
}
Run Code Online (Sandbox Code Playgroud)
在我的ExternalLoginCallbackAsync方法中
var info = await _signInManager.GetExternalLoginInfoAsync();
Run Code Online (Sandbox Code Playgroud)
有什么提示我为什么总是空吗?
谢谢
我按照Lasse Vabe Rolstad的建议查看了SignInManager代码,对我来说,auth属性中缺少密钥,因此我必须像这样手动添加它:
var authProperties = new AuthenticationProperties
{
RedirectUri = Url.Action("ExternalLoginCallbackAsync", "Login"),
Items = { new KeyValuePair<string, string>("LoginProvider",provider) }
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1670 次 |
| 最近记录: |