Skip to content

Commit

Permalink
Switched from using Google+ APIs to using OAuth userinfo (#224)
Browse files Browse the repository at this point in the history
Fixes #223
  • Loading branch information
ThomasArdal authored and PureKrome committed Dec 27, 2018
1 parent 43f5011 commit 8494a55
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ namespace SimpleAuthentication.Core.Providers.Google
{
public class UserInfoResult
{
public string Id { get; set; }
public List<Email> Emails { get; set; }
public string DisplayName { get; set; }
public Name Name { get; set; }
public string Url { get; set; }
public Image Image { get; set; }
public string Sub { get; set; }
public string Name { get; set; }
public string GivenName { get; set; }
public string FamilyName { get; set; }
public string Profile { get; set; }
public string Picture { get; set; }
public string Email { get; set; }
public string EmailVerified { get; set; }
public string Gender { get; set; }
public string Language { get; set; }
public string Locale { get; set; }
}
}
19 changes: 7 additions & 12 deletions Code/SimpleAuthentication.Core/Providers/GoogleProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected override UserInformation RetrieveUserInformation(AccessToken accessTok

try
{
var restRequest = new RestRequest("/plus/v1/people/me", Method.GET);
var restRequest = new RestRequest("/oauth2/v3/userinfo", Method.GET);
restRequest.AddParameter(AccessTokenKey, accessToken.PublicToken);

var restClient = RestClientFactory.CreateRestClient("https://www.googleapis.com");
Expand Down Expand Up @@ -135,7 +135,7 @@ protected override UserInformation RetrieveUserInformation(AccessToken accessTok
}

// Lets check to make sure we have some bare minimum data.
if (string.IsNullOrEmpty(response.Data.Id))
if (string.IsNullOrEmpty(response.Data.Sub))
{
const string errorMessage =
"We were unable to retrieve the User Id from Google API, the user may have denied the authorization.";
Expand All @@ -145,20 +145,15 @@ protected override UserInformation RetrieveUserInformation(AccessToken accessTok

return new UserInformation
{
Id = response.Data.Id,
Id = response.Data.Sub,
Gender = string.IsNullOrEmpty(response.Data.Gender)
? GenderType.Unknown
: GenderTypeHelpers.ToGenderType(response.Data.Gender),
Name = response.Data.Name.ToString(),
Email = response.Data.Emails != null &&
response.Data.Emails.Any()
? response.Data.Emails.First().Value
: null,
Locale = response.Data.Language,
Picture = response.Data.Image != null
? response.Data.Image.Url
: null,
UserName = response.Data.DisplayName
Email = response.Data.Email,
Locale = response.Data.Locale,
Picture = response.Data.Picture,
UserName = response.Data.Name
};
}

Expand Down

0 comments on commit 8494a55

Please sign in to comment.