fix: read OAUTH_SCOPES at runtime instead of build time
This commit is contained in:
@@ -146,6 +146,8 @@ export const CONFIG_ENV_MAP: Record<string, { envVar: string; fileEnvVar?: strin
|
||||
oauthClientId: { envVar: 'OAUTH_CLIENT_ID', type: 'string', defaultValue: '' },
|
||||
oauthClientSecret: { envVar: 'OAUTH_CLIENT_SECRET', fileEnvVar: 'OAUTH_CLIENT_SECRET_FILE', type: 'string', defaultValue: '' },
|
||||
oauthIssuerUrl: { envVar: 'OAUTH_ISSUER_URL', type: 'url', defaultValue: '' },
|
||||
oauthScopes: { envVar: 'OAUTH_SCOPES', type: 'string', defaultValue: '' },
|
||||
oauthExtraScopes: { envVar: 'OAUTH_EXTRA_SCOPES', type: 'string', defaultValue: '' },
|
||||
allowCustomJmapEndpoint: { envVar: 'ALLOW_CUSTOM_JMAP_ENDPOINT', type: 'boolean', defaultValue: false },
|
||||
jmapServers: { envVar: 'JMAP_SERVERS', type: 'json', defaultValue: [] },
|
||||
jmapServerAutoPickByDomain: { envVar: 'JMAP_SERVER_AUTO_PICK_BY_DOMAIN', type: 'boolean', defaultValue: false },
|
||||
|
||||
+16
-2
@@ -1,6 +1,20 @@
|
||||
import { configManager } from '@/lib/admin/config-manager';
|
||||
|
||||
const DEFAULT_SCOPES = 'openid email profile';
|
||||
const EXTRA_SCOPES = process.env.OAUTH_EXTRA_SCOPES || '';
|
||||
export const OAUTH_SCOPES = process.env.OAUTH_SCOPES || (EXTRA_SCOPES ? `${DEFAULT_SCOPES} ${EXTRA_SCOPES}`.trim() : DEFAULT_SCOPES);
|
||||
|
||||
/**
|
||||
* Resolve the OAuth scopes to request at authorize time.
|
||||
*
|
||||
* Reads admin override / OAUTH_SCOPES / OAUTH_EXTRA_SCOPES at call time so
|
||||
* runtime env vars (and admin dashboard changes) take effect without a rebuild.
|
||||
* Server-only: callers in the browser must read `oauthScopes` from /api/config.
|
||||
*/
|
||||
export function getOauthScopes(): string {
|
||||
const explicit = configManager.get<string>('oauthScopes', '');
|
||||
if (explicit) return explicit;
|
||||
const extra = configManager.get<string>('oauthExtraScopes', '');
|
||||
return extra ? `${DEFAULT_SCOPES} ${extra}`.trim() : DEFAULT_SCOPES;
|
||||
}
|
||||
export const REFRESH_TOKEN_COOKIE = 'jmap_rt';
|
||||
export const REFRESH_TOKEN_SERVER_COOKIE = 'jmap_rts';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user