public override async Task <ExternalAuthUserInfo> GetUserInfo(string accessCode)
        {
            ExternalAuthUserInfo externalAuthUserInfo;

            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.UserAgent.ParseAdd("Microsoft ASP.NET Core OAuth middleware");
                client.DefaultRequestHeaders.Accept.ParseAdd("application/json");
                client.Timeout = TimeSpan.FromSeconds(30.0);
                client.MaxResponseContentBufferSize = 10485760L;
                HttpResponseMessage httpResponseMessage = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, GoogleDefaults.UserInformationEndpoint)
                {
                    Headers =
                    {
                        Authorization = new AuthenticationHeaderValue("Bearer", accessCode)
                    }
                });

                httpResponseMessage.EnsureSuccessStatusCode();
                JObject user = JObject.Parse(await httpResponseMessage.Content.ReadAsStringAsync());
                externalAuthUserInfo = new ExternalAuthUserInfo()
                {
                    Name         = GoogleHelper.GetName(user),
                    EmailAddress = GoogleHelper.GetEmail(user),
                    Surname      = GoogleHelper.GetFamilyName(user),
                    ProviderKey  = GoogleHelper.GetId(user),
                    Provider     = "Google"
                };
            }
            return(externalAuthUserInfo);
        }
Exemple #2
0
 public static string GetEmail(JObject user)
 {
     if (user == null)
     {
         throw new ArgumentNullException(nameof(user));
     }
     return(GoogleHelper.TryGetFirstValue(user, "emails", "value"));
 }
Exemple #3
0
 public static string GetFamilyName(JObject user)
 {
     if (user == null)
     {
         throw new ArgumentNullException(nameof(user));
     }
     return(GoogleHelper.TryGetValue(user, "name", "familyName"));
 }