Last active
December 4, 2023 11:33
-
-
Save DavidKlempfner/9fcc19e296964434cc111a4d3df30cd9 to your computer and use it in GitHub Desktop.
PkceGeneration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async Task HandleChallengeAsyncInternal(AuthenticationProperties properties) | |
{ | |
// code omitted | |
if (Options.UsePkce && Options.ResponseType == OpenIdConnectResponseType.Code) | |
{ | |
var bytes = new byte[32]; | |
RandomNumberGenerator.Fill(bytes); | |
var codeVerifier = Base64UrlTextEncoder.Encode(bytes); | |
// Store this for use during the code redemption. See RunAuthorizationCodeReceivedEventAsync. | |
properties.Items.Add(OAuthConstants.CodeVerifierKey, codeVerifier); | |
var challengeBytes = SHA256.HashData(Encoding.UTF8.GetBytes(codeVerifier)); | |
var codeChallenge = WebEncoders.Base64UrlEncode(challengeBytes); | |
message.Parameters.Add(OAuthConstants.CodeChallengeKey, codeChallenge); | |
message.Parameters.Add(OAuthConstants.CodeChallengeMethodKey, OAuthConstants.CodeChallengeMethodS256); | |
} | |
// code omitted | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment