Asp.net identity Google account id migration from openId to oauth

无人久伴 提交于 2020-01-01 07:04:21

问题


I have an existing asp.net mvc5 application using DotNetOpenAuth for Google OpenId authentication. I am migrating to Asp.Net Identity, and using Google+ Auth with OAuth2.0.

But I have seen thant I can't map existing OpenId account Id to OAuth2.0 Id : - Old id is : https://www.google.com/accounts/o8/id?id=blablabla - New Id is : a long number

Since I would like to use new id, I am searching for help on migrating identities. I have not found yet a simple sample to achieve this.

I am using a new asp.net mvc5 application (freshly scaffolded), added Microsoft Identity (with custom implementation for my data), configured the GoogleOAuth2 provider.

When I try to login, surprise ! :) Account id have changed...

I have read some posts that tell to add "openid.realm" to auth request but, how can I change the authentication request url, and how do I know the value to put in it ?

Thanks.


回答1:


To change the authentication request to include the openid.realm parameter, you can use the OnApplyRedirect delegate e.g.

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);
        },
    }
});

The value of openid.realm needs to be the realm you used for OpenID 2.0

The google migration doc has information on how to map from the users old id to the new one



来源:https://stackoverflow.com/questions/25568187/asp-net-identity-google-account-id-migration-from-openid-to-oauth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!