gpt4 book ai didi

asp.net-core-mvc - GetExternalLoginInfoAsync 返回 null dotnet core 2.0

转载 作者:行者123 更新时间:2023-12-02 21:10:50 25 4
gpt4 key购买 nike

我正在尝试使用 dot-net core 2.0 设置 Facebook 身份验证,但在我的ExternalLoginCallbackAsync 方法中,我总是得到 null 作为响应,我已遵循文档,到目前为止,这就是我所做的:

in my ConfigureServices in the startup file:

services.AddAuthentication(
options => options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme);

services.AddAuthentication().AddFacebook(
f => {
f.AppId = Configuration["facebook-app-id"];
f.AppSecret = Configuration["facebook-app-secret"];
});

在我的登录 Controller 中:

public IActionResult ExternalLogin(string provider)
{

var authProperties = new AuthenticationProperties
{
RedirectUri = Url.Action("ExternalLoginCallbackAsync", "Login")
};
return Challenge(authProperties,provider);
}

在我的ExternalLoginCallbackAsync方法中当我这样做的时候

var info = await _signInManager.GetExternalLoginInfoAsync();

任何提示为什么我总是得到 null?

谢谢

最佳答案

我按照 Lasse Vabe Rolstad 的建议查看了 SignInManager 代码,对我来说,身份验证属性中缺少一个 key ,因此我必须像这样手动添加它:

 var authProperties = new AuthenticationProperties
{
RedirectUri = Url.Action("ExternalLoginCallbackAsync", "Login"),
Items = { new KeyValuePair<string, string>("LoginProvider",provider) }
};

关于asp.net-core-mvc - GetExternalLoginInfoAsync 返回 null dotnet core 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45852188/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com