uthenticationOptions时遇到了redirect

uthenticationOptions时遇到了redirect

本文介绍了使用GoogleOAuth2AuthenticationOptions时遇到了redirect_uri_mismatch错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在MVC 5网络应用中实施Google身份验证.身份验证工作正常,但我会检索个人资料和图片信息.

I'm trying to implement a Google authentication in a MVC 5 web app. Authentication is working fine, but I would retrieve profile and picture informations.

为此,我添加了一个GoogleOAuth2AuthenticationOptions对象以指定其他声明:

To do this, I added a GoogleOAuth2AuthenticationOptions object to specify additional claims :

var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions
{
    ClientId = "xxxxxxxxxxxxxxxx",
    ClientSecret = "xxxxxxxxxxxxxxxxx",
    CallbackPath = new PathString("/Account/LoginCallback"),
    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()));
        }
    }
};

app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions);

但这会导致生成错误的URL:

But it causes that a wrong URL is generated :

HTTP://admin.localhost. COM/帐户/LoginCallback&安培;状态= GS-otJmI79bgWA3_qJzDcGziWnkRCOf7JRoCUDCIz0jv4IIvDdoZlZzVSq2kZxfaPFDmv9hbZGp5q1Aq8mpLPguKnCF31twHj8NQCMv_NrgZzvKwaelmZr_HwY_bdj8h1ICFrkGTKLJ1saEYDbFJ2CJxvDkyBL2iygQmTXQTs-aUiL4yWe5_7dZQOjP_mDUSW-GXns3wr7Okwkoj8VEITJTUz9nAbrBd_N_7puTMlHU&安培; CLIENT_ID = XXXXXXXXXXXXXXXX

没有'?'在参数之前,这会导致redirect_uri_mismatch.

There is no '?' before parameters, that's cause a redirect_uri_mismatch.

但是,当我简单使用时:

However, when I use simply :

app.UseGoogleAuthentication(
    clientId : "xxxxxxxxxxxxxxxxxxx",
    clientSecret : "xxxxxxxxxxxxxxxxx");

正在工作.

有什么主意吗?

推荐答案

仅使用这一点.

var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions
            {
                ClientId = "MYCLIENTID",
                ClientSecret = "MYSECRET",
            };
    app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions);

该方法似乎会自动在地址中使用signin-google请求.要解决此更改,请在Google控制台中更改Google回调位置,使其指向该地址.

This method seems to automatically use the signin-google request in the address.To fix this change google callback location in the google console to point to this address.

添加 RouteConfig文件

 routes.MapRoute( name: "signin-google", url: "signin-google", defaults: new { controller = "Account", action = "LoginCallback" } );

这篇关于使用GoogleOAuth2AuthenticationOptions时遇到了redirect_uri_mismatch错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 20:24