From e7eb6694a6df11058b3d05aa370c478e3ece6217 Mon Sep 17 00:00:00 2001 From: Philip Molares Date: Sat, 4 Sep 2021 19:24:32 +0200 Subject: [PATCH] feat: change email auth config to local This was done to use the same term. Also email was the old term from HedgeDoc 1 and wildly inaccurate. As we never checked any mail addresses, in fact it was more of a username than anything else. Signed-off-by: Philip Molares --- src/config/auth.config.ts | 28 +++++++++---------- src/config/mock/auth.config.mock.ts | 4 +-- src/frontend-config/frontend-config.dto.ts | 4 +-- .../frontend-config.service.spec.ts | 8 +++--- .../frontend-config.service.ts | 4 +-- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/config/auth.config.ts b/src/config/auth.config.ts index 57406a0f0..a9a98fa40 100644 --- a/src/config/auth.config.ts +++ b/src/config/auth.config.ts @@ -17,9 +17,9 @@ import { export interface AuthConfig { session: { secret: string; - lifeTime: number; + lifetime: number; }; - email: { + local: { enableLogin: boolean; enableRegister: boolean; }; @@ -108,20 +108,20 @@ export interface AuthConfig { const authSchema = Joi.object({ session: { secret: Joi.string().label('HD_SESSION_SECRET'), - lifeTime: Joi.number() - .default(100000) + lifetime: Joi.number() + .default(1209600000) // 14 * 24 * 60 * 60 * 1000ms = 14 days .optional() - .label('HD_SESSION_LIFE_TIME'), + .label('HD_SESSION_LIFETIME'), }, - email: { + local: { enableLogin: Joi.boolean() .default(false) .optional() - .label('HD_AUTH_EMAIL_ENABLE_LOGIN'), + .label('HD_AUTH_LOCAL_ENABLE_LOGIN'), enableRegister: Joi.boolean() .default(false) .optional() - .label('HD_AUTH_EMAIL_ENABLE_REGISTER'), + .label('HD_AUTH_LOCAL_ENABLE_REGISTER'), }, facebook: { clientID: Joi.string().optional().label('HD_AUTH_FACEBOOK_CLIENT_ID'), @@ -211,7 +211,7 @@ const authSchema = Joi.object({ attribute: { id: Joi.string().default('NameId').optional(), username: Joi.string().default('NameId').optional(), - email: Joi.string().default('NameId').optional(), + local: Joi.string().default('NameId').optional(), }, }).optional(), ) @@ -309,7 +309,7 @@ export default registerAs('authConfig', () => { attribute: { id: process.env[`HD_AUTH_SAML_${samlName}_ATTRIBUTE_ID`], username: process.env[`HD_AUTH_SAML_${samlName}_ATTRIBUTE_USERNAME`], - email: process.env[`HD_AUTH_SAML_${samlName}_ATTRIBUTE_USERNAME`], + local: process.env[`HD_AUTH_SAML_${samlName}_ATTRIBUTE_USERNAME`], }, }; }); @@ -346,11 +346,11 @@ export default registerAs('authConfig', () => { { session: { secret: process.env.HD_SESSION_SECRET, - lifeTime: parseOptionalInt(process.env.HD_SESSION_LIFE_TIME), + lifetime: parseOptionalInt(process.env.HD_SESSION_LIFETIME), }, - email: { - enableLogin: process.env.HD_AUTH_EMAIL_ENABLE_LOGIN, - enableRegister: process.env.HD_AUTH_EMAIL_ENABLE_REGISTER, + local: { + enableLogin: process.env.HD_AUTH_LOCAL_ENABLE_LOGIN, + enableRegister: process.env.HD_AUTH_LOCAL_ENABLE_REGISTER, }, facebook: { clientID: process.env.HD_AUTH_FACEBOOK_CLIENT_ID, diff --git a/src/config/mock/auth.config.mock.ts b/src/config/mock/auth.config.mock.ts index 2b59e7c59..9ffada095 100644 --- a/src/config/mock/auth.config.mock.ts +++ b/src/config/mock/auth.config.mock.ts @@ -8,9 +8,9 @@ import { registerAs } from '@nestjs/config'; export default registerAs('authConfig', () => ({ session: { secret: 'my_secret', - lifeTime: 1209600000, + lifetime: 1209600000, }, - email: { + local: { enableLogin: true, enableRegister: true, }, diff --git a/src/frontend-config/frontend-config.dto.ts b/src/frontend-config/frontend-config.dto.ts index 3fd06aa06..6814acf68 100644 --- a/src/frontend-config/frontend-config.dto.ts +++ b/src/frontend-config/frontend-config.dto.ts @@ -71,10 +71,10 @@ export class AuthProviders { oauth2: boolean; /** - * Is internal auth available? + * Is local auth available? */ @IsBoolean() - internal: boolean; + local: boolean; } export class BrandingDto { diff --git a/src/frontend-config/frontend-config.service.spec.ts b/src/frontend-config/frontend-config.service.spec.ts index f2d43a04a..b019f8460 100644 --- a/src/frontend-config/frontend-config.service.spec.ts +++ b/src/frontend-config/frontend-config.service.spec.ts @@ -25,9 +25,9 @@ describe('FrontendConfigService', () => { const emptyAuthConfig: AuthConfig = { session: { secret: 'my-secret', - lifeTime: 1209600000, + lifetime: 1209600000, }, - email: { + local: { enableLogin: false, enableRegister: false, }, @@ -197,7 +197,7 @@ describe('FrontendConfigService', () => { }; const authConfig: AuthConfig = { ...emptyAuthConfig, - email: { + local: { enableLogin, enableRegister, }, @@ -262,7 +262,7 @@ describe('FrontendConfigService', () => { expect(config.authProviders.google).toEqual( !!authConfig.google.clientID, ); - expect(config.authProviders.internal).toEqual( + expect(config.authProviders.local).toEqual( enableLogin, ); expect(config.authProviders.twitter).toEqual( diff --git a/src/frontend-config/frontend-config.service.ts b/src/frontend-config/frontend-config.service.ts index 1492aad8c..f66342188 100644 --- a/src/frontend-config/frontend-config.service.ts +++ b/src/frontend-config/frontend-config.service.ts @@ -44,7 +44,7 @@ export class FrontendConfigService { return { // ToDo: use actual value here allowAnonymous: false, - allowRegister: this.authConfig.email.enableRegister, + allowRegister: this.authConfig.local.enableRegister, authProviders: this.getAuthProviders(), branding: this.getBranding(), customAuthNames: this.getCustomAuthNames(), @@ -66,7 +66,7 @@ export class FrontendConfigService { github: !!this.authConfig.github.clientID, gitlab: this.authConfig.gitlab.length !== 0, google: !!this.authConfig.google.clientID, - internal: this.authConfig.email.enableLogin, + local: this.authConfig.local.enableLogin, ldap: this.authConfig.ldap.length !== 0, oauth2: this.authConfig.oauth2.length !== 0, saml: this.authConfig.saml.length !== 0,