Skip to content

Commit

Permalink
add parameters for hybrid flow
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaBs committed Sep 7, 2022
1 parent ec1b1a8 commit 6206adc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
10 changes: 9 additions & 1 deletion XboxAuthNet/OAuth/MicrosoftOAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ internal async Task<MicrosoftOAuthResponse> handleMicrosoftOAuthResponse(HttpRes
if (resObj == null)
throw new MicrosoftOAuthException("Response was null", (int)res.StatusCode);

if (resObj.ExpiresOn == default)
resObj.ExpiresOn = DateTimeOffset.Now.AddSeconds(resObj.ExpireIn);
return resObj;
}
catch (Exception ex) when (
Expand Down Expand Up @@ -135,6 +137,8 @@ public bool CheckOAuthCodeResult(Uri uri, out MicrosoftOAuthCode authCode)
authCode = new MicrosoftOAuthCode
{
Code = query["code"],
IdToken = query["id_token"],
State = query["state"],
Error = query["error"],
ErrorDescription = HttpUtility.UrlDecode(query["error_description"])
};
Expand All @@ -150,12 +154,16 @@ public async Task<MicrosoftOAuthResponse> GetTokens(MicrosoftOAuthCode authCode)
var query = createQueriesForAuth();
query["code"] = authCode.Code ?? "";

return await microsoftOAuthRequest(new HttpRequestMessage
var res = await microsoftOAuthRequest(new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri(OAuthToken),
Content = new FormUrlEncodedContent(query)
}).ConfigureAwait(false);

if (string.IsNullOrEmpty(res.IdToken))
res.IdToken = authCode.IdToken;
return res;
}

public async Task<MicrosoftOAuthResponse> RefreshToken(string refreshToken)
Expand Down
6 changes: 3 additions & 3 deletions XboxAuthNet/OAuth/MicrosoftOAuthCode.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
namespace XboxAuthNet.OAuth
{
// https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow
public class MicrosoftOAuthCode
{
public string? Code { get; set; }
public string? IdToken { get; set; }
public string? State { get; set; }
public string? Error { get; set; }
public string? ErrorDescription { get; set; }

// error description
// https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow#error-codes-for-authorization-endpoint-errors

public bool IsSuccess
=> !string.IsNullOrEmpty(Code)
&& string.IsNullOrEmpty(Error);
Expand Down
3 changes: 3 additions & 0 deletions XboxAuthNet/OAuth/MicrosoftOAuthParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,8 @@ public class MicrosoftOAuthParameters
/// code_challenge_method
/// </summary>
public string? CodeChallengeMethod { get; set; }

public string? Scope { get; set; }
public string? Nonce { get; set; }
}
}

0 comments on commit 6206adc

Please sign in to comment.