From 43242cccc9cd860fc65859f5d0a950b2b15c089e Mon Sep 17 00:00:00 2001 From: Philip Molares Date: Sat, 4 Sep 2021 17:46:58 +0200 Subject: [PATCH] feat: add session to AuthConfig this handles the settings for the cookie session. The secret and the lifeTime of the cookie can be configured. Signed-off-by: Philip Molares --- src/config/auth.config.ts | 16 ++++++++++++++++ src/config/mock/auth.config.mock.ts | 4 ++++ .../frontend-config.service.spec.ts | 4 ++++ 3 files changed, 24 insertions(+) diff --git a/src/config/auth.config.ts b/src/config/auth.config.ts index 5670ad14b..57406a0f0 100644 --- a/src/config/auth.config.ts +++ b/src/config/auth.config.ts @@ -9,11 +9,16 @@ import * as Joi from 'joi'; import { GitlabScope, GitlabVersion } from './gitlab.enum'; import { buildErrorMessage, + parseOptionalInt, replaceAuthErrorsWithEnvironmentVariables, toArrayConfig, } from './utils'; export interface AuthConfig { + session: { + secret: string; + lifeTime: number; + }; email: { enableLogin: boolean; enableRegister: boolean; @@ -101,6 +106,13 @@ export interface AuthConfig { } const authSchema = Joi.object({ + session: { + secret: Joi.string().label('HD_SESSION_SECRET'), + lifeTime: Joi.number() + .default(100000) + .optional() + .label('HD_SESSION_LIFE_TIME'), + }, email: { enableLogin: Joi.boolean() .default(false) @@ -332,6 +344,10 @@ export default registerAs('authConfig', () => { const authConfig = authSchema.validate( { + session: { + secret: process.env.HD_SESSION_SECRET, + lifeTime: parseOptionalInt(process.env.HD_SESSION_LIFE_TIME), + }, email: { enableLogin: process.env.HD_AUTH_EMAIL_ENABLE_LOGIN, enableRegister: process.env.HD_AUTH_EMAIL_ENABLE_REGISTER, diff --git a/src/config/mock/auth.config.mock.ts b/src/config/mock/auth.config.mock.ts index 0fdc9b5ae..2b59e7c59 100644 --- a/src/config/mock/auth.config.mock.ts +++ b/src/config/mock/auth.config.mock.ts @@ -6,6 +6,10 @@ import { registerAs } from '@nestjs/config'; export default registerAs('authConfig', () => ({ + session: { + secret: 'my_secret', + lifeTime: 1209600000, + }, email: { enableLogin: true, enableRegister: true, diff --git a/src/frontend-config/frontend-config.service.spec.ts b/src/frontend-config/frontend-config.service.spec.ts index bb52e239e..f2d43a04a 100644 --- a/src/frontend-config/frontend-config.service.spec.ts +++ b/src/frontend-config/frontend-config.service.spec.ts @@ -23,6 +23,10 @@ import { FrontendConfigService } from './frontend-config.service'; describe('FrontendConfigService', () => { const domain = 'http://md.example.com'; const emptyAuthConfig: AuthConfig = { + session: { + secret: 'my-secret', + lifeTime: 1209600000, + }, email: { enableLogin: false, enableRegister: false,