diff --git a/XboxAuthNet/OAuth/MicrosoftOAuth.cs b/XboxAuthNet/OAuth/MicrosoftOAuth.cs index 6b7605b..c9d9394 100644 --- a/XboxAuthNet/OAuth/MicrosoftOAuth.cs +++ b/XboxAuthNet/OAuth/MicrosoftOAuth.cs @@ -66,6 +66,8 @@ internal async Task 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 ( @@ -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"]) }; @@ -150,12 +154,16 @@ public async Task 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 RefreshToken(string refreshToken) diff --git a/XboxAuthNet/OAuth/MicrosoftOAuthCode.cs b/XboxAuthNet/OAuth/MicrosoftOAuthCode.cs index f8cefad..924a387 100644 --- a/XboxAuthNet/OAuth/MicrosoftOAuthCode.cs +++ b/XboxAuthNet/OAuth/MicrosoftOAuthCode.cs @@ -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); diff --git a/XboxAuthNet/OAuth/MicrosoftOAuthParameters.cs b/XboxAuthNet/OAuth/MicrosoftOAuthParameters.cs index 604835c..e625370 100644 --- a/XboxAuthNet/OAuth/MicrosoftOAuthParameters.cs +++ b/XboxAuthNet/OAuth/MicrosoftOAuthParameters.cs @@ -46,5 +46,8 @@ public class MicrosoftOAuthParameters /// code_challenge_method /// public string? CodeChallengeMethod { get; set; } + + public string? Scope { get; set; } + public string? Nonce { get; set; } } }