Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Sep 28, 2024
1 parent e5783e2 commit d9826a3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
10 changes: 10 additions & 0 deletions web/.env
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,16 @@ DISABLE_PERSONAL_INFOS_INJECTION_IN_GROUP=false
#
DISABLE_AUTO_LAUNCH=false

# This parameter enables you to make it so that when users access your Onyxia instance
# and they are not authenticated they are redirected to the login page automatically,
# without being able to browse the homepage and the catalog of services anonymously.
#
# Type: "true" or "false"
#
# Default: false (users can browse the homepage and the catalog without being authenticated)
#
AUTH_GLOBALLY_REQUIRED=false


# In the Data Explorer helper text there's a link to a sample dataset.
# You can customize the URL of this dataset with this parameter.
Expand Down
8 changes: 7 additions & 1 deletion web/src/core/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type ParamsOfBootstrapCore = {
isCommandBarEnabledByDefault: boolean;
quotaWarningThresholdPercent: number;
quotaCriticalThresholdPercent: number;
isAuthGloballyRequired: boolean;
};

export type Context = {
Expand All @@ -45,7 +46,7 @@ export type Core = GenericCore<typeof usecases, Context>;
export async function bootstrapCore(
params: ParamsOfBootstrapCore
): Promise<{ core: Core }> {
const { apiUrl, transformUrlBeforeRedirectToLogin } = params;
const { apiUrl, transformUrlBeforeRedirectToLogin, isAuthGloballyRequired } = params;

const isSandboxEnvironment = apiUrl === "";

Expand Down Expand Up @@ -136,6 +137,11 @@ export async function bootstrapCore(
});
})();

if (isAuthGloballyRequired && !oidc.isUserLoggedIn) {
await oidc.login({ "doesCurrentHrefRequiresAuth": true });
// NOTE: Never reached
}

const context: Context = {
"paramsOfBootstrapCore": params,
oidc,
Expand Down
15 changes: 15 additions & 0 deletions web/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,21 @@ export const { env, injectTransferableEnvsInQueryParams } = createParsedEnvs([
return envValue === "true";
}
},
{
"envName": "AUTH_GLOBALLY_REQUIRED",
"isUsedInKeycloakTheme": false,
"validateAndParseOrGetDefault": ({ envValue, envName }) => {

const possibleValues = ["true", "false"];

assert(
possibleValues.indexOf(envValue) >= 0,
`${envName} should either be ${possibleValues.join(" or ")}`
);

return envValue === "true";
}
},
{
"envName": "HEADER_HIDE_ONYXIA",
"isUsedInKeycloakTheme": false,
Expand Down
3 changes: 2 additions & 1 deletion web/src/ui/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const { CoreProvider } = createCoreProvider({
"disablePersonalInfosInjectionInGroup": env.DISABLE_PERSONAL_INFOS_INJECTION_IN_GROUP,
"isCommandBarEnabledByDefault": !env.DISABLE_COMMAND_BAR,
"quotaWarningThresholdPercent": env.QUOTA_WARNING_THRESHOLD * 100,
"quotaCriticalThresholdPercent": env.QUOTA_CRITICAL_THRESHOLD * 100
"quotaCriticalThresholdPercent": env.QUOTA_CRITICAL_THRESHOLD * 100,
"isAuthGloballyRequired": env.AUTH_GLOBALLY_REQUIRED
});

export default function App() {
Expand Down
1 change: 1 addition & 0 deletions web/src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type ImportMetaEnv = {
DISABLE_COMMAND_BAR: string
DISABLE_PERSONAL_INFOS_INJECTION_IN_GROUP: string
DISABLE_AUTO_LAUNCH: string
AUTH_GLOBALLY_REQUIRED: string
SAMPLE_DATASET_URL: string
QUOTA_WARNING_THRESHOLD: string
QUOTA_CRITICAL_THRESHOLD: string
Expand Down

0 comments on commit d9826a3

Please sign in to comment.