Skip to content

Update Google auth user info endpoint #253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Microsoft.Owin.Security.Google/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ internal static class Constants

internal const string AuthorizationEndpoint = "https://accounts.google.com/o/oauth2/v2/auth";
internal const string TokenEndpoint = "https://www.googleapis.com/oauth2/v4/token";
internal const string UserInformationEndpoint = "https://www.googleapis.com/plus/v1/people/me";
internal const string UserInformationEndpoint = "https://www.googleapis.com/oauth2/v2/userinfo";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public GoogleOAuth2AuthenticatedContext(IOwinContext context, JObject user, stri
}

Id = TryGetValue(user, "id");
Name = TryGetValue(user, "displayName");
GivenName = TryGetValue(user, "name", "givenName");
FamilyName = TryGetValue(user, "name", "familyName");
Profile = TryGetValue(user, "url");
Email = TryGetFirstValue(user, "emails", "value"); // TODO:
Name = TryGetValue(user, "name");
GivenName = TryGetValue(user, "given_name");
FamilyName = TryGetValue(user, "family_name");
Profile = TryGetValue(user, "link");
Email = TryGetValue(user, "email");
}

/// <summary>
Expand All @@ -70,18 +70,18 @@ public GoogleOAuth2AuthenticatedContext(IOwinContext context, JObject user, JObj
}

Id = TryGetValue(user, "id");
Name = TryGetValue(user, "displayName");
GivenName = TryGetValue(user, "name", "givenName");
FamilyName = TryGetValue(user, "name", "familyName");
Profile = TryGetValue(user, "url");
Email = TryGetFirstValue(user, "emails", "value"); // TODO:
Name = TryGetValue(user, "name");
GivenName = TryGetValue(user, "given_name");
FamilyName = TryGetValue(user, "family_name");
Profile = TryGetValue(user, "link");
Email = TryGetValue(user, "email");
}

/// <summary>
/// Gets the JSON-serialized user
/// </summary>
/// <remarks>
/// Contains the Google user obtained from the endpoint https://www.googleapis.com/oauth2/v3/userinfo
/// Contains the Google user obtained from the UserInformationEndpoint
/// </remarks>
public JObject User { get; private set; }

Expand Down Expand Up @@ -153,42 +153,5 @@ private static string TryGetValue(JObject user, string propertyName)
JToken value;
return user.TryGetValue(propertyName, out value) ? value.ToString() : null;
}

// Get the given subProperty from a property.
private static string TryGetValue(JObject user, string propertyName, string subProperty)
{
JToken value;
if (user.TryGetValue(propertyName, out value))
{
var subObject = JObject.Parse(value.ToString());
if (subObject != null && subObject.TryGetValue(subProperty, out value))
{
return value.ToString();
}
}
return null;
}

// Get the given subProperty from a list property.
private static string TryGetFirstValue(JObject user, string propertyName, string subProperty)
{
JToken value;
if (user.TryGetValue(propertyName, out value))
{
var array = JArray.Parse(value.ToString());
if (array != null && array.Count > 0)
{
var subObject = JObject.Parse(array.First.ToString());
if (subObject != null)
{
if (subObject.TryGetValue(subProperty, out value))
{
return value.ToString();
}
}
}
}
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,26 +239,16 @@ public async Task ReplyPathWillAuthenticateValidAuthorizeCodeAndState()
token_type = "Bearer"
});
}
else if (req.RequestUri.GetLeftPart(UriPartial.Path) == "https://www.googleapis.com/plus/v1/people/me")
else if (req.RequestUri.GetLeftPart(UriPartial.Path) == "https://www.googleapis.com/oauth2/v2/userinfo")
{
return await ReturnJsonResponse(new
{
id = "Test User ID",
displayName = "Test Name",
name = new
{
familyName = "Test Family Name",
givenName = "Test Given Name"
},
url = "Profile link",
emails = new[]
{
new
{
value = "Test email",
type = "account"
}
}
name = "Test Name",
given_name = "Test Given Name",
family_name = "Test Family Name",
link = "Profile link",
email = "Test email",
});
}

Expand Down Expand Up @@ -371,26 +361,16 @@ public async Task AuthenticatedEventCanGetRefreshToken()
refresh_token = "Test Refresh Token"
});
}
else if (req.RequestUri.GetLeftPart(UriPartial.Path) == "https://www.googleapis.com/plus/v1/people/me")
else if (req.RequestUri.GetLeftPart(UriPartial.Path) == "https://www.googleapis.com/oauth2/v2/userinfo")
{
return await ReturnJsonResponse(new
{
id = "Test User ID",
displayName = "Test Name",
name = new
{
familyName = "Test Family Name",
givenName = "Test Given Name"
},
url = "Profile link",
emails = new[]
{
new
{
value = "Test email",
type = "account"
}
}
name = "Test Name",
given_name = "Test Given Name",
family_name = "Test Family Name",
link = "Profile link",
email = "Test email",
});
}

Expand Down