首页 文章

Asp.net标识Google帐户ID从openId迁移到oauth

提问于
浏览
2

我有一个使用DotNetOpenAuth进行Google OpenId身份验证的现有asp.net mvc5应用程序 . 我正在迁移到Asp.Net Identity,并使用Google Auth和OAuth2.0 .

但我已经看到我无法将现有的OpenId帐户ID映射到OAuth2.0 Id: - 旧ID为:https://www.google.com/accounts/o8/id?id=blablabla - 新ID为:长号

由于我想使用新的id,我正在寻找有关迁移身份的帮助 . 我还没有找到一个简单的样本来实现这一目标 .

我正在使用一个新的asp.net mvc5应用程序(刚刚搭建),添加了Microsoft Identity(我的数据的自定义实现),配置了GoogleOAuth2提供程序 .

当我尝试登录时,惊喜! :)帐户ID已更改...

我已经阅读了一些帖子告诉我们将“openid.realm”添加到auth请求但是,如何更改身份验证请求URL,以及如何知道要放入的值?

谢谢 .

1 回答

  • 2

    要更改身份验证请求以包含 openid.real m参数,您可以使用OnApplyRedirect委托,例如

    app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
    {
        ClientId = "",
        ClientSecret = "",
        Provider = new GoogleOAuth2AuthenticationProvider
        {
            OnApplyRedirect = context =>
            {
                Dictionary<string, string> dictionary = new Dictionary<string, string>()
                {
                    { "openid.realm", "http://mywebsite.com/openid/realm" }
                };
                var redirectUri = WebUtilities.AddQueryString(context.RedirectUri, dictionary);
                context.Response.Redirect(redirectUri);
            },
        }
    });
    

    openid.realm 的值必须是您用于OpenID 2.0的realm

    google migration doc包含有关如何从用户旧ID映射到新ID的信息

相关问题