Skip to content

Commit 1c8bf36

Browse files
committed
generate random state parameter in oauth state machine
1 parent 56ef795 commit 1c8bf36

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

client/src/lib/oauth-state-machine.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,21 @@ export const oauthTransitions: Record<OAuthStep, StateTransition> = {
113113
scope = metadata.scopes_supported.join(" ");
114114
}
115115

116+
// Generate a random state
117+
const array = new Uint8Array(32);
118+
crypto.getRandomValues(array);
119+
const state = Array.from(array, (byte) =>
120+
byte.toString(16).padStart(2, '0'),
121+
).join('');
122+
116123
const { authorizationUrl, codeVerifier } = await startAuthorization(
117124
context.serverUrl,
118125
{
119126
metadata,
120127
clientInformation,
121128
redirectUrl: context.provider.redirectUrl,
122129
scope,
130+
state: state,
123131
resource: context.state.resource ?? undefined,
124132
},
125133
);

0 commit comments

Comments
 (0)