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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Authentication can be optionally disabled #89

Merged
merged 16 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,24 @@ const PLUGINS_MODULE = process.env.PLUGINS_MODULE;
// If it has no protocol, it will be treated as relative to window.location.origin
const STATUS_URL = process.env.STATUS_URL;

const DISABLE_AUTH = process.env.DISABLE_AUTH;

module.exports = {
ADMIN_API_URL,
BASE_URL,
// Config env isn't sent to the client, so excluded from processEnv
CONFIG_CACHE_TTL_SECONDS,
CONFIG_DIR,
CORS_PROXY_PREFIX,
DISABLE_AUTH,
NODE_ENV,
PLUGINS_MODULE,
STATUS_URL,
processEnv: {
ADMIN_API_URL,
BASE_URL,
CORS_PROXY_PREFIX,
DISABLE_AUTH,
NODE_ENV,
STATUS_URL
}
Expand Down
10 changes: 10 additions & 0 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,13 @@ export function assertNever(
`Unhandled discriminated union member: ${JSON.stringify(value)}`
);
}

/**
* Function that returns boolean value for the string or number representation
*/
export function toBoolean(value?: string): boolean {
if (value == null) {
return false;
}
return ['true', 'True', 'TRUE', '1'].includes(value);
}
1 change: 1 addition & 0 deletions src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export interface Env extends NodeJS.ProcessEnv {
CORS_PROXY_PREFIX: string;
DISABLE_ANALYTICS?: string;
STATUS_URL?: string;
DISABLE_AUTH?: string;
}
7 changes: 5 additions & 2 deletions src/models/AdminEntity/AdminEntity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import axios, { AxiosRequestConfig } from 'axios';
import { env } from 'common/env';
import { toBoolean } from 'common/utils';

import { generateAdminApiQuery } from './AdminApiQuery';

import { transformRequestError } from './transformRequestError';
import {
AdminEntityTransformer,
Expand Down Expand Up @@ -44,7 +47,7 @@ async function request(
const finalOptions = {
...options,
url: adminApiUrl(endpoint),
withCredentials: true
withCredentials: !toBoolean(env.DISABLE_AUTH)
};

try {
Expand All @@ -70,7 +73,7 @@ export async function getProtobufObject<ResponseType>(
headers,
method: 'get',
responseType: 'arraybuffer',
withCredentials: true
withCredentials: !toBoolean(env.DISABLE_AUTH)
};

const { data } = await axios.request(options);
Expand Down