Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.
TypeScript cloud-alternativecollaborationcollaborative-editingdropboxfile-serverfile-sharingfile-storagefile-syncfull-text-searchhomelabnextcloudon-premiseopen-sourceprivacy-firstprivate-cloudrealtimesecureself-hostedstorage-serverwebdav
refactor(auth)!: rename method to provider in AuthConfig and replace authMethod with authProvider for naming consistency
johaven9d187e06f848
diff --git a/backend/src/applications/sync/services/sync-clients-manager.service.spec.ts b/backend/src/applications/sync/services/sync-clients-manager.service.spec.tsindex 33bf2597..375ab4cd 100644--- a/backend/src/applications/sync/services/sync-clients-manager.service.spec.ts+++ b/backend/src/applications/sync/services/sync-clients-manager.service.spec.ts@@ -54,7 +54,7 @@ describe(SyncClientsManager.name, () => {// Mockslet http: { axiosRef: jest.Mock }let authManager: { setCookies: jest.Mock; getTokens: jest.Mock }- let authMethod: { validateUser: jest.Mock }+ let authProvider: { validateUser: jest.Mock }let usersManager: { fromUserId: jest.Mock; updateAccesses: jest.Mock }let syncQueries: {getOrCreateClient: jest.Mock@@ -94,7 +94,7 @@ describe(SyncClientsManager.name, () => {beforeAll(async () => {http = { axiosRef: jest.fn() }authManager = { setCookies: jest.fn(), getTokens: jest.fn() }- authMethod = { validateUser: jest.fn() }+ authProvider = { validateUser: jest.fn() }usersManager = { fromUserId: jest.fn(), updateAccesses: jest.fn() }syncQueries = {getOrCreateClient: jest.fn(),@@ -119,7 +119,7 @@ describe(SyncClientsManager.name, () => {{ provide: SyncQueries, useValue: syncQueries },{ provide: UsersManager, useValue: usersManager },{ provide: AuthManager, useValue: authManager },- { provide: AuthProvider, useValue: authMethod },+ { provide: AuthProvider, useValue: authProvider },{ provide: AuthProvider2FA, useValue: {} }]}).compile()@@ -162,12 +162,12 @@ describe(SyncClientsManager.name, () => {['Unauthorized when credentials are invalid', null, HttpStatus.UNAUTHORIZED],['Forbidden when user lacks DESKTOP_APP permission', { id: 10, login: 'john', havePermission: () => false }, HttpStatus.FORBIDDEN]])('should throw %s', async (_label, user, status) => {- authMethod.validateUser.mockResolvedValue(user)+ authProvider.validateUser.mockResolvedValue(user)await expect(service.register(baseDto as any, '1.2.3.4')).rejects.toMatchObject({ status })})it('should return client token when registration succeeds', async () => {- authMethod.validateUser.mockResolvedValue({ id: 10, login: 'john', havePermission: () => true })+ authProvider.validateUser.mockResolvedValue({ id: 10, login: 'john', havePermission: () => true })syncQueries.getOrCreateClient.mockResolvedValue('token-abc')const r = await service.register(baseDto as any, '1.2.3.4')@@ -176,7 +176,7 @@ describe(SyncClientsManager.name, () => {})it('should throw Internal Server Error when persistence fails', async () => {- authMethod.validateUser.mockResolvedValue({ id: 10, login: 'john', havePermission: () => true })+ authProvider.validateUser.mockResolvedValue({ id: 10, login: 'john', havePermission: () => true })syncQueries.getOrCreateClient.mockRejectedValue(new Error('db error'))await expect(service.register(baseDto as any, '1.2.3.4')).rejects.toMatchObject({ status: HttpStatus.INTERNAL_SERVER_ERROR })})diff --git a/backend/src/applications/sync/services/sync-clients-manager.service.ts b/backend/src/applications/sync/services/sync-clients-manager.service.tsindex 15f5222c..80506c9b 100644--- a/backend/src/applications/sync/services/sync-clients-manager.service.ts+++ b/backend/src/applications/sync/services/sync-clients-manager.service.ts@@ -44,14 +44,14 @@ export class SyncClientsManager {constructor(private readonly http: HttpService,private readonly authManager: AuthManager,- private readonly authMethod: AuthProvider,- private readonly authMethod2Fa: AuthProvider2FA,+ private readonly authProvider: AuthProvider,+ private readonly authProvider2FA: AuthProvider2FA,private readonly usersManager: UsersManager,private readonly syncQueries: SyncQueries) {}async register(clientRegistrationDto: SyncClientRegistrationDto, ip: string): Promise<SyncClientAuthRegistration> {- const user: UserModel = await this.authMethod.validateUser(clientRegistrationDto.login, clientRegistrationDto.password)+ const user: UserModel = await this.authProvider.validateUser(clientRegistrationDto.login, clientRegistrationDto.password)if (!user) {this.logger.warn(`${this.register.name} - auth failed for user *${clientRegistrationDto.login}*`)throw new HttpException('Wrong login or password', HttpStatus.UNAUTHORIZED)@@ -66,10 +66,10 @@ export class SyncClientsManager {this.logger.warn(`${this.register.name} - missing two-fa code for user *${user.login}* (${user.id})`)throw new HttpException('Missing TWO-FA code', HttpStatus.UNAUTHORIZED)}- const authCode = this.authMethod2Fa.validateTwoFactorCode(clientRegistrationDto.code, user.secrets.twoFaSecret)+ const authCode = this.authProvider2FA.validateTwoFactorCode(clientRegistrationDto.code, user.secrets.twoFaSecret)if (!authCode.success) {this.logger.warn(`${this.register.name} - two-fa code for *${user.login}* (${user.id}) - ${authCode.message}`)- const authRCode = await this.authMethod2Fa.validateRecoveryCode(user.id, clientRegistrationDto.code, user.secrets.recoveryCodes)+ const authRCode = await this.authProvider2FA.validateRecoveryCode(user.id, clientRegistrationDto.code, user.secrets.recoveryCodes)if (!authRCode.success) {this.logger.warn(`${this.register.name} - two-fa recovery code for *${user.login}* (${user.id}) - ${authRCode.message}`)this.usersManager.updateAccesses(user, ip, false).catch((e: Error) => this.logger.error(`${this.register.name} - ${e}`))diff --git a/backend/src/authentication/auth.config.ts b/backend/src/authentication/auth.config.tsindex af21ab88..a89a576b 100644--- a/backend/src/authentication/auth.config.ts+++ b/backend/src/authentication/auth.config.ts@@ -8,8 +8,8 @@ import { Exclude, Type } from 'class-transformer'import { IsDefined, IsEnum, IsIn, IsNotEmpty, IsNotEmptyObject, IsObject, IsOptional, IsString, ValidateIf, ValidateNested } from 'class-validator'import { ACCESS_KEY, CSRF_KEY, REFRESH_KEY, WS_KEY } from './constants/auth'import { AUTH_PROVIDER } from './providers/auth-providers.constants'-import { AuthMethodLDAPConfig } from './providers/ldap/auth-ldap.config'-import { AuthMethodOIDCConfig } from './providers/oidc/auth-oidc.config'+import { AuthProviderLDAPConfig } from './providers/ldap/auth-ldap.config'+import { AuthProviderOIDCConfig } from './providers/oidc/auth-oidc.config'import { AuthMFAConfig } from './providers/two-fa/auth-two-fa.config'export class AuthTokenAccessConfig {@@ -85,7 +85,7 @@ export class AuthTokenConfig {export class AuthConfig {@IsString()@IsEnum(AUTH_PROVIDER)- method: AUTH_PROVIDER = AUTH_PROVIDER.MYSQL+ provider: AUTH_PROVIDER = AUTH_PROVIDER.MYSQL@IsOptional()@IsString()@@ -109,17 +109,17 @@ export class AuthConfig {@Type(() => AuthTokenConfig)token: AuthTokenConfig- @ValidateIf((o: AuthConfig) => o.method === AUTH_PROVIDER.LDAP)+ @ValidateIf((o: AuthConfig) => o.provider === AUTH_PROVIDER.LDAP)@IsDefined()@IsObject()@ValidateNested()- @Type(() => AuthMethodLDAPConfig)- ldap: AuthMethodLDAPConfig+ @Type(() => AuthProviderLDAPConfig)+ ldap: AuthProviderLDAPConfig- @ValidateIf((o: AuthConfig) => o.method === AUTH_PROVIDER.OIDC)+ @ValidateIf((o: AuthConfig) => o.provider === AUTH_PROVIDER.OIDC)@IsDefined()@IsObject()@ValidateNested()- @Type(() => AuthMethodOIDCConfig)- oidc: AuthMethodOIDCConfig+ @Type(() => AuthProviderOIDCConfig)+ oidc: AuthProviderOIDCConfig}diff --git a/backend/src/authentication/auth.controller.ts b/backend/src/authentication/auth.controller.tsindex 6eedc150..86bb1be3 100755--- a/backend/src/authentication/auth.controller.ts+++ b/backend/src/authentication/auth.controller.ts@@ -31,7 +31,7 @@ import { TwoFaSetup, TwoFaVerifyResult } from './providers/two-fa/auth-two-fa.inexport class AuthController {constructor(private readonly authManager: AuthManager,- private readonly authMethod2FA: AuthProvider2FA+ private readonly authProvider2FA: AuthProvider2FA) {}@Post(AUTH_ROUTE.LOGIN)@@ -80,21 +80,21 @@ export class AuthController {@UseGuards(UserRolesGuard)@UserHaveRole(USER_ROLE.USER)twoFaInit(@GetUser() user: UserModel): Promise<TwoFaSetup> {- return this.authMethod2FA.initTwoFactor(user)+ return this.authProvider2FA.initTwoFactor(user)}@Post(`${AUTH_ROUTE.TWO_FA_BASE}/${AUTH_ROUTE.TWO_FA_ENABLE}`)@UseGuards(UserRolesGuard)@UserHaveRole(USER_ROLE.USER)twoFaEnable(@Body() body: TwoFaVerifyWithPasswordDto, @Req() req: FastifyAuthenticatedRequest): Promise<TwoFaVerifyResult> {- return this.authMethod2FA.enableTwoFactor(body, req)+ return this.authProvider2FA.enableTwoFactor(body, req)}@Post(`${AUTH_ROUTE.TWO_FA_BASE}/${AUTH_ROUTE.TWO_FA_DISABLE}`)@UseGuards(UserRolesGuard)@UserHaveRole(USER_ROLE.USER)twoFaDisable(@Body() body: TwoFaVerifyWithPasswordDto, @Req() req: FastifyAuthenticatedRequest): Promise<TwoFaVerifyResult> {- return this.authMethod2FA.disableTwoFactor(body, req)+ return this.authProvider2FA.disableTwoFactor(body, req)}@Post(`${AUTH_ROUTE.TWO_FA_BASE}/${AUTH_ROUTE.TWO_FA_LOGIN_VERIFY}`)@@ -105,7 +105,7 @@ export class AuthController {@Req() req: FastifyAuthenticatedRequest,@Res({ passthrough: true }) res: FastifyReply): Promise<TwoFaResponseDto | TwoFaVerifyResult> {- const [authStatus, user] = await this.authMethod2FA.verify(body, req, true)+ const [authStatus, user] = await this.authProvider2FA.verify(body, req, true)if (authStatus.success) {const loginResponseDto = await this.authManager.setCookies(user, res)// clear the temporary 2FA cookie@@ -119,6 +119,6 @@ export class AuthController {@UseGuards(UserRolesGuard, AuthTwoFaGuard)@UserHaveRole(USER_ROLE.ADMINISTRATOR)twoFaReset(@Param('id', ParseIntPipe) userId: number): Promise<TwoFaVerifyResult> {- return this.authMethod2FA.adminResetUserTwoFa(userId)+ return this.authProvider2FA.adminResetUserTwoFa(userId)}}diff --git a/backend/src/authentication/auth.module.ts b/backend/src/authentication/auth.module.tsindex 89ed19fd..8d81b3f5 100755--- a/backend/src/authentication/auth.module.ts+++ b/backend/src/authentication/auth.module.ts@@ -25,7 +25,7 @@ import { AuthTokenRefreshStrategy } from './guards/auth-token-refresh.strategy'import { AUTH_PROVIDER } from './providers/auth-providers.constants'import { AuthProvider } from './providers/auth-providers.models'import { selectAuthProvider } from './providers/auth-providers.utils'-import { AuthMethodOIDCModule } from './providers/oidc/auth-method-oidc.module'+import { AuthProviderOIDCModule } from './providers/oidc/auth-provider-oidc.module'import { AuthProvider2FA } from './providers/two-fa/auth-provider-two-fa.service'@Global()@@ -34,7 +34,7 @@ import { AuthProvider2FA } from './providers/two-fa/auth-provider-two-fa.serviceJwtModule.register({ global: true }),UsersModule,PassportModule,- ...(configuration.auth.method === AUTH_PROVIDER.OIDC ? [AuthMethodOIDCModule] : [])+ ...(configuration.auth.provider === AUTH_PROVIDER.OIDC ? [AuthProviderOIDCModule] : [])],controllers: [AuthController],providers: [@@ -53,7 +53,7 @@ import { AuthProvider2FA } from './providers/two-fa/auth-provider-two-fa.serviceAuthAnonymousStrategy,AuthManager,AuthProvider2FA,- selectAuthProvider(configuration.auth.method)+ selectAuthProvider(configuration.auth.provider)],exports: [AuthManager, AuthProvider, AuthProvider2FA]})diff --git a/backend/src/authentication/auth.service.ts b/backend/src/authentication/auth.service.tsindex 35365420..b373dbfa 100755--- a/backend/src/authentication/auth.service.ts+++ b/backend/src/authentication/auth.service.ts@@ -142,7 +142,7 @@ export class AuthManager {}authSettings(): AuthOIDCSettings | false {- if (configuration.auth.method !== AUTH_PROVIDER.OIDC) {+ if (configuration.auth.provider !== AUTH_PROVIDER.OIDC) {return false}return {diff --git a/backend/src/authentication/guards/auth-basic.guard.spec.ts b/backend/src/authentication/guards/auth-basic.guard.spec.tsindex 28d7d5a9..85967464 100644--- a/backend/src/authentication/guards/auth-basic.guard.spec.ts+++ b/backend/src/authentication/guards/auth-basic.guard.spec.ts@@ -19,7 +19,7 @@ import { AuthBasicStrategy } from './auth-basic.strategy'describe(AuthBasicGuard.name, () => {let authBasicGuard: AuthBasicGuardlet authBasicStrategy: AuthBasicStrategy- let authMethod: AuthProvider+ let authProvider: AuthProviderlet cache: Cachelet userTest: UserModellet encodedAuth: string@@ -56,7 +56,7 @@ describe(AuthBasicGuard.name, () => {authBasicGuard = module.get<AuthBasicGuard>(AuthBasicGuard)authBasicStrategy = module.get<AuthBasicStrategy>(AuthBasicStrategy)- authMethod = module.get<AuthProvider>(AuthProvider)+ authProvider = module.get<AuthProvider>(AuthProvider)cache = module.get<Cache>(Cache)userTest = new UserModel(generateUserTest(), false)encodedAuth = Buffer.from(`${userTest.login}:${userTest.password}`).toString('base64')@@ -66,7 +66,7 @@ describe(AuthBasicGuard.name, () => {it('should be defined', () => {expect(authBasicGuard).toBeDefined()expect(authBasicStrategy).toBeDefined()- expect(authMethod).toBeDefined()+ expect(authProvider).toBeDefined()expect(cache).toBeDefined()expect(encodedAuth).toBeDefined()expect(userTest).toBeDefined()@@ -74,7 +74,7 @@ describe(AuthBasicGuard.name, () => {})it('should validate the user authentication', async () => {- authMethod.validateUser = jest.fn().mockReturnValueOnce(userTest)+ authProvider.validateUser = jest.fn().mockReturnValueOnce(userTest)context.switchToHttp().getRequest.mockReturnValue({raw: { user: '' },headers: { authorization: `Basic ${encodedAuth}` }@@ -88,7 +88,7 @@ describe(AuthBasicGuard.name, () => {const userWithColonPassword = new UserModel({ ...generateUserTest(), password: passwordWithColon }, false)const encodedAuthWithColon = Buffer.from(`${userWithColonPassword.login}:${passwordWithColon}`).toString('base64')- authMethod.validateUser = jest.fn().mockImplementation((login: string, password: string) => {+ authProvider.validateUser = jest.fn().mockImplementation((login: string, password: string) => {expect(login).toBe(userWithColonPassword.login)expect(password).toBe(passwordWithColon)return userWithColonPassword@@ -121,7 +121,7 @@ describe(AuthBasicGuard.name, () => {it('should not validate the user authentication when cache returns undefined and database return null', async () => {cache.get = jest.fn().mockReturnValueOnce(undefined)- authMethod.validateUser = jest.fn().mockReturnValueOnce(null)+ authProvider.validateUser = jest.fn().mockReturnValueOnce(null)jest.spyOn(cache, 'set').mockRejectedValueOnce(new Error('cache failed'))context.switchToHttp().getRequest.mockReturnValue({raw: { user: '' },diff --git a/backend/src/authentication/guards/auth-local.guard.spec.ts b/backend/src/authentication/guards/auth-local.guard.spec.tsindex 443267a9..f8c6cf23 100644--- a/backend/src/authentication/guards/auth-local.guard.spec.ts+++ b/backend/src/authentication/guards/auth-local.guard.spec.ts@@ -16,7 +16,7 @@ import { AuthLocalStrategy } from './auth-local.strategy'describe(AuthLocalGuard.name, () => {let authLocalGuard: AuthLocalGuard- let authMethod: AuthProvider+ let authProvider: AuthProviderlet userTest: UserModellet context: DeepMocked<ExecutionContext>@@ -36,19 +36,19 @@ describe(AuthLocalGuard.name, () => {}).compile()authLocalGuard = module.get<AuthLocalGuard>(AuthLocalGuard)- authMethod = module.get<AuthProvider>(AuthProvider)+ authProvider = module.get<AuthProvider>(AuthProvider)userTest = new UserModel(generateUserTest(), false)context = createMock<ExecutionContext>()})it('should be defined', () => {expect(authLocalGuard).toBeDefined()- expect(authMethod).toBeDefined()+ expect(authProvider).toBeDefined()expect(userTest).toBeDefined()})it('should validate the user authentication', async () => {- authMethod.validateUser = jest.fn().mockReturnValueOnce(userTest)+ authProvider.validateUser = jest.fn().mockReturnValueOnce(userTest)context.switchToHttp().getRequest.mockReturnValue({raw: { user: '' },body: {@@ -62,7 +62,7 @@ describe(AuthLocalGuard.name, () => {it('should not validate the user authentication', async () => {userTest.password = 'password'- authMethod.validateUser = jest.fn().mockReturnValueOnce(null)+ authProvider.validateUser = jest.fn().mockReturnValueOnce(null)context.switchToHttp().getRequest.mockReturnValue({raw: { user: '' },body: {@@ -74,7 +74,7 @@ describe(AuthLocalGuard.name, () => {})it('should throw error due to malformed body', async () => {- authMethod.validateUser = jest.fn().mockReturnValueOnce(null)+ authProvider.validateUser = jest.fn().mockReturnValueOnce(null)context.switchToHttp().getRequest.mockReturnValue({raw: { user: '' },body: nulldiff --git a/backend/src/authentication/guards/auth-local.strategy.ts b/backend/src/authentication/guards/auth-local.strategy.tsindex b083e720..2d11cc6d 100755--- a/backend/src/authentication/guards/auth-local.strategy.ts+++ b/backend/src/authentication/guards/auth-local.strategy.ts@@ -15,7 +15,7 @@ import { AuthProvider } from '../providers/auth-providers.models'@Injectable()export class AuthLocalStrategy extends PassportStrategy(Strategy, 'local') implements AbstractStrategy {constructor(- private readonly authMethod: AuthProvider,+ private readonly authProvider: AuthProvider,private readonly logger: PinoLogger) {super({ usernameField: 'login', passwordField: 'password', passReqToCallback: true })@@ -25,7 +25,7 @@ export class AuthLocalStrategy extends PassportStrategy(Strategy, 'local') impleloginOrEmail = loginOrEmail.trim()password = password.trim()this.logger.assign({ user: loginOrEmail })- const user: UserModel = await this.authMethod.validateUser(loginOrEmail, password, req.ip)+ const user: UserModel = await this.authProvider.validateUser(loginOrEmail, password, req.ip)if (user) {user.removePassword()return userdiff --git a/backend/src/authentication/providers/auth-providers.utils.ts b/backend/src/authentication/providers/auth-providers.utils.tsindex c52419bd..0404cc10 100644--- a/backend/src/authentication/providers/auth-providers.utils.ts+++ b/backend/src/authentication/providers/auth-providers.utils.ts@@ -15,7 +15,7 @@ import { AuthProviderOIDC } from './oidc/auth-provider-oidc.service'export function selectAuthProvider(provider: AUTH_PROVIDER): Provider {switch (provider) {case AUTH_PROVIDER.OIDC:- // AuthMethodOIDC is already provided by AuthMethodOIDCModule+ // `AuthProviderOIDC` is already provided by `AuthProviderOIDCModule`return { provide: AuthProvider, useExisting: AuthProviderOIDC }case AUTH_PROVIDER.LDAP:diff --git a/backend/src/authentication/providers/ldap/auth-ldap.config.ts b/backend/src/authentication/providers/ldap/auth-ldap.config.tsindex 237a446f..fe2bb535 100644--- a/backend/src/authentication/providers/ldap/auth-ldap.config.ts+++ b/backend/src/authentication/providers/ldap/auth-ldap.config.ts@@ -21,7 +21,7 @@ import {import { USER_PERMISSION } from '../../../applications/users/constants/user'import { LDAP_COMMON_ATTR, LDAP_LOGIN_ATTR } from './auth-ldap.constants'-export class AuthMethodLDAPAttributesConfig {+export class AuthProviderLDAPAttributesConfig {@IsOptional()@Transform(({ value }) => value || LDAP_LOGIN_ATTR.UID)@IsEnum(LDAP_LOGIN_ATTR)@@ -33,7 +33,7 @@ export class AuthMethodLDAPAttributesConfig {email: string = LDAP_COMMON_ATTR.MAIL}-export class AuthMethodLDAPOptionsConfig {+export class AuthProviderLDAPOptionsConfig {@IsOptional()@IsString()adminGroup?: string@@ -52,7 +52,7 @@ export class AuthMethodLDAPOptionsConfig {enablePasswordAuthFallback? = true}-export class AuthMethodLDAPConfig {+export class AuthProviderLDAPConfig {@Transform(({ value }) => (Array.isArray(value) ? value.filter((v: string) => Boolean(v)) : value))@ArrayNotEmpty()@IsArray()@@ -71,8 +71,8 @@ export class AuthMethodLDAPConfig {@IsNotEmptyObject()@IsObject()@ValidateNested()- @Type(() => AuthMethodLDAPAttributesConfig)- attributes: AuthMethodLDAPAttributesConfig = new AuthMethodLDAPAttributesConfig()+ @Type(() => AuthProviderLDAPAttributesConfig)+ attributes: AuthProviderLDAPAttributesConfig = new AuthProviderLDAPAttributesConfig()@IsOptional()@IsString()@@ -86,6 +86,6 @@ export class AuthMethodLDAPConfig {@IsNotEmptyObject()@IsObject()@ValidateNested()- @Type(() => AuthMethodLDAPOptionsConfig)- options: AuthMethodLDAPOptionsConfig = new AuthMethodLDAPOptionsConfig()+ @Type(() => AuthProviderLDAPOptionsConfig)+ options: AuthProviderLDAPOptionsConfig = new AuthProviderLDAPOptionsConfig()}diff --git a/backend/src/authentication/providers/ldap/auth-provider-ldap.service.spec.ts b/backend/src/authentication/providers/ldap/auth-provider-ldap.service.spec.tsindex 2d6e67da..5f189d61 100644--- a/backend/src/authentication/providers/ldap/auth-provider-ldap.service.spec.ts+++ b/backend/src/authentication/providers/ldap/auth-provider-ldap.service.spec.ts@@ -14,7 +14,7 @@ import { AdminUsersManager } from '../../../applications/users/services/admin-usimport { UsersManager } from '../../../applications/users/services/users-manager.service'import * as commonFunctions from '../../../common/functions'import { configuration } from '../../../configuration/config.environment'-import type { AuthMethodLDAPConfig } from './auth-ldap.config'+import type { AuthProviderLDAPConfig } from './auth-ldap.config'import { LDAP_COMMON_ATTR, LDAP_LOGIN_ATTR } from './auth-ldap.constants'import { AuthProviderLDAP } from './auth-provider-ldap.service'@@ -52,17 +52,17 @@ const ldapClient = {;(Client as Mocked<any>).mockImplementation(() => ldapClient)describe(AuthProviderLDAP.name, () => {- let authMethodLdapService: AuthProviderLDAP+ let authProviderLDAP: AuthProviderLDAPlet usersManager: Mocked<UsersManager>let adminUsersManager: Mocked<AdminUsersManager>- type LdapConfigOverrides = Omit<Partial<AuthMethodLDAPConfig>, 'attributes' | 'options'> & {- attributes?: Partial<AuthMethodLDAPConfig['attributes']>- options?: Partial<AuthMethodLDAPConfig['options']>+ type LdapConfigOverrides = Omit<Partial<AuthProviderLDAPConfig>, 'attributes' | 'options'> & {+ attributes?: Partial<AuthProviderLDAPConfig['attributes']>+ options?: Partial<AuthProviderLDAPConfig['options']>}const setLdapConfig = (overrides: LdapConfigOverrides = {}) => {- const base: AuthMethodLDAPConfig = {+ const base: AuthProviderLDAPConfig = {servers: ['ldap://localhost:389'],attributes: { login: LDAP_LOGIN_ATTR.UID, email: LDAP_COMMON_ATTR.MAIL },baseDN: 'ou=people,dc=example,dc=org',@@ -73,15 +73,15 @@ describe(AuthProviderLDAP.name, () => {enablePasswordAuthFallback: true}}- const next: AuthMethodLDAPConfig = {+ const next: AuthProviderLDAPConfig = {...base,...overrides,attributes: { ...base.attributes, ...(overrides.attributes || {}) },options: { ...base.options, ...(overrides.options || {}) }}configuration.auth.ldap = next- ;(authMethodLdapService as any).ldapConfig = next- ;(authMethodLdapService as any).isAD = [LDAP_LOGIN_ATTR.SAM, LDAP_LOGIN_ATTR.UPN].includes(next.attributes.login)+ ;(authProviderLDAP as any).ldapConfig = next+ ;(authProviderLDAP as any).isAD = [LDAP_LOGIN_ATTR.SAM, LDAP_LOGIN_ATTR.UPN].includes(next.attributes.login)}const mockBindResolve = () => {@@ -123,7 +123,7 @@ describe(AuthProviderLDAP.name, () => {}).compile()module.useLogger(['fatal'])- authMethodLdapService = module.get<AuthProviderLDAP>(AuthProviderLDAP)+ authProviderLDAP = module.get<AuthProviderLDAP>(AuthProviderLDAP)adminUsersManager = module.get<Mocked<AdminUsersManager>>(AdminUsersManager)usersManager = module.get<Mocked<UsersManager>>(UsersManager)})@@ -139,7 +139,7 @@ describe(AuthProviderLDAP.name, () => {})it('should be defined', () => {- expect(authMethodLdapService).toBeDefined()+ expect(authProviderLDAP).toBeDefined()expect(usersManager).toBeDefined()expect(adminUsersManager).toBeDefined()expect(ldapClient).toBeDefined()@@ -151,7 +151,7 @@ describe(AuthProviderLDAP.name, () => {const dbAuthResult: any = { ...guestUser, token: 'jwt' }usersManager.logUser.mockResolvedValue(dbAuthResult)- const res = await authMethodLdapService.validateUser('guest1', 'pass', '127.0.0.1')+ const res = await authProviderLDAP.validateUser('guest1', 'pass', '127.0.0.1')expect(res).toEqual(dbAuthResult)expect(usersManager.logUser).toHaveBeenCalledWith(guestUser, 'pass', '127.0.0.1', undefined)@@ -163,7 +163,7 @@ describe(AuthProviderLDAP.name, () => {usersManager.findUser.mockResolvedValue(user)usersManager.logUser.mockResolvedValue(user)- const res = await authMethodLdapService.validateUser('john', 'app-password', '10.0.0.2', 'webdav' as any)+ const res = await authProviderLDAP.validateUser('john', 'app-password', '10.0.0.2', 'webdav' as any)expect(res).toBe(user)expect(usersManager.logUser).toHaveBeenCalledWith(user, 'app-password', '10.0.0.2', 'webdav')@@ -172,9 +172,9 @@ describe(AuthProviderLDAP.name, () => {it('should throw FORBIDDEN for locked account', async () => {usersManager.findUser.mockResolvedValue({ login: 'john', isGuest: false, isActive: false } as UserModel)- const loggerErrorSpy = jest.spyOn(authMethodLdapService['logger'], 'error').mockImplementation(() => undefined as any)+ const loggerErrorSpy = jest.spyOn(authProviderLDAP['logger'], 'error').mockImplementation(() => undefined as any)- await expect(authMethodLdapService.validateUser('john', 'pwd')).rejects.toThrow(/account locked/i)+ await expect(authProviderLDAP.validateUser('john', 'pwd')).rejects.toThrow(/account locked/i)expect(loggerErrorSpy).toHaveBeenCalled()})@@ -183,7 +183,7 @@ describe(AuthProviderLDAP.name, () => {usersManager.findUser.mockResolvedValue(existingUser)mockBindRejectInvalid('invalid credentials')- const res = await authMethodLdapService.validateUser('john', 'badpwd', '10.0.0.1')+ const res = await authProviderLDAP.validateUser('john', 'badpwd', '10.0.0.1')expect(res).toBeNull()expect(usersManager.logUser).not.toHaveBeenCalled()@@ -196,12 +196,12 @@ describe(AuthProviderLDAP.name, () => {mockBindResolve()mockSearchEntries([])- const resA = await authMethodLdapService.validateUser('john', 'pwd')+ const resA = await authProviderLDAP.validateUser('john', 'pwd')expect(resA).toBeNull()ldapClient.search.mockRejectedValue(new Error('search failed'))- const resB = await authMethodLdapService.validateUser('john', 'pwd')+ const resB = await authProviderLDAP.validateUser('john', 'pwd')expect(resB).toBeNull()expect(usersManager.updateAccesses).not.toHaveBeenCalled()@@ -215,7 +215,7 @@ describe(AuthProviderLDAP.name, () => {ldapClient.bind.mockRejectedValue({ errors: [err] })ldapClient.unbind.mockResolvedValue(undefined)- const res = await authMethodLdapService.validateUser('john', 'pwd', '10.0.0.3')+ const res = await authProviderLDAP.validateUser('john', 'pwd', '10.0.0.3')expect(res).toBe(existingUser)expect(usersManager.logUser).toHaveBeenCalledWith(existingUser, 'pwd', '10.0.0.3')@@ -229,7 +229,7 @@ describe(AuthProviderLDAP.name, () => {ldapClient.bind.mockRejectedValue({ errors: [err] })ldapClient.unbind.mockResolvedValue(undefined)- await expect(authMethodLdapService.validateUser('john', 'pwd')).rejects.toThrow(/authentication service error/i)+ await expect(authProviderLDAP.validateUser('john', 'pwd')).rejects.toThrow(/authentication service error/i)})it('should allow admin local fallback when LDAP is unavailable even if fallback is disabled', async () => {@@ -241,7 +241,7 @@ describe(AuthProviderLDAP.name, () => {ldapClient.bind.mockRejectedValue({ errors: [err] })ldapClient.unbind.mockResolvedValue(undefined)- const res = await authMethodLdapService.validateUser('john', 'pwd')+ const res = await authProviderLDAP.validateUser('john', 'pwd')expect(res).toBe(existingUser)expect(usersManager.logUser).toHaveBeenCalledWith(existingUser, 'pwd', undefined)@@ -251,9 +251,9 @@ describe(AuthProviderLDAP.name, () => {usersManager.findUser.mockResolvedValue(null)mockBindResolve()mockSearchEntries([{ uid: 'jane', cn: 'Jane Doe', mail: undefined }])- const loggerErrorSpy = jest.spyOn(authMethodLdapService['logger'], 'error').mockImplementation(() => undefined as any)+ const loggerErrorSpy = jest.spyOn(authProviderLDAP['logger'], 'error').mockImplementation(() => undefined as any)- const res = await authMethodLdapService.validateUser('jane', 'pwd')+ const res = await authProviderLDAP.validateUser('jane', 'pwd')expect(res).toBeNull()expect(adminUsersManager.createUserOrGuest).not.toHaveBeenCalled()@@ -263,12 +263,12 @@ describe(AuthProviderLDAP.name, () => {it('should throw UNAUTHORIZED when autoCreateUser is disabled', async () => {setLdapConfig({ options: { autoCreateUser: false } })usersManager.findUser.mockResolvedValue(null)- const checkAuthSpy = jest.spyOn<any, any>(authMethodLdapService as any, 'checkAuth').mockResolvedValue({+ const checkAuthSpy = jest.spyOn<any, any>(authProviderLDAP as any, 'checkAuth').mockResolvedValue({uid: 'john',mail: '[email protected]'})- await expect(authMethodLdapService.validateUser('john', 'pwd')).rejects.toThrow(/user not found/i)+ await expect(authProviderLDAP.validateUser('john', 'pwd')).rejects.toThrow(/user not found/i)checkAuthSpy.mockRestore()})@@ -294,7 +294,7 @@ describe(AuthProviderLDAP.name, () => {adminUsersManager.createUserOrGuest.mockResolvedValue(createdUser)usersManager.fromUserId.mockResolvedValue(createdUser)- const res = await authMethodLdapService.validateUser('john', 'pwd', '192.168.1.10')+ const res = await authProviderLDAP.validateUser('john', 'pwd', '192.168.1.10')expect(adminUsersManager.createUserOrGuest).toHaveBeenCalledWith({@@ -320,7 +320,7 @@ describe(AuthProviderLDAP.name, () => {mockSearchEntries([{ uid: 'john', cn: 'John Doe', mail: '[email protected]' }])jest.spyOn(commonFunctions, 'comparePassword').mockResolvedValue(true)- await authMethodLdapService.validateUser('john', 'pwd')+ await authProviderLDAP.validateUser('john', 'pwd')expect(adminUsersManager.updateUserOrGuest).toHaveBeenCalled()const updateArgs = adminUsersManager.updateUserOrGuest.mock.calls[0][1]@@ -336,7 +336,7 @@ describe(AuthProviderLDAP.name, () => {const compareSpy = jest.spyOn(commonFunctions, 'comparePassword').mockResolvedValue(false)const splitSpy = jest.spyOn(commonFunctions, 'splitFullName').mockReturnValue({ firstName: 'Jane', lastName: 'Doe' })- const res = await authMethodLdapService.validateUser('john', 'new-plain-password', '127.0.0.2')+ const res = await authProviderLDAP.validateUser('john', 'new-plain-password', '127.0.0.2')expect(adminUsersManager.updateUserOrGuest).toHaveBeenCalledWith(6,@@ -362,21 +362,21 @@ describe(AuthProviderLDAP.name, () => {mockBindResolve()mockSearchEntries([{ uid: 'jane', cn: 'Jane Doe', mail: '[email protected]' }])- await expect(authMethodLdapService.validateUser('john', 'pwd')).rejects.toThrow(/account matching error/i)+ await expect(authProviderLDAP.validateUser('john', 'pwd')).rejects.toThrow(/account matching error/i)})it('should build LDAP logins and filters for AD and standard LDAP', () => {setLdapConfig({ attributes: { login: LDAP_LOGIN_ATTR.UPN }, upnSuffix: 'sync-in.com', filter: '(memberOf=cn=staff)' })- const adLogin = (authMethodLdapService as any).buildLdapLogin('john')+ const adLogin = (authProviderLDAP as any).buildLdapLogin('john')expect(adLogin).toBe('[email protected]')- const adFilter = (authMethodLdapService as any).buildUserFilter('SYNC-IN\\john', '(memberOf=cn=staff)')+ const adFilter = (authProviderLDAP as any).buildUserFilter('SYNC-IN\\john', '(memberOf=cn=staff)')expect(adFilter).toContain('(sAMAccountName=john)')expect(adFilter).toContain('(userPrincipalName=john)')expect(adFilter).toContain('(mail=john)')expect(adFilter).toContain('(memberOf=cn=staff)')setLdapConfig({ attributes: { login: LDAP_LOGIN_ATTR.UID }, filter: '(department=IT)' })- const ldapFilter = (authMethodLdapService as any).buildUserFilter('john', '(department=IT)')+ const ldapFilter = (authProviderLDAP as any).buildUserFilter('john', '(department=IT)')expect(ldapFilter).toContain('(uid=john)')expect(ldapFilter).toContain('(cn=john)')expect(ldapFilter).toContain('(mail=john)')@@ -390,7 +390,7 @@ describe(AuthProviderLDAP.name, () => {memberOf: ['CN=Admins,OU=Groups,DC=example,DC=org', 'CN=Staff,OU=Groups,DC=example,DC=org']}- const normalized = (authMethodLdapService as any).convertToLdapUserEntry(entry)+ const normalized = (authProviderLDAP as any).convertToLdapUserEntry(entry)expect(normalized.uid).toBe('john')expect(normalized.mail).toBe('[email protected]')@@ -399,7 +399,7 @@ describe(AuthProviderLDAP.name, () => {it('should build LDAP logins for SAM account name when netbiosName is set', () => {setLdapConfig({ attributes: { login: LDAP_LOGIN_ATTR.SAM }, netbiosName: 'SYNC' })- const samLogin = (authMethodLdapService as any).buildLdapLogin('john')+ const samLogin = (authProviderLDAP as any).buildLdapLogin('john')expect(samLogin).toBe('SYNC\\john')})})diff --git a/backend/src/authentication/providers/ldap/auth-provider-ldap.service.ts b/backend/src/authentication/providers/ldap/auth-provider-ldap.service.tsindex 58ceaa38..cd012f79 100644--- a/backend/src/authentication/providers/ldap/auth-provider-ldap.service.ts+++ b/backend/src/authentication/providers/ldap/auth-provider-ldap.service.ts@@ -16,7 +16,7 @@ import { comparePassword, splitFullName } from '../../../common/functions'import { configuration } from '../../../configuration/config.environment'import type { AUTH_SCOPE } from '../../constants/scope'import { AuthProvider } from '../auth-providers.models'-import type { AuthMethodLDAPConfig } from './auth-ldap.config'+import type { AuthProviderLDAPConfig } from './auth-ldap.config'import { ALL_LDAP_ATTRIBUTES, LDAP_COMMON_ATTR, LDAP_LOGIN_ATTR } from './auth-ldap.constants'type LdapUserEntry = Entry & Record<LDAP_LOGIN_ATTR | (typeof LDAP_COMMON_ATTR)[keyof typeof LDAP_COMMON_ATTR], string>@@ -24,7 +24,7 @@ type LdapUserEntry = Entry & Record<LDAP_LOGIN_ATTR | (typeof LDAP_COMMON_ATTR)[@Injectable()export class AuthProviderLDAP implements AuthProvider {private readonly logger = new Logger(AuthProviderLDAP.name)- private readonly ldapConfig: AuthMethodLDAPConfig = configuration.auth.ldap+ private readonly ldapConfig: AuthProviderLDAPConfig = configuration.auth.ldapprivate readonly isAD = this.ldapConfig.attributes.login === LDAP_LOGIN_ATTR.SAM || this.ldapConfig.attributes.login === LDAP_LOGIN_ATTR.UPNprivate clientOptions: ClientOptions = { timeout: 6000, connectTimeout: 6000, url: '' }diff --git a/backend/src/authentication/providers/oidc/auth-oidc.config.ts b/backend/src/authentication/providers/oidc/auth-oidc.config.tsindex 5e59dedb..2bf75b78 100644--- a/backend/src/authentication/providers/oidc/auth-oidc.config.ts+++ b/backend/src/authentication/providers/oidc/auth-oidc.config.ts@@ -21,7 +21,7 @@ import {import { USER_PERMISSION } from '../../../applications/users/constants/user'import { OAuthTokenEndpoint } from './auth-oidc.constants'-export class AuthMethodOIDCSecurityConfig {+export class AuthProviderOIDCSecurityConfig {@IsString()@Matches(/\bopenid\b/, { message: 'OIDC scope must include "openid"' })scope = 'openid email profile'@@ -43,7 +43,7 @@ export class AuthMethodOIDCSecurityConfig {skipSubjectCheck? = false}-export class AuthMethodOIDCOptionsConfig {+export class AuthProviderOIDCOptionsConfig {@IsOptional()@IsBoolean()autoCreateUser? = true@@ -70,7 +70,7 @@ export class AuthMethodOIDCOptionsConfig {buttonText: string = 'Continue with OpenID Connect'}-export class AuthMethodOIDCConfig {+export class AuthProviderOIDCConfig {@IsString()@IsNotEmpty()issuerUrl: string@@ -91,13 +91,13 @@ export class AuthMethodOIDCConfig {@IsNotEmptyObject()@IsObject()@ValidateNested()- @Type(() => AuthMethodOIDCOptionsConfig)- options: AuthMethodOIDCOptionsConfig = new AuthMethodOIDCOptionsConfig()+ @Type(() => AuthProviderOIDCOptionsConfig)+ options: AuthProviderOIDCOptionsConfig = new AuthProviderOIDCOptionsConfig()@IsDefined()@IsNotEmptyObject()@IsObject()@ValidateNested()- @Type(() => AuthMethodOIDCSecurityConfig)- security: AuthMethodOIDCSecurityConfig = new AuthMethodOIDCSecurityConfig()+ @Type(() => AuthProviderOIDCSecurityConfig)+ security: AuthProviderOIDCSecurityConfig = new AuthProviderOIDCSecurityConfig()}diff --git a/backend/src/authentication/providers/oidc/auth-method-oidc.module.ts b/backend/src/authentication/providers/oidc/auth-provider-oidc.module.tssimilarity index 92%rename from backend/src/authentication/providers/oidc/auth-method-oidc.module.tsrename to backend/src/authentication/providers/oidc/auth-provider-oidc.module.tsindex d08660bf..c3bdd210 100644--- a/backend/src/authentication/providers/oidc/auth-method-oidc.module.ts+++ b/backend/src/authentication/providers/oidc/auth-provider-oidc.module.ts@@ -13,4 +13,4 @@ import { AuthProviderOIDC } from './auth-provider-oidc.service'providers: [AuthProviderOIDC],exports: [AuthProviderOIDC]})-export class AuthMethodOIDCModule {}+export class AuthProviderOIDCModule {}diff --git a/backend/src/authentication/providers/oidc/auth-provider-oidc.service.ts b/backend/src/authentication/providers/oidc/auth-provider-oidc.service.tsindex b8f100bd..c74a2c44 100644--- a/backend/src/authentication/providers/oidc/auth-provider-oidc.service.ts+++ b/backend/src/authentication/providers/oidc/auth-provider-oidc.service.ts@@ -37,13 +37,13 @@ import { TOKEN_TYPE } from '../../interfaces/token.interface'import { AUTH_PROVIDER } from '../auth-providers.constants'import { AuthProvider } from '../auth-providers.models'import { OAuthDesktopCallBackURI, OAuthDesktopLoopbackPorts, OAuthDesktopPortParam } from './auth-oidc-desktop.constants'-import type { AuthMethodOIDCConfig } from './auth-oidc.config'+import type { AuthProviderOIDCConfig } from './auth-oidc.config'import { OAuthCookie, OAuthCookieSettings, OAuthTokenEndpoint } from './auth-oidc.constants'@Injectable()export class AuthProviderOIDC implements AuthProvider {private readonly logger = new Logger(AuthProviderOIDC.name)- private readonly oidcConfig: AuthMethodOIDCConfig = configuration.auth.oidc+ private readonly oidcConfig: AuthProviderOIDCConfig = configuration.auth.oidcprivate frontendBaseUrl: stringprivate config: Configuration = nulldiff --git a/backend/src/configuration/config.environment.ts b/backend/src/configuration/config.environment.tsindex e7398c5b..4c9a535e 100755--- a/backend/src/configuration/config.environment.ts+++ b/backend/src/configuration/config.environment.ts@@ -47,14 +47,5 @@ function loadConfiguration(): GlobalConfig {config.applications.files.usersPath = join(config.applications.files.dataPath, 'users')config.applications.files.spacesPath = join(config.applications.files.dataPath, 'spaces')config.applications.files.tmpPath = join(config.applications.files.dataPath, 'tmp')- // DEPRECATIONS- // ldap.adminGroup → ldap.options.adminGroup- if (typeof config.auth.ldap['adminGroup'] === 'string' && config.auth.ldap['adminGroup'].length > 0) {- config.auth.ldap.options.adminGroup = config.auth.ldap['adminGroup']- console.warn(- '[DEPRECATED][CONFIGURATION] auth.ldap.adminGroup is deprecated and will be removed in a future version. ' +- 'Please use auth.ldap.options.adminGroup instead.'- )- }return transformAndValidate(GlobalConfig, config, { exposeDefaultValues: true }, { skipMissingProperties: false })}diff --git a/environment/environment.dist.yaml b/environment/environment.dist.yamlindex c6021e1c..d0a5a01b 100755--- a/environment/environment.dist.yaml+++ b/environment/environment.dist.yaml@@ -77,9 +77,9 @@ mail:# default: `false`debug: falseauth:- # adapter : `mysql` | `ldap` | `oidc`+ # provider : `mysql` | `ldap` | `oidc`# default: `mysql`- method: mysql+ provider: mysql# Key used to encrypt user secret keys in the database# Optional but strongly recommended# Warning: do not change or remove the encryption key after MFA activation, or the codes will become invalid