为什么MVC 5 Owin OAuth是不打/帐号/ ExternalLoginCallback行动 [英] Why MVC 5 Owin Oauth is not hitting /Account/ExternalLoginCallback action

查看:524
本文介绍了为什么MVC 5 Owin OAuth是不打/帐号/ ExternalLoginCallback行动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的MVC 5认证。目前,我试过的谷歌授权使用Owin
在code在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行动进行调试。

But it does not hit ExternalLoginCallback Action for debug.

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

它停在 /帐号/ ExternalLoginCallback?RETURNURL =%2F 与空白屏幕。
我不会觉得有什么错。并找到类似的问题<一href=\"http://stackoverflow.com/questions/23072786/google-authentication-using-owin-oauth-in-mvc5-not-hitting-externallogincallback\">Google使用OWIN OAuth认证的MVC5不打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.

推荐答案

这是类似于:<一href=\"http://stackoverflow.com/questions/23072786/google-authentication-using-owin-oauth-in-mvc5-not-hitting-externallogincallback\">Google使用OWIN OAuth认证的MVC5不打ExternalLoginCallback功能

基本上,开发者仪表盘设置你的谷歌应用程序指向您的* / ExternalLoginCallback方法。

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

离开Goog​​leProvider使用默认回调路径。

Leave the GoogleProvider with the default callback path.

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

添加路由处理的登入,谷歌在RouteConfig:

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是不打/帐号/ ExternalLoginCallback行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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