oauth - 为什么 MVC 5 Owin Oauth 没有点击/Account/ExternalLoginCallback 操作

标签 oauth asp.net-mvc-5

我是 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=%2F 与空白的白色屏幕。
我不会发现这有什么问题。并找到类似的问题 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"});

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

关于oauth - 为什么 MVC 5 Owin Oauth 没有点击/Account/ExternalLoginCallback 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24691992/

相关文章:

ruby-on-rails - omn​​iauth OAuthException 和 OAuth::Unauthorized

asp.net-mvc - ASP MVC 5 (Microsoft.AspNet.Identity) 用户管理包

jQuery AJAX 事件仅触发一次

asp.net-mvc-5 - MVC 5 - 选择项目时在同一页面中显示项目详细信息

jquery - Javascript 字符串化对象

post - 在 Chrome 扩展程序中向 Tumblr 的 API 发出 POST 请求

javascript - GitHub Octokit/rest.js 用于单页应用程序的 OAuth

c# - 更改表单上下文以确保正确命名嵌套模型?

java - 如何防止代币替换攻击?

python - 将 SSL 验证与 Tweepy 结合使用