From 517cc717a8e2512d970af7d2de2d3a291c39ccb4 Mon Sep 17 00:00:00 2001 From: Wroud Date: Mon, 19 May 2025 17:22:52 +0800 Subject: [PATCH] fix: check configuration id for auth token --- .../packages/core-authentication/src/UserInfoResource.ts | 7 +++++-- .../plugin-authentication/src/AuthenticationService.ts | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/webapp/packages/core-authentication/src/UserInfoResource.ts b/webapp/packages/core-authentication/src/UserInfoResource.ts index 86e0b8d197..517bdf6619 100644 --- a/webapp/packages/core-authentication/src/UserInfoResource.ts +++ b/webapp/packages/core-authentication/src/UserInfoResource.ts @@ -17,6 +17,7 @@ import { AUTH_PROVIDER_LOCAL_ID } from './AUTH_PROVIDER_LOCAL_ID.js'; import { AuthProviderService } from './AuthProviderService.js'; import type { ELMRole } from './ELMRole.js'; import type { IAuthCredentials } from './IAuthCredentials.js'; +import { isNotNullDefined } from '@dbeaver/js-helpers'; export type UserLogoutInfo = AuthLogoutQuery['result']; @@ -89,7 +90,7 @@ export class UserInfoResource extends CachedDataResource return this.data?.userId || ANONYMOUS_USER_ID; } - hasToken(providerId: string): boolean { + hasToken(providerId: string, configurationId?: string): boolean { if (providerId === AUTH_PROVIDER_LOCAL_ID) { return true; } @@ -99,7 +100,9 @@ export class UserInfoResource extends CachedDataResource } // TODO: will be changed due wrong origin in authTokens - return this.data.authTokens.some(token => token.authProvider === providerId); + return this.data.authTokens.some(token => + token.authProvider === providerId && isNotNullDefined(configurationId) ? token.authConfiguration === configurationId : true, + ); } async login(provider: string, { credentials, configurationId, linkUser, forceSessionsLogout }: ILoginOptions): Promise { diff --git a/webapp/packages/plugin-authentication/src/AuthenticationService.ts b/webapp/packages/plugin-authentication/src/AuthenticationService.ts index ff3d888914..f8870d38d9 100644 --- a/webapp/packages/plugin-authentication/src/AuthenticationService.ts +++ b/webapp/packages/plugin-authentication/src/AuthenticationService.ts @@ -247,11 +247,11 @@ export class AuthenticationService extends Bootstrap { return; } - if (!this.userInfoResource.hasToken(data.providerId)) { + if (!this.userInfoResource.hasToken(data.providerId, data.configurationId)) { await this.auth(false, { providerId: data.providerId, configurationId: data.configurationId }); } - if (this.userInfoResource.hasToken(data.providerId)) { + if (this.userInfoResource.hasToken(data.providerId, data.configurationId)) { const provider = contexts.getContext(AuthProviderContext); provider.auth(); }