-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(auth): centralize SSO error handling logic #9832
base: main
Are you sure you want to change the base?
Conversation
Introduce `SsoErrorRedirectService` to handle SSO error redirection and exception capturing across the authentication controllers. Refactor Microsoft, Google, and SSO authentication controllers to utilize this service, replacing the previous direct calls to `DomainManagerService`. Added unit tests for the new service to ensure robust error handling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR introduces a new SsoErrorRedirectService
to centralize error handling across SSO authentication flows, improving code organization and maintainability.
- Added
SsoErrorRedirectService
in/auth/services/sso-error-redirect.service.ts
to handle error redirection and exception capturing - Refactored Microsoft, Google, and SSO auth controllers to use the new service, removing direct
DomainManagerService
dependencies - Added comprehensive test coverage in
sso-error-redirect.spec.ts
for various error scenarios - Improved error handling consistency by capturing and redirecting all error types uniformly
- Simplified OIDC issuer discovery logic in
sso.service.ts
with better error handling patterns
8 file(s) reviewed, 11 comment(s)
Edit PR Review Bot Settings | Greptile
packages/twenty-server/src/engine/core-modules/auth/controllers/google-auth.controller.ts
Outdated
Show resolved
Hide resolved
err: any, | ||
workspace: { id?: string; subdomain: string }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: err parameter should be typed more specifically than 'any'. Consider creating a union type of expected error types (AuthException | Error | unknown)
!(err instanceof AuthException) || | ||
('code' in err && err.code === 'INTERNAL_SERVER_ERROR') | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: this condition will capture exceptions for non-AuthExceptions OR AuthExceptions with INTERNAL_SERVER_ERROR code. The logic may need to be reversed to capture ONLY non-AuthExceptions and INTERNAL_SERVER_ERROR AuthExceptions
packages/twenty-server/src/engine/core-modules/auth/services/social-sso.spec.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/services/sso-error-redirect.service.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/services/sso-error-redirect.service.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/services/sso-error-redirect.spec.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/services/sso-error-redirect.spec.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/sso/services/sso.service.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/sso/services/sso.service.ts
Outdated
Show resolved
Hide resolved
Integrate ExceptionHandlerService into SSOService and refine error capturing in SsoErrorRedirectService. Streamlined error handling logic by consolidating exception capture methods and improving maintainability.
…vice Removed SsoErrorRedirectService and its related tests, consolidating its functionality into GuardRedirectService. Updated all references across the codebase to use GuardRedirectService for error handling and redirection in guards and controllers. This change improves modularity and simplifies the error handling logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
(updates since last review)
This PR continues the SSO error handling improvements by implementing the GuardRedirectService across all authentication guards and controllers.
- Added workspace context tracking in
guard-redirect.service.ts
to improve error tracing and redirection - Standardized error handling parameter format across all guards to use
{subdomain}
object structure - Removed debug
console.log
statement inmicrosoft-apis-oauth-exchange-code-for-token.guard.ts
- Added comprehensive test coverage in
social-sso.spec.ts
for workspace lookup scenarios
The changes maintain consistent error handling patterns while adding better context for debugging and error tracking.
19 file(s) reviewed, 14 comment(s)
Edit PR Review Bot Settings | Greptile
packages/twenty-server/src/engine/core-modules/auth/controllers/microsoft-auth.controller.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/controllers/google-auth.controller.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/controllers/google-apis-auth.controller.ts
Show resolved
Hide resolved
...ges/twenty-server/src/engine/core-modules/auth/controllers/microsoft-apis-auth.controller.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/guards/enterprise-features-enabled.guard.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/guards/google-oauth.guard.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/guards/saml-auth.guard.ts
Show resolved
Hide resolved
...ages/twenty-server/src/engine/core-modules/guard-redirect/services/guard-redirect.service.ts
Outdated
Show resolved
Hide resolved
...erver/src/engine/core-modules/auth/guards/google-apis-oauth-exchange-code-for-token.guard.ts
Show resolved
Hide resolved
...erver/src/engine/core-modules/auth/guards/google-apis-oauth-exchange-code-for-token.guard.ts
Show resolved
Hide resolved
Updated parameter types in `dispatchErrorFromGuard` to enhance clarity and type safety, replacing generic types with specific ones. Removed debug log from Microsoft OAuth guard to clean up the codebase. These changes improve maintainability and overall code quality.
…ore/improve-sso-error
Introduce
SsoErrorRedirectService
to handle SSO error redirection and exception capturing across the authentication controllers. Refactor Microsoft, Google, and SSO authentication controllers to utilize this service, replacing the previous direct calls toDomainManagerService
. Added unit tests for the new service to ensure robust error handling.