Skip to content

Commit

Permalink
Update RemoteAuthenticationClient.cs
Browse files Browse the repository at this point in the history
Moved code and grant_type parameters in GetToken(sting code) to http form content. Otherwise, Hue IdP fails due to missing grant_type  parameter as documented here: https://developers.meethue.com/develop/hue-api/remote-authentication-oauth/
  • Loading branch information
teilmeier authored Jan 11, 2022
1 parent fd4b8ed commit 0df522b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Q42.HueApi/RemoteAuthenticationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,17 @@ public RemoteAuthorizeResponse ProcessAuthorizeResponse(string responseData)
/// <returns></returns>
public async Task<AccessTokenResponse?> GetToken(string code)
{
var requestUri = new Uri($"https://api.meethue.com/v2/oauth2/token?code={code}&grant_type=authorization_code");
var requestUri = new Uri($"https://api.meethue.com/v2/oauth2/token");

var formParameters = new Dictionary<string, string> {
{"code", code},
{"grant_type", "authorization_code"}
};

var formContent = new FormUrlEncodedContent(formParameters);

//Do a token request
var responseTask = await _httpClient.PostAsync(requestUri, new StringContent(string.Empty)).ConfigureAwait(false);
var responseTask = await _httpClient.PostAsync(requestUri, formContent).ConfigureAwait(false);
var responseString = responseTask.Headers.WwwAuthenticate.ToString();
responseString = responseString.Replace("Digest ", string.Empty);
string nonce = GetNonce(responseString);
Expand All @@ -111,7 +118,7 @@ public RemoteAuthorizeResponse ProcessAuthorizeResponse(string responseData)
{
RequestUri = requestUri,
Method = HttpMethod.Post,

Content = formContent
};

//Build request
Expand Down

0 comments on commit 0df522b

Please sign in to comment.