Skip to content

Commit 3010015

Browse files
committed
feat: add nonce external definition and remove redundant code random generator calls
1 parent 12bce7d commit 3010015

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/types.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type LoginMethodParams = Pick<
1717
| "orgName"
1818
| "connectionId"
1919
| "redirectURL"
20-
| "hasSuccessPage"
20+
| "hasSuccessPage"
2121
>;
2222

2323
export type LoginOptions = {
@@ -105,6 +105,10 @@ export type LoginOptions = {
105105
* Whether to show the success screen at the end of the flow, this is most useful when the callback is not a webpage.
106106
*/
107107
hasSuccessPage?: boolean;
108+
/**
109+
* Single use code to prevent replay attacks
110+
*/
111+
nonce?: string;
108112
};
109113

110114
export enum IssuerRouteTypes {

lib/utils/generateAuthUrl.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ export const generateAuthUrl = (
2222
...mapLoginMethodParamsForUrl(options),
2323
};
2424

25-
const generatedState = generateRandomString(32);
26-
const generatedNonce = generateRandomString(16);
25+
if (!options.state) {
26+
options.state = generateRandomString(32);
27+
}
28+
searchParams["state"] = options.state;
2729

28-
searchParams["state"] = options.state || generatedState;
29-
searchParams["nonce"] = generatedNonce;
30+
if (!options.nonce) {
31+
options.nonce = generateRandomString(16);
32+
}
33+
searchParams["nonce"] = options.nonce;
3034

3135
if (options.codeChallenge) {
3236
searchParams["code_challenge"] = options.codeChallenge;

0 commit comments

Comments
 (0)