GetExternalLoginInfoAsync null与OWIN在ExternalLoginCallback除非已经登录到谷歌 [英] GetExternalLoginInfoAsync null with OWIN in ExternalLoginCallback unless already logged into google

查看:988
本文介绍了GetExternalLoginInfoAsync null与OWIN在ExternalLoginCallback除非已经登录到谷歌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用一个谷歌帐户来实现在MVC5应用与OWIN外部登录。

I've been trying to implement external logins with OWIN in an MVC5 app using a google account.

如果我已经登录到谷歌,点击我的应用程序的谷歌按钮是好的,它让我获得了将LoginInfo后带我到我的注册页面。

If I'm already logged into google, clicking the google button in my app is fine and it takes me to my registration page after allowing me access to the logininfo.

如果我不是已经登录到谷歌,当我点击我的谷歌应用程序按钮,我得到提示与谷歌登录预期,但回调接收器似乎没有看到我的身份登录LoginInfo类总是空在此方案中,如下回调...

If I'm not already logged into google when I click my applications google button, I get prompted to login with Google as expected but the call back receiver doesn't seem to see that I've logged in as logininfo is always null in this scenario in the callback as below...

    [AllowAnonymous]
    public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
    {
        var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

         if (loginInfo == null)
        {
            return RedirectToAction("Login");
        }

        // Code omitted for brevity.
        }
    }

有没有人有一种变通方法或解释?这几乎就像外部cookie不会提供给OWIN直到登录到谷歌后的要求。

Does anyone have a workaround or explanation? It's almost like the external cookie isn't made available to OWIN until the request after logging into google.

推荐答案

在调查的日子里,我终于遇到了答案。这个问题似乎是,登录到谷歌之后,它重定向回网站,并没有权限来签到,谷歌这样被重定向回到登录页面。不知道为什么这工作,如果已经签署了谷歌虽然。我找到的文章后,发现这个...

After days of investigation, I have eventually come across the answer. The problem seems to be that after logging into google, it redirects back to the site and doesn't have permission to signin-google so is redirected back to the login page. Not sure why this works if already signed into google though. I discovered this after finding the article...

<一个href=\"http://blog.technovert.com/2014/01/google-openid-integration-issues-asp-net-identity/\">http://blog.technovert.com/2014/01/google-openid-integration-issues-asp-net-identity/

我添加以下到我的配置文件。

I added the following to my config file.

<location path="signin-google">
 <system.web>
   <authorization>
     <allow users="*" />
   </authorization>
 </system.web>
</location>

现在它的工作原理...

It now works...

这篇关于GetExternalLoginInfoAsync null与OWIN在ExternalLoginCallback除非已经登录到谷歌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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