为什么 MVC 5 Owin Oauth 没有点击/Account/ExternalLoginCallback 操作 [英] Why MVC 5 Owin Oauth is not hitting /Account/ExternalLoginCallback action

查看:15
本文介绍了为什么 MVC 5 Owin Oauth 没有点击/Account/ExternalLoginCallback 操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 MVC 5 身份验证的新手.目前我尝试使用 Owin 进行 Google 授权startup.Auth.cs 中的代码

I am new to MVC 5 authentication. Currently I tried Google Authorization using Owin The code in 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 进行调试.

But it does not hit ExternalLoginCallback Action for debug.

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

它停在 /Account/ExternalLoginCallback?ReturnUrl=%2F 处,白屏.我不会发现这有什么问题.并找到类似的问题 Google Authentication using OWIN Oauth in MVC5 not点击 ExternalLoginCallback 函数,但在我的情况下没有帮助.

It stop at /Account/ExternalLoginCallback?ReturnUrl=%2F with blank white screen. I won't find what is wrong with this. and find similar question Google Authentication using OWIN Oauth in MVC5 not hitting ExternalLoginCallback function, but it is not helpful in mine case.

推荐答案

这类似于:在 MVC5 中使用 OWIN Oauth 的 Google 身份验证未命中 ExternalLoginCallback 函数

基本上,在开发者仪表板中将您的 Google 应用设置为指向您的 */ExternalLoginCallback 方法.

Basically, set your google App in the Developers dashboard to point to your */ExternalLoginCallback method.

保留 GoogleProvider 的默认回调路径.

Leave the GoogleProvider with the default callback path.

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

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

Add a route to handle signin-google in RouteConfig:

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

这应该可以解决谷歌提供商和其他所有问题.

That should fix google provider and all the others too.

这篇关于为什么 MVC 5 Owin Oauth 没有点击/Account/ExternalLoginCallback 操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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