加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

为什么MVC 5 Owin Oauth没有点击/ Account/ExternalLoginCallbac

发布时间:2020-12-16 03:53:59 所属栏目:asp.Net 来源:网络整理
导读:我是MVC 5认证的新手.目前,我尝试使用Owin进行Google授权 startup.Auth.cs中的代码 var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions{ ClientId = "Client-id",ClientSecret = "secret-key",CallbackPath = new PathString("
我是MVC 5认证的新手.目前,我尝试使用Owin进行Google授权
startup.Auth.cs中的代码

var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions
{
    ClientId = "Client-id",ClientSecret = "secret-key",CallbackPath = new PathString("/Account/ExternalLoginCallback"),Provider = new GoogleOAuth2AuthenticationProvider()
    {
        OnAuthenticated = async context =>
        {
            context.Identity.AddClaim(new Claim("picture",context.User.GetValue("picture").ToString()));
            context.Identity.AddClaim(new Claim("profile",context.User.GetValue("profile").ToString()));
        }
    }
};
googleOAuth2AuthenticationOptions.Scope.Add("email");

app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions);

但它没有点击ExternalLoginCallback Action进行调试.

[AllowAnonymous]
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)

它停在/ Account / ExternalLoginCallback?ReturnUrl = /,带有空白屏幕.
我不会发现这有什么问题.并找到类似的问题Google Authentication using OWIN Oauth in MVC5 not hitting ExternalLoginCallback function,但它在我的情况下没有帮助.

解决方法

这类似于: Google Authentication using OWIN Oauth in MVC5 not hitting ExternalLoginCallback function

基本上,将开发人员信息中心中的Google应用设置为指向* / ExternalLoginCallback方法.

保留GoogleProvider的默认回调路径.

var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions
    {
        ClientId = "MYCLIENTID",ClientSecret = "MYSECRET"
    };

在RouteConfig中添加处理signin-google的路由:

routes.MapRoute(
            name: "signin-google",url: "signin-google",defaults: new { controller = "[YOURCONTROLLLER]",action = "ExternalLoginCallback"});

这应该修复谷歌提供商和所有其他人.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读