Fixed Authentication

Also added Geni to the list of supported providers in the readme file
This commit is contained in:
papinto
2016-05-15 17:11:31 -07:00
parent 842c250113
commit fa61e28d09
3 changed files with 10 additions and 13 deletions

View File

@@ -17,6 +17,7 @@ Provides a set of extra authentication providers for OWIN ([Project Katana](http
- Fitbit
- Flickr
- Foursquare
- Geni
- GitHub
- Gitter
- Google+

View File

@@ -71,28 +71,24 @@ namespace Owin.Security.Providers.Geni
new KeyValuePair<string, string>("code", code),
new KeyValuePair<string, string>("grant_type", "authorization_code"),
new KeyValuePair<string, string>("client_id", Options.AppKey),
new KeyValuePair<string, string>("client_secret", Options.AppSecret),
new KeyValuePair<string, string>("redirect_uri", redirectUri)
};
// Request the token
var requestMessage = new HttpRequestMessage(HttpMethod.Post, Options.Endpoints.TokenEndpoint);
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Basic", new Base64TextEncoder().Encode(Encoding.ASCII.GetBytes(Options.AppKey + ":" + Options.AppSecret)));
requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
requestMessage.Content = new FormUrlEncodedContent(body);
var tokenResponse = await _httpClient.SendAsync(requestMessage);
var tokenResponse =
await _httpClient.PostAsync(Options.Endpoints.TokenEndpoint, new FormUrlEncodedContent(body));
tokenResponse.EnsureSuccessStatusCode();
var text = await tokenResponse.Content.ReadAsStringAsync();
// Deserializes the token response
dynamic response = JsonConvert.DeserializeObject<dynamic>(text);
var accessToken = (string)response.access_token;
var refreshToken = (string) response.refresh_token;
var refreshToken = (string)response.refresh_token;
// Get the user info
var userInfoRequest = new HttpRequestMessage(HttpMethod.Get, Options.Endpoints.UserEndpoint);
userInfoRequest.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
userInfoRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var userInfoResponse = await _httpClient.SendAsync(userInfoRequest);
// Get the Geni user
var userInfoResponse = await _httpClient.GetAsync(
Options.Endpoints.UserEndpoint + "?access_token=" + Uri.EscapeDataString(accessToken), Request.CallCancelled);
userInfoResponse.EnsureSuccessStatusCode();
text = await userInfoResponse.Content.ReadAsStringAsync();
var user = JObject.Parse(text);

View File

@@ -26,8 +26,8 @@ namespace Owin.Security.Providers.Geni.Provider
AccessToken = accessToken;
RefreshToken = refreshToken;
User = user;
Name = user.SelectToken("user.name").ToString();
Id = user.SelectToken("user.translator_id").ToString();
Name = user.SelectToken("name").ToString();
Id = user.SelectToken("translator_id").ToString();
}
/// <summary>