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 <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-09-04 19:24:32 +02:00 committed by David Mehren
parent 43242cccc9
commit e7eb6694a6
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
5 changed files with 24 additions and 24 deletions

View file

@ -17,9 +17,9 @@ import {
export interface AuthConfig { export interface AuthConfig {
session: { session: {
secret: string; secret: string;
lifeTime: number; lifetime: number;
}; };
email: { local: {
enableLogin: boolean; enableLogin: boolean;
enableRegister: boolean; enableRegister: boolean;
}; };
@ -108,20 +108,20 @@ export interface AuthConfig {
const authSchema = Joi.object({ const authSchema = Joi.object({
session: { session: {
secret: Joi.string().label('HD_SESSION_SECRET'), secret: Joi.string().label('HD_SESSION_SECRET'),
lifeTime: Joi.number() lifetime: Joi.number()
.default(100000) .default(1209600000) // 14 * 24 * 60 * 60 * 1000ms = 14 days
.optional() .optional()
.label('HD_SESSION_LIFE_TIME'), .label('HD_SESSION_LIFETIME'),
}, },
email: { local: {
enableLogin: Joi.boolean() enableLogin: Joi.boolean()
.default(false) .default(false)
.optional() .optional()
.label('HD_AUTH_EMAIL_ENABLE_LOGIN'), .label('HD_AUTH_LOCAL_ENABLE_LOGIN'),
enableRegister: Joi.boolean() enableRegister: Joi.boolean()
.default(false) .default(false)
.optional() .optional()
.label('HD_AUTH_EMAIL_ENABLE_REGISTER'), .label('HD_AUTH_LOCAL_ENABLE_REGISTER'),
}, },
facebook: { facebook: {
clientID: Joi.string().optional().label('HD_AUTH_FACEBOOK_CLIENT_ID'), clientID: Joi.string().optional().label('HD_AUTH_FACEBOOK_CLIENT_ID'),
@ -211,7 +211,7 @@ const authSchema = Joi.object({
attribute: { attribute: {
id: Joi.string().default('NameId').optional(), id: Joi.string().default('NameId').optional(),
username: Joi.string().default('NameId').optional(), username: Joi.string().default('NameId').optional(),
email: Joi.string().default('NameId').optional(), local: Joi.string().default('NameId').optional(),
}, },
}).optional(), }).optional(),
) )
@ -309,7 +309,7 @@ export default registerAs('authConfig', () => {
attribute: { attribute: {
id: process.env[`HD_AUTH_SAML_${samlName}_ATTRIBUTE_ID`], id: process.env[`HD_AUTH_SAML_${samlName}_ATTRIBUTE_ID`],
username: process.env[`HD_AUTH_SAML_${samlName}_ATTRIBUTE_USERNAME`], 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: { session: {
secret: process.env.HD_SESSION_SECRET, secret: process.env.HD_SESSION_SECRET,
lifeTime: parseOptionalInt(process.env.HD_SESSION_LIFE_TIME), lifetime: parseOptionalInt(process.env.HD_SESSION_LIFETIME),
}, },
email: { local: {
enableLogin: process.env.HD_AUTH_EMAIL_ENABLE_LOGIN, enableLogin: process.env.HD_AUTH_LOCAL_ENABLE_LOGIN,
enableRegister: process.env.HD_AUTH_EMAIL_ENABLE_REGISTER, enableRegister: process.env.HD_AUTH_LOCAL_ENABLE_REGISTER,
}, },
facebook: { facebook: {
clientID: process.env.HD_AUTH_FACEBOOK_CLIENT_ID, clientID: process.env.HD_AUTH_FACEBOOK_CLIENT_ID,

View file

@ -8,9 +8,9 @@ import { registerAs } from '@nestjs/config';
export default registerAs('authConfig', () => ({ export default registerAs('authConfig', () => ({
session: { session: {
secret: 'my_secret', secret: 'my_secret',
lifeTime: 1209600000, lifetime: 1209600000,
}, },
email: { local: {
enableLogin: true, enableLogin: true,
enableRegister: true, enableRegister: true,
}, },

View file

@ -71,10 +71,10 @@ export class AuthProviders {
oauth2: boolean; oauth2: boolean;
/** /**
* Is internal auth available? * Is local auth available?
*/ */
@IsBoolean() @IsBoolean()
internal: boolean; local: boolean;
} }
export class BrandingDto { export class BrandingDto {

View file

@ -25,9 +25,9 @@ describe('FrontendConfigService', () => {
const emptyAuthConfig: AuthConfig = { const emptyAuthConfig: AuthConfig = {
session: { session: {
secret: 'my-secret', secret: 'my-secret',
lifeTime: 1209600000, lifetime: 1209600000,
}, },
email: { local: {
enableLogin: false, enableLogin: false,
enableRegister: false, enableRegister: false,
}, },
@ -197,7 +197,7 @@ describe('FrontendConfigService', () => {
}; };
const authConfig: AuthConfig = { const authConfig: AuthConfig = {
...emptyAuthConfig, ...emptyAuthConfig,
email: { local: {
enableLogin, enableLogin,
enableRegister, enableRegister,
}, },
@ -262,7 +262,7 @@ describe('FrontendConfigService', () => {
expect(config.authProviders.google).toEqual( expect(config.authProviders.google).toEqual(
!!authConfig.google.clientID, !!authConfig.google.clientID,
); );
expect(config.authProviders.internal).toEqual( expect(config.authProviders.local).toEqual(
enableLogin, enableLogin,
); );
expect(config.authProviders.twitter).toEqual( expect(config.authProviders.twitter).toEqual(

View file

@ -44,7 +44,7 @@ export class FrontendConfigService {
return { return {
// ToDo: use actual value here // ToDo: use actual value here
allowAnonymous: false, allowAnonymous: false,
allowRegister: this.authConfig.email.enableRegister, allowRegister: this.authConfig.local.enableRegister,
authProviders: this.getAuthProviders(), authProviders: this.getAuthProviders(),
branding: this.getBranding(), branding: this.getBranding(),
customAuthNames: this.getCustomAuthNames(), customAuthNames: this.getCustomAuthNames(),
@ -66,7 +66,7 @@ export class FrontendConfigService {
github: !!this.authConfig.github.clientID, github: !!this.authConfig.github.clientID,
gitlab: this.authConfig.gitlab.length !== 0, gitlab: this.authConfig.gitlab.length !== 0,
google: !!this.authConfig.google.clientID, google: !!this.authConfig.google.clientID,
internal: this.authConfig.email.enableLogin, local: this.authConfig.local.enableLogin,
ldap: this.authConfig.ldap.length !== 0, ldap: this.authConfig.ldap.length !== 0,
oauth2: this.authConfig.oauth2.length !== 0, oauth2: this.authConfig.oauth2.length !== 0,
saml: this.authConfig.saml.length !== 0, saml: this.authConfig.saml.length !== 0,