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.
To change the authentication request to include the openid.real
m 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