加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 使用GoogleOAuth2AuthenticationOptions时出现re

发布时间:2020-12-16 07:06:15 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试在MVC 5网络应用中实施Google身份验证.身份验证工作正常,但我会检索配置文件和图片信息. 为此,我添加了一个GoogleOAuth2AuthenticationOptions对象来指定其他声明: var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptio
我正在尝试在MVC 5网络应用中实施Google身份验证.身份验证工作正常,但我会检索配置文件和图片信息.

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

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:

http://admin.localhost.com/Account/LoginCallback&state=Gs-otJmI79bgWA3_qJzDcGziWnkRCOf7JRoCUDCIz0jv4IIvDdoZlZzVSq2kZxfaPFDmv9hbZGp5q1Aq8mpLPguKnCF31twHj8NQCMv_NrgZzvKwaelmZr_HwY_bdj8h1ICFrkGTKLJ1saEYDbFJ2CJxvDkyBL2iygQmTXQTs-aUiL4yWe5_7dZQOjP_mDUSW-GXns3wr7Okwkoj8VEITJTUz9nAbrBd_N_7puTMlHU&client_id=xxxxxxxxxxxxxxxx

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

但是,当我简单地使用时:

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

它正在发挥作用.

任何的想法 ?

解决方法

只使用这么多.

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

此方法似乎会自动在地址中使用signin-google请求.要修复此更改,请将谷歌控制台中的谷歌回调位置指向此地址.

添加RouteConfig文件

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读