Skip to content

Commit b18bd2c

Browse files
committed
made state optional in getOAuth2RedirectUrl
1 parent d2cd285 commit b18bd2c

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

src/util/oauth.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,31 @@ export async function getOAuth2RedirectUrl(
2828
config: OAuthParams,
2929
req: Request,
3030
res: Response,
31+
addState: boolean = true,
3132
): Promise<string> {
3233
try {
3334
const nonce_string: string = Security.Nonce.nonce();
34-
const state = JSON.stringify({
35-
nonce: nonce_string,
36-
accessTokenUrl: config.accesTokenUrl,
37-
apiUrl: config.apiUrl,
38-
});
39-
const searchParamsAuth = new URLSearchParams({
40-
response_type: 'code',
41-
redirect_uri: config.redirect_uri,
42-
client_id: config.client_id,
43-
state,
44-
});
35+
let searchParams;
36+
if (addState) {
37+
const state = JSON.stringify({
38+
nonce: nonce_string,
39+
accessTokenUrl: config.accesTokenUrl,
40+
apiUrl: config.apiUrl,
41+
});
42+
searchParams = {
43+
response_type: 'code',
44+
redirect_uri: config.redirect_uri,
45+
client_id: config.client_id,
46+
state,
47+
};
48+
} else {
49+
searchParams = {
50+
response_type: 'code',
51+
redirect_uri: config.redirect_uri,
52+
client_id: config.client_id,
53+
};
54+
}
55+
const searchParamsAuth = new URLSearchParams(searchParams);
4556
Security.Nonce.setNonceCookie(
4657
req,
4758
res,

0 commit comments

Comments
 (0)