GetExternalLoginInfoAsync 返回 null dotnet core 2.0 [英] GetExternalLoginInfoAsync returns null dotnet core 2.0

查看:35
本文介绍了GetExternalLoginInfoAsync 返回 null dotnet core 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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:

在我的启动文件中的ConfigureServices中:

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"];
});

在我的登录控制器中:

public IActionResult ExternalLogin(string provider)
        {

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

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

in my ExternalLoginCallbackAsync method when 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 返回 null dotnet core 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆