fix(auth): Improve error management with sso + fix microsoft saml (#9799)

Fix #9760 #9758
This commit is contained in:
Antoine Moreaux
2025-01-24 10:36:18 +01:00
committed by GitHub
parent 3c85516f77
commit 5783c41df2
49 changed files with 505 additions and 309 deletions

View File

@ -129,13 +129,10 @@ export class SSOService {
};
}
async findSSOIdentityProviderById(identityProviderId?: string) {
// if identityProviderId is not provide, typeorm return a random idp instead of undefined
if (!identityProviderId) return undefined;
async findSSOIdentityProviderById(identityProviderId: string) {
return (await this.workspaceSSOIdentityProviderRepository.findOne({
where: { id: identityProviderId },
})) as (SSOConfiguration & WorkspaceSSOIdentityProvider) | undefined;
})) as (SSOConfiguration & WorkspaceSSOIdentityProvider) | null;
}
buildCallbackUrl(

View File

@ -11,6 +11,8 @@ import { SSOService } from 'src/engine/core-modules/sso/services/sso.service';
import { SSOResolver } from 'src/engine/core-modules/sso/sso.resolver';
import { WorkspaceSSOIdentityProvider } from 'src/engine/core-modules/sso/workspace-sso-identity-provider.entity';
import { User } from 'src/engine/core-modules/user/user.entity';
import { DomainManagerModule } from 'src/engine/core-modules/domain-manager/domain-manager.module';
import { GuardRedirectModule } from 'src/engine/core-modules/guard-redirect/guard-redirect.module';
@Module({
imports: [
@ -19,6 +21,8 @@ import { User } from 'src/engine/core-modules/user/user.entity';
'core',
),
BillingModule,
DomainManagerModule,
GuardRedirectModule,
],
exports: [SSOService],
providers: [SSOService, SSOResolver],

View File

@ -3,7 +3,7 @@
import { UseGuards } from '@nestjs/common';
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
import { SSOProviderEnabledGuard } from 'src/engine/core-modules/auth/guards/sso-provider-enabled.guard';
import { EnterpriseFeaturesEnabledGuard } from 'src/engine/core-modules/auth/guards/enterprise-features-enabled.guard';
import { DeleteSsoInput } from 'src/engine/core-modules/sso/dtos/delete-sso.input';
import { DeleteSsoOutput } from 'src/engine/core-modules/sso/dtos/delete-sso.output';
import { EditSsoInput } from 'src/engine/core-modules/sso/dtos/edit-sso.input';
@ -26,7 +26,7 @@ import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
export class SSOResolver {
constructor(private readonly sSOService: SSOService) {}
@UseGuards(WorkspaceAuthGuard, SSOProviderEnabledGuard)
@UseGuards(WorkspaceAuthGuard, EnterpriseFeaturesEnabledGuard)
@Mutation(() => SetupSsoOutput)
async createOIDCIdentityProvider(
@Args('input') setupSsoInput: SetupOIDCSsoInput,
@ -38,7 +38,7 @@ export class SSOResolver {
);
}
@UseGuards(SSOProviderEnabledGuard)
@UseGuards(EnterpriseFeaturesEnabledGuard)
@Query(() => [FindAvailableSSOIDPOutput])
async listSSOIdentityProvidersByWorkspaceId(
@AuthWorkspace() { id: workspaceId }: Workspace,
@ -53,7 +53,7 @@ export class SSOResolver {
return this.sSOService.getAuthorizationUrl(identityProviderId);
}
@UseGuards(WorkspaceAuthGuard, SSOProviderEnabledGuard)
@UseGuards(WorkspaceAuthGuard, EnterpriseFeaturesEnabledGuard)
@Mutation(() => SetupSsoOutput)
async createSAMLIdentityProvider(
@Args('input') setupSsoInput: SetupSAMLSsoInput,
@ -65,7 +65,7 @@ export class SSOResolver {
);
}
@UseGuards(WorkspaceAuthGuard, SSOProviderEnabledGuard)
@UseGuards(WorkspaceAuthGuard, EnterpriseFeaturesEnabledGuard)
@Mutation(() => DeleteSsoOutput)
async deleteSSOIdentityProvider(
@Args('input') { identityProviderId }: DeleteSsoInput,
@ -77,7 +77,7 @@ export class SSOResolver {
);
}
@UseGuards(WorkspaceAuthGuard, SSOProviderEnabledGuard)
@UseGuards(WorkspaceAuthGuard, EnterpriseFeaturesEnabledGuard)
@Mutation(() => EditSsoOutput)
async editSSOIdentityProvider(
@Args('input') input: EditSsoInput,