I see that there are some questions about this already, but none of them have found any details.
I already used my own code from DotNetOpenAuth, but now I decided to switch to Microsoft Wrapper for authentication. Anyway, I found this a really good OAuth Client:
https://github.com/mj1856/DotNetOpenAuth.GoogleOAuth2
It seems to be working fine, but now it comes to the migration part. In my current login system, I save the full OpenID URL that Google returns, in the form:
https://www.google.com/accounts/o8/id?id= ????????????????????????????????? ????
According to the documentation here https://developers.google.com/accounts/docs/OpenID I have to somehow get this value using the new OAuth system.
I included the parameter "openid.realm" in the Auth request.
return BuildUri(AuthorizationEndpoint, new NameValueCollection
{
{ "response_type", "code" },
{ "client_id", _clientId },
{ "scope", string.Join(" ", scopes) },
{ "redirect_uri", returnUrl.GetLeftPart(UriPartial.Path) },
{ "state", state },
{ "openid.realm", "http://myoldopenidrealm" }
});
And as far as I understand the documentation, which should be all that I need to do. I made sure that the Realm that I used for my OpenID 2 authentication is the same, and it also matches my return url.
After I have done this, I execute this token, and as I understand it, here I should see the "open_id" field, but I can’t figure out how to get it.
protected override string QueryAccessToken(Uri returnUrl, string authorizationCode) {
var postData = HttpUtility.ParseQueryString(string.Empty);
postData.Add(new NameValueCollection
{
{ "grant_type", "authorization_code" },
{ "code", authorizationCode },
{ "client_id", _clientId },
{ "client_secret", _clientSecret },
{ "redirect_uri", returnUrl.GetLeftPart(UriPartial.Path) },
});
var webRequest = (HttpWebRequest)WebRequest.Create(TokenEndpoint);
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
using (var s = webRequest.GetRequestStream())
using (var sw = new StreamWriter(s))
sw.Write(postData.ToString());
using (var webResponse = webRequest.GetResponse()) {
var responseStream = webResponse.GetResponseStream();
if (responseStream == null)
return null;
using (var reader = new StreamReader(responseStream)) {
var response = reader.ReadToEnd();
var json = JObject.Parse(response);
var accessToken = json.Value<string>("access_token");
return accessToken;
}
}
}
This is what the documentation says, and I see neither the "sub" field nor the "openid_id".
* (access_token ..), openid_id OpenID Connect. , , - openid_id sub: *