mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 19:26: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 { GitlabScope, GitlabVersion } from './gitlab.enum';
|
||||||
import {
|
import {
|
||||||
buildErrorMessage,
|
buildErrorMessage,
|
||||||
|
parseOptionalInt,
|
||||||
replaceAuthErrorsWithEnvironmentVariables,
|
replaceAuthErrorsWithEnvironmentVariables,
|
||||||
toArrayConfig,
|
toArrayConfig,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
|
||||||
export interface AuthConfig {
|
export interface AuthConfig {
|
||||||
|
session: {
|
||||||
|
secret: string;
|
||||||
|
lifeTime: number;
|
||||||
|
};
|
||||||
email: {
|
email: {
|
||||||
enableLogin: boolean;
|
enableLogin: boolean;
|
||||||
enableRegister: boolean;
|
enableRegister: boolean;
|
||||||
|
@ -101,6 +106,13 @@ export interface AuthConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
const authSchema = Joi.object({
|
const authSchema = Joi.object({
|
||||||
|
session: {
|
||||||
|
secret: Joi.string().label('HD_SESSION_SECRET'),
|
||||||
|
lifeTime: Joi.number()
|
||||||
|
.default(100000)
|
||||||
|
.optional()
|
||||||
|
.label('HD_SESSION_LIFE_TIME'),
|
||||||
|
},
|
||||||
email: {
|
email: {
|
||||||
enableLogin: Joi.boolean()
|
enableLogin: Joi.boolean()
|
||||||
.default(false)
|
.default(false)
|
||||||
|
@ -332,6 +344,10 @@ export default registerAs('authConfig', () => {
|
||||||
|
|
||||||
const authConfig = authSchema.validate(
|
const authConfig = authSchema.validate(
|
||||||
{
|
{
|
||||||
|
session: {
|
||||||
|
secret: process.env.HD_SESSION_SECRET,
|
||||||
|
lifeTime: parseOptionalInt(process.env.HD_SESSION_LIFE_TIME),
|
||||||
|
},
|
||||||
email: {
|
email: {
|
||||||
enableLogin: process.env.HD_AUTH_EMAIL_ENABLE_LOGIN,
|
enableLogin: process.env.HD_AUTH_EMAIL_ENABLE_LOGIN,
|
||||||
enableRegister: process.env.HD_AUTH_EMAIL_ENABLE_REGISTER,
|
enableRegister: process.env.HD_AUTH_EMAIL_ENABLE_REGISTER,
|
||||||
|
|
|
@ -6,6 +6,10 @@
|
||||||
import { registerAs } from '@nestjs/config';
|
import { registerAs } from '@nestjs/config';
|
||||||
|
|
||||||
export default registerAs('authConfig', () => ({
|
export default registerAs('authConfig', () => ({
|
||||||
|
session: {
|
||||||
|
secret: 'my_secret',
|
||||||
|
lifeTime: 1209600000,
|
||||||
|
},
|
||||||
email: {
|
email: {
|
||||||
enableLogin: true,
|
enableLogin: true,
|
||||||
enableRegister: true,
|
enableRegister: true,
|
||||||
|
|
|
@ -23,6 +23,10 @@ import { FrontendConfigService } from './frontend-config.service';
|
||||||
describe('FrontendConfigService', () => {
|
describe('FrontendConfigService', () => {
|
||||||
const domain = 'http://md.example.com';
|
const domain = 'http://md.example.com';
|
||||||
const emptyAuthConfig: AuthConfig = {
|
const emptyAuthConfig: AuthConfig = {
|
||||||
|
session: {
|
||||||
|
secret: 'my-secret',
|
||||||
|
lifeTime: 1209600000,
|
||||||
|
},
|
||||||
email: {
|
email: {
|
||||||
enableLogin: false,
|
enableLogin: false,
|
||||||
enableRegister: false,
|
enableRegister: false,
|
||||||
|
|
Loading…
Reference in a new issue