Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement AUTH_DISABLE_DEFAULT config option #9322

Merged
merged 9 commits into from Dec 3, 2021
8 changes: 5 additions & 3 deletions api/src/auth.ts
Expand Up @@ -24,10 +24,12 @@ export function getAuthProvider(provider: string): AuthDriver {

export async function registerAuthProviders(): Promise<void> {
const options = { knex: getDatabase(), schema: await getSchema() };
const defaultProvider = getProviderInstance('local', options)!;

// Register default provider
providers.set(DEFAULT_AUTH_PROVIDER, defaultProvider);
// Register default provider if not disabled
if (!env.AUTH_DISABLE_DEFAULT) {
const defaultProvider = getProviderInstance('local', options)!;
providers.set(DEFAULT_AUTH_PROVIDER, defaultProvider);
}

if (!env.AUTH_PROVIDERS) {
return;
Expand Down
5 changes: 4 additions & 1 deletion api/src/controllers/auth.ts
Expand Up @@ -191,7 +191,10 @@ router.post(
router.get(
'/',
asyncHandler(async (req, res, next) => {
res.locals.payload = { data: getAuthProviders() };
res.locals.payload = {
data: getAuthProviders(),
disableDefault: env.AUTH_DISABLE_DEFAULT,
};
return next();
}),
respond
Expand Down
1 change: 1 addition & 0 deletions api/src/env.ts
Expand Up @@ -55,6 +55,7 @@ const defaults: Record<string, any> = {
CACHE_SCHEMA: true,

AUTH_PROVIDERS: '',
AUTH_DISABLE_DEFAULT: false,

EXTENSIONS_PATH: './extensions',

Expand Down
8 changes: 7 additions & 1 deletion app/src/routes/login/login.vue
Expand Up @@ -59,6 +59,7 @@ export default defineComponent({
const provider = ref(DEFAULT_AUTH_PROVIDER);
const providerOptions = ref([]);
const driver = ref('local');
const disableDefault = ref(false);

const providerSelect = computed({
get() {
Expand All @@ -78,7 +79,11 @@ export default defineComponent({
providerOptions.value = providers.value
.filter((provider) => !AUTH_SSO_DRIVERS.includes(provider.driver))
.map((provider) => ({ text: formatTitle(provider.name), value: provider.name }));
providerOptions.value.unshift({ text: t('default_provider'), value: DEFAULT_AUTH_PROVIDER });
if (!disableDefault.value) {
providerOptions.value.unshift({ text: t('default_provider'), value: DEFAULT_AUTH_PROVIDER });
} else {
providerSelect.value = providerOptions.value[0].value;
dorianim marked this conversation as resolved.
Show resolved Hide resolved
dorianim marked this conversation as resolved.
Show resolved Hide resolved
}
});

return { t, te, authenticated, providers, providerSelect, providerOptions, provider, driver };
Expand All @@ -87,6 +92,7 @@ export default defineComponent({
try {
const response = await api.get('/auth');
providers.value = response.data.data;
rijkvanzanten marked this conversation as resolved.
Show resolved Hide resolved
disableDefault.value = response.data.disableDefault;
} catch (err: any) {
unexpectedError(err);
}
Expand Down
7 changes: 4 additions & 3 deletions docs/configuration/config-options.md
Expand Up @@ -515,9 +515,10 @@ we recommend lowering the allowed concurrent transformations to prevent you from

## Authentication

| Variable | Description | Default Value |
| ---------------- | -------------------------------------- | ------------- |
| `AUTH_PROVIDERS` | CSV of auth providers you want to use. | -- |
| Variable | Description | Default Value |
| ---------------------- | -------------------------------------- | ------------- |
| `AUTH_PROVIDERS` | CSV of auth providers you want to use. | -- |
| `AUTH_DISABLE_DEFAULT` | Disable the default auth provider | `false` |

For each of the auth providers you list, you must provide the following configuration:

Expand Down