Skip to content

Commit 33dbf83

Browse files
authored
Merge pull request #615 from KKonstantinov/bugfix/authorization-url-generate-state
OAuth Flow: generate random state parameter in oauth state machine
2 parents 21bb004 + 816f6c2 commit 33dbf83

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)