GetExternalLoginInfoAsync returns null dotnet core 2.0

…衆ロ難τιáo~ 提交于 2019-12-10 18:36:24

问题


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:

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

in my login controller:

public IActionResult ExternalLogin(string provider)
        {

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

in my ExternalLoginCallbackAsync method when I do

var info = await _signInManager.GetExternalLoginInfoAsync();

any hint why am I always getting null?

thanks


回答1:


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


来源:https://stackoverflow.com/questions/45852188/getexternallogininfoasync-returns-null-dotnet-core-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!