Skip to content

Commit

Permalink
Merge pull request #11 from Shoogn/dev
Browse files Browse the repository at this point in the history
Improve the PKCE validation when client call the Authorization Reques…
  • Loading branch information
Shoogn authored Mar 22, 2024
2 parents 6886fd8 + 48daf86 commit b91360a
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions Server/src/OAuth20.Server/Services/AuthorizeResultService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ public AuthorizeResponse AuthorizeRequest(IHttpContextAccessor httpContextAccess
return response;
}

if (client.Client.UsePkce && string.IsNullOrWhiteSpace(authorizationRequest.code_challenge))
{
response.Error = ErrorTypeEnum.InvalidRequest.GetEnumDescription();
response.ErrorDescription = "code challenge required";
return response;

}


// check the return url is match the one that in the client store
bool redirectUriIsMatched = client.Client.RedirectUri.Equals(authorizationRequest.redirect_uri, StringComparison.OrdinalIgnoreCase);
Expand Down Expand Up @@ -300,17 +308,23 @@ private bool codeVerifierIsSendByTheClientThatReceivedTheCode(string codeVerifie

if (codeChallengeMethod == Constants.ChallengeMethod.Plain)
{
using var shaPalin = SHA256.Create();
var computedHashPalin = shaPalin.ComputeHash(odeVerifireAsByte);
var tranformedResultPalin = Base64UrlEncoder.Encode(computedHashPalin);
return tranformedResultPalin.Equals(codeChallenge);
return codeVerifier.Equals(codeChallenge);
}

using var shaS256 = SHA256.Create();
var computedHashS256 = shaS256.ComputeHash(odeVerifireAsByte);
var tranformedResultS256 = Base64UrlEncoder.Encode(computedHashS256);
else if (codeChallengeMethod == Constants.ChallengeMethod.SHA256)
{

using var shaS256 = SHA256.Create();
var computedHashS256 = shaS256.ComputeHash(odeVerifireAsByte);
var tranformedResultS256 = Base64UrlEncoder.Encode(computedHashS256);

return tranformedResultS256.Equals(codeChallenge);
}
else
{
return false;
}

return tranformedResultS256.Equals(codeChallenge);
}


Expand Down

0 comments on commit b91360a

Please sign in to comment.