generate random state parameter in oauth state machine

This commit is contained in:
Konstantin Konstantinov 2025-07-13 08:42:46 +03:00
commit 1c8bf36ea2
No known key found for this signature in database

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,
},
);