Skip to content
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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

AMoreaux
Copy link
Contributor

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.

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.
@AMoreaux AMoreaux self-assigned this Jan 24, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a 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

Comment on lines 26 to 27
err: any,
workspace: { id?: string; subdomain: string },
Copy link
Contributor

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)

Comment on lines 31 to 33
!(err instanceof AuthException) ||
('code' in err && err.code === 'INTERNAL_SERVER_ERROR')
) {
Copy link
Contributor

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

Integrate ExceptionHandlerService into SSOService and refine error capturing in SsoErrorRedirectService. Streamlined error handling logic by consolidating exception capture methods and improving maintainability.
@AMoreaux AMoreaux removed the request for review from charlesBochet January 24, 2025 15:59
@AMoreaux AMoreaux marked this pull request as draft January 24, 2025 15:59
…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.
@AMoreaux AMoreaux marked this pull request as ready for review January 25, 2025 10:50
Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 in microsoft-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

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants