public async Task <JObject> GetUserInfoAsync(string accessToken) { var provider = ExternalProviders.GetProviders().FirstOrDefault(x => x.Name.Equals(TokenExchangeProviders.Facebook, StringComparison.OrdinalIgnoreCase)); if (provider == null) { throw new ArgumentNullException(nameof(provider)); } var request = new Dictionary <string, string>(); request.Add("tokenString", accessToken); request.Add("endpoint", provider.UserInfoEndpoint); var authorizationHeaderParams = QueryBuilder.GetQuery(request, TokenExchangeProviders.Twitter); _client.DefaultRequestHeaders.Clear(); _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded")); _client.DefaultRequestHeaders.Add("Authorization", authorizationHeaderParams); var result = await _client.GetAsync(provider.UserInfoEndpoint); if (result.IsSuccessStatusCode) { var infoObject = JObject.Parse(await result.Content.ReadAsStringAsync()); return(infoObject); } return(null); }
public async Task <JObject> GetUserInfoAsync(string accessToken) { var provider = ExternalProviders.GetProviders().FirstOrDefault(x => x.Name.Equals(TokenExchangeProviders.Facebook, StringComparison.OrdinalIgnoreCase)); if (provider == null) { throw new ArgumentNullException(nameof(provider)); } var urlParams = $"oauth2_access_token={accessToken}&format=json"; var result = await _client.GetAsync($"{provider.UserInfoEndpoint}{urlParams}"); if (result.IsSuccessStatusCode) { var infoObject = JObject.Parse(await result.Content.ReadAsStringAsync()); return(infoObject); } return(null); }
public async Task <JObject> GetUserInfoAsync(string accessToken) { var provider = ExternalProviders.GetProviders().FirstOrDefault(x => x.Name.Equals(TokenExchangeProviders.Facebook, StringComparison.OrdinalIgnoreCase)); if (provider == null) { throw new ArgumentNullException(nameof(provider)); } var request = new Dictionary <string, string>(); request.Add("token", accessToken); var result = await _client.GetAsync(provider.UserInfoEndpoint + QueryBuilder.GetQuery(request, TokenExchangeProviders.Google)); if (result.IsSuccessStatusCode) { var infoObject = JObject.Parse(await result.Content.ReadAsStringAsync()); return(infoObject); } return(null); }