mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05:00
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 <philip.molares@udo.edu>
This commit is contained in:
parent
0ef0d1e111
commit
43242cccc9
3 changed files with 24 additions and 0 deletions
|
@ -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,
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
import { registerAs } from '@nestjs/config';
|
||||
|
||||
export default registerAs('authConfig', () => ({
|
||||
session: {
|
||||
secret: 'my_secret',
|
||||
lifeTime: 1209600000,
|
||||
},
|
||||
email: {
|
||||
enableLogin: true,
|
||||
enableRegister: true,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue