Add ability to prevent OIDC redirect (#6544)

* Add ability to prevent OIDC redirect

* Fix Typing on optional boolean

* Fix lint

* Fix lint

* Rename var from PREVENT to DISABLE

---------

Co-authored-by: Tom Moor <tom@getoutline.com>
This commit is contained in:
Shuttleu
2024-02-16 17:48:40 +00:00
committed by GitHub
parent 2b0a8d1f7c
commit 0219885548
5 changed files with 41 additions and 2 deletions

View File

@@ -499,6 +499,16 @@ export class Environment {
process.env.OIDC_USERINFO_URI
);
/**
* Disable autoredirect to the OIDC login page if there is only one
* authentication method and that method is OIDC.
*/
@IsOptional()
@IsBoolean()
public OIDC_DISABLE_REDIRECT = this.toOptionalBoolean(
process.env.OIDC_DISABLE_REDIRECT
);
/**
* The OIDC logout endpoint.
*/
@@ -776,6 +786,26 @@ export class Environment {
);
}
}
/**
* Convert a string to an optional boolean. Supports the following:
*
* 0 = false
* 1 = true
* "true" = true
* "false" = false
* "" = undefined
*
* @param value The string to convert
* @returns A boolean or undefined
*/
private toOptionalBoolean(value: string | undefined) {
try {
return value ? !!JSON.parse(value) : undefined;
} catch (err) {
return undefined;
}
}
}
const env = new Environment();