为什么MVC 5 Owin Oauth没有点击/ Account/ExternalLoginCallback行动

Abh*_*ngh 7 oauth asp.net-mvc-5

我是MVC 5认证的新手.目前,我尝试使用OwinGoogle授权.在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);
Run Code Online (Sandbox Code Playgroud)

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

[AllowAnonymous]
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
Run Code Online (Sandbox Code Playgroud)

它停在/ Account/ExternalLoginCallback?ReturnUrl =%2F,空白屏幕.我不会发现这有什么问题.并找到类似的问题谷歌认证使用MVC5中的OWIN Oauth没有击中ExternalLoginCallback功能,但它在我的情况下没有帮助.

Rod*_*igo 5

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

基本上,在开发人员仪表板中设置您的 google 应用程序以指向您的 */ExternalLoginCallback 方法。

保留 GoogleProvider 的默认回调路径。

var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions
    {
        ClientId = "MYCLIENTID",
        ClientSecret = "MYSECRET"
    };
Run Code Online (Sandbox Code Playgroud)

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

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

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