Merge pull request #615 from KKonstantinov/bugfix/authorization-url-generate-state

OAuth Flow: generate random state parameter in oauth state machine
This commit is contained in:
Ola Hungerford 2025-07-31 18:45:05 -07:00 • committed by GitHub
commit 33dbf8399e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -113,6 +113,13 @@ export const oauthTransitions: Record<OAuthStep, StateTransition> = {
scope = metadata.scopes_supported.join(" ");
}
// Generate a random state
const array = new Uint8Array(32);
crypto.getRandomValues(array);
const state = Array.from(array, (byte) =>
byte.toString(16).padStart(2, "0"),
).join("");
const { authorizationUrl, codeVerifier } = await startAuthorization(
context.serverUrl,
{
@ -120,6 +127,7 @@ export const oauthTransitions: Record<OAuthStep, StateTransition> = {
clientInformation,
redirectUrl: context.provider.redirectUrl,
scope,
state: state,
resource: context.state.resource ?? undefined,
},
);