mirror of
https://github.com/documenso/documenso.git
synced 2026-07-14 23:07:13 +10:00
fix: preserve prompt parameter in OAuth authorize URL builder (#2421)
The prompt option was being discarded for OAuth authorize URLs after adding support for the NEXT_PRIVATE_OIDC_PROMPT env var. This meant select_account (used elsewhere) was not being passed through. Now defaults prompt to the provided option (or 'login'), and only overwrites it when a valid OIDC prompt env var is set. Also adds a type guard to validate the env var value.
This commit is contained in:
@@ -30,11 +30,17 @@ type HandleOAuthAuthorizeUrlOptions = {
|
||||
prompt?: 'none' | 'login' | 'consent' | 'select_account';
|
||||
};
|
||||
|
||||
const isOidcPrompt = (value: unknown): value is HandleOAuthAuthorizeUrlOptions['prompt'] => {
|
||||
return value === 'none' || value === 'login' || value === 'consent' || value === 'select_account';
|
||||
};
|
||||
|
||||
const oauthCookieMaxAge = 60 * 10; // 10 minutes.
|
||||
|
||||
export const handleOAuthAuthorizeUrl = async (options: HandleOAuthAuthorizeUrlOptions) => {
|
||||
const { c, clientOptions, redirectPath } = options;
|
||||
|
||||
let prompt = options.prompt ?? 'login';
|
||||
|
||||
if (!clientOptions.clientId || !clientOptions.clientSecret) {
|
||||
throw new AppError(AppErrorCode.NOT_SETUP);
|
||||
}
|
||||
@@ -63,12 +69,12 @@ export const handleOAuthAuthorizeUrl = async (options: HandleOAuthAuthorizeUrlOp
|
||||
);
|
||||
|
||||
// Pass the prompt to the authorization endpoint.
|
||||
if (process.env.NEXT_PRIVATE_OIDC_PROMPT !== '') {
|
||||
const prompt = process.env.NEXT_PRIVATE_OIDC_PROMPT ?? 'login';
|
||||
|
||||
url.searchParams.append('prompt', prompt);
|
||||
if (process.env.NEXT_PRIVATE_OIDC_PROMPT && isOidcPrompt(process.env.NEXT_PRIVATE_OIDC_PROMPT)) {
|
||||
prompt = process.env.NEXT_PRIVATE_OIDC_PROMPT;
|
||||
}
|
||||
|
||||
url.searchParams.set('prompt', prompt);
|
||||
|
||||
setCookie(c, `${clientOptions.id}_oauth_state`, state, {
|
||||
...sessionCookieOptions,
|
||||
sameSite: 'lax',
|
||||
|
||||
Reference in New Issue
Block a user