fix: check configuration id for auth token

This commit is contained in:
Wroud
2025-05-19 17:22:52 +08:00
parent 918828151c
commit 517cc717a8
2 changed files with 7 additions and 4 deletions
@@ -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<UserInfo | null, void>
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<UserInfo | null, void>
}
// 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<AuthInfo> {
@@ -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();
}