Skip to content

Commit

Permalink
chore(SLB-450): skip authentication if not explicitly set
Browse files Browse the repository at this point in the history
Allows to run in the CI / in local without authentication as we don't create consumers in this case.
  • Loading branch information
colorfield committed Jul 12, 2024
1 parent d7d86ab commit 82da3b8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
3 changes: 0 additions & 3 deletions apps/preview/.lagoon.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@ OAUTH2_SESSION_SECRET=REPLACE_ME
#AUTHENTICATION_TYPE=basic
#BASIC_AUTH_USER=preview
#BASIC_AUTH_PASSWORD=preview

# To skip authentication
#SKIP_AUTHENTICATION=true
7 changes: 2 additions & 5 deletions apps/preview/server/utils/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ import { oAuth2AuthCodeMiddleware } from './oAuth2.js';
*/
export const getAuthenticationMiddleware = (): RequestHandler =>
((): RequestHandler => {
const skipAuthentication = process.env.SKIP_AUTHENTICATION === 'true';
if (skipAuthentication) {
return (req: Request, res: Response, next: NextFunction): void => next();
}

const config = getConfig();
switch (config.authenticationType) {
case 'oauth2':
Expand All @@ -36,6 +31,8 @@ export const getAuthenticationMiddleware = (): RequestHandler =>
console.error('Missing basic auth configuration.');
}
break;
case 'noauth':
break;
default:
console.error('Unknown authentication type.');
break;
Expand Down
4 changes: 2 additions & 2 deletions apps/preview/server/utils/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type PreviewConfig = {
authenticationType: string; // 'oauth2' | 'basic';
authenticationType: string; // 'oauth2' | 'basic' | 'noauth';
drupalHost: string;
/**
* Basic auth.
Expand All @@ -25,7 +25,7 @@ export type PreviewConfig = {

export const getConfig = (): PreviewConfig => {
return {
authenticationType: process.env.AUTHENTICATION_TYPE || 'oauth2',
authenticationType: process.env.AUTHENTICATION_TYPE || 'noauth',
drupalHost: process.env.DRUPAL_URL || 'http://127.0.0.1:8888',
basicAuth: {
username: process.env.BASIC_AUTH_USER || 'test',
Expand Down

0 comments on commit 82da3b8

Please sign in to comment.