GetExternalLoginInfoAsync null与ExternalLoginCallback中的OWIN,除非已登录到谷歌

Hoo*_*ots 6 c# asp.net asp.net-mvc login owin

我一直在尝试使用谷歌帐户在MVC5应用程序中使用OWIN实现外部登录.

如果我已经登录谷歌,点击我的应用程序中的谷歌按钮是好的,它允许我访问logininfo后,我将进入我的注册页面.

如果我点击我的应用程序谷歌按钮时我还没有登录谷歌,我会被提示按预期登录谷歌,但回叫接收器似乎没有看到我登录,因为logininfo始终为null回调中的场景如下......

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

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

        // Code omitted for brevity.
        }
    }
Run Code Online (Sandbox Code Playgroud)

有没有人有解决方法或解释?这几乎就像外部cookie在登录谷歌之后才能提供给OWIN.

Hoo*_*ots 7

经过几天的调查,我终于得到了答案.问题似乎是登录谷歌后,它重定向回网站,没有登录谷歌的权限,因此被重定向回登录页面.如果已经登录谷歌,不知道为什么这会有效.找到文章后我发现了这个......

http://blog.technovert.com/2014/01/google-openid-integration-issues-asp-net-identity/

我在配置文件中添加了以下内容.

<location path="signin-google">
 <system.web>
   <authorization>
     <allow users="*" />
   </authorization>
 </system.web>
</location>
Run Code Online (Sandbox Code Playgroud)

它现在有效......