From fa61e28d0966a77c2bfc785367eaf95eb8c65cfb Mon Sep 17 00:00:00 2001 From: papinto Date: Sun, 15 May 2016 17:11:31 -0700 Subject: [PATCH] Fixed Authentication Also added Geni to the list of supported providers in the readme file --- README.md | 1 + .../GeniAuthenticationHandler.cs | 18 +++++++----------- .../Provider/GeniAuthenticatedContext.cs | 4 ++-- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index d99fd22..9fbbb18 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Provides a set of extra authentication providers for OWIN ([Project Katana](http - Fitbit - Flickr - Foursquare + - Geni - GitHub - Gitter - Google+ diff --git a/src/Owin.Security.Providers.Geni/GeniAuthenticationHandler.cs b/src/Owin.Security.Providers.Geni/GeniAuthenticationHandler.cs index 1333590..b5de7cb 100644 --- a/src/Owin.Security.Providers.Geni/GeniAuthenticationHandler.cs +++ b/src/Owin.Security.Providers.Geni/GeniAuthenticationHandler.cs @@ -71,28 +71,24 @@ namespace Owin.Security.Providers.Geni new KeyValuePair("code", code), new KeyValuePair("grant_type", "authorization_code"), new KeyValuePair("client_id", Options.AppKey), + new KeyValuePair("client_secret", Options.AppSecret), new KeyValuePair("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(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); diff --git a/src/Owin.Security.Providers.Geni/Provider/GeniAuthenticatedContext.cs b/src/Owin.Security.Providers.Geni/Provider/GeniAuthenticatedContext.cs index 443f281..fa02a2b 100644 --- a/src/Owin.Security.Providers.Geni/Provider/GeniAuthenticatedContext.cs +++ b/src/Owin.Security.Providers.Geni/Provider/GeniAuthenticatedContext.cs @@ -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(); } ///