在 MVC5 中使用 OWIN Oauth 的 Google 身份验证未命中 ExternalLoginCallback 函数 [英] Google Authentication using OWIN Oauth in MVC5 not hitting ExternalLoginCallback function

查看:23
本文介绍了在 MVC5 中使用 OWIN Oauth 的 Google 身份验证未命中 ExternalLoginCallback 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在升级我的登录过程,以便 Google 在他们贬低他们的 OpenID 登录方法之前使用 OAuth.

I am currently upgrading my login process for Google to use OAuth before they depricate their OpenID login method.

到目前为止,我已确定的步骤是将 Microsoft.Owin.Security.Google 包升级到版本 2.1.0,因为该版本能够在 UseGoogleAuthentication 方法中包含选项.

The steps I have Identified so far is that I have upgraded the package Microsoft.Owin.Security.Google to version 2.1.0 as this version includes the ability to include options in the UseGoogleAuthentication method.

我尝试在链接中使用 Alex Wheat 的解决方案:使用外部身份验证提供程序从 MVC5 框架 OAuth/OWin 身份提供程序获取 ExtraData

I have tried to use Alex Wheat's Solution in the link: Get ExtraData from MVC5 framework OAuth/OWin identity provider with external auth provider

Startup.Auth.cs(也包括 Facebook 身份验证)中的代码来自:

The code in Startup.Auth.cs (which also includes Facebook authentication) goes from this:

    var facebookAuthenticationOptions = new FacebookAuthenticationOptions()
        {
            AppId = "MYAPPID",
            AppSecret = "MYSECRET"
        };
        facebookAuthenticationOptions.Scope.Add("email");
        app.UseFacebookAuthentication(facebookAuthenticationOptions);

        app.UseGoogleAuthentication();

为此:

var facebookAuthenticationOptions = new FacebookAuthenticationOptions()
        {
            AppId = "MYAPPID",
            AppSecret = "MYSECRET"
        };
        facebookAuthenticationOptions.Scope.Add("email");
        app.UseFacebookAuthentication(facebookAuthenticationOptions);


        var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions
        {
            ClientId = "MYCLIENTID",
            ClientSecret = "MYSECRET",
            CallbackPath = new PathString("/en/Account/ExternalLoginCallback"),
            Provider = new GoogleOAuth2AuthenticationProvider()
            {

            }
        };

        app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions);

在向 Google 身份验证添加选项后,我的应用不允许为 google 或 facebook 调用 ExternalLoginCallback 操作(facebook 代码没有更改,但问题仍然影响它).

After I add options to the Google Authentication, my app does not allow the ExternalLoginCallback action to be called for either google or facebook (no changes to facebook code but the issue still affects it).

在前端,点击外部登录按钮后,页面将我重定向到下面的链接并返回一个空白的白屏

On the front end, after clicking the external login buttons, the page redirects me to the link below and returns an empty white screen

https....../en/Account/ExternalLoginCallback#__=_(= 符号前实际上只有一个下划线,如果我有它,那么语法会将它删除,因为它出现在我的地址栏上).

https....../en/Account/ExternalLoginCallback#__=_ (There is actually only a single underscore before the = sign, SO syntax removes it if I have it as it appears on my address bar).

对于脸书和

https....../en/Account/ExternalLoginCallback

https....../en/Account/ExternalLoginCallback

对于谷歌.它不会像往常一样命中下面的控制器方法(我尝试在此函数中放置调试断点,并且在有谷歌身份验证选项时它永远不会停止.

for google. It does not hit the controller method below as it normally does (I have tried to place debug breakpoints within this function and it never gets stopped when there are google authentication options.

    // GET: /Account/ExternalLoginCallback
    [AllowAnonymous]
    public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
    {

如果我从 Google 身份验证中删除身份验证选项,它只会恢复到旧的 OpenID 登录名并再次正常工作.

If I remove the authentication options from Google Authentication, it just reverts back to the old OpenID login and works fine again.

我在这里遗漏了一些简单的东西吗?或者是 Owin.Security.Google 库内部发生了什么不好的事情导致了问题?

Am I missing something simple here? or is there something bad happening inside the Owin.Security.Google Library that is causing the problem?

推荐答案

只试试这个

var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions
        {
            ClientId = "MYCLIENTID",
            ClientSecret = "MYSECRET",
        };
app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions);

这对我有用

这篇关于在 MVC5 中使用 OWIN Oauth 的 Google 身份验证未命中 ExternalLoginCallback 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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