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

查看:88
本文介绍了GetExternalLoginInfoAsync返回空的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返回空的dotnet core 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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