Skip to content

Conversation

@adamrefaey
Copy link
Collaborator

@adamrefaey adamrefaey commented May 5, 2025

This pull request enhances the DirectCognitoAuthService class in the authentication service to improve token handling, including expiration checks, refresh logic, and error handling. It also adds a new localization string for displaying time-related messages.

Authentication Enhancements:

  • Token Expiration Handling: Added logic to extract and calculate token expiration times (expires_in and expires_at) from the ID token, ensuring accurate tracking of token validity. (frontend/src/common/services/auth/direct-cognito-auth-service.ts, frontend/src/common/services/auth/direct-cognito-auth-service.tsR290-R311)
  • Improved Token Refresh Logic: Refactored the token refresh process into modular methods (isTokenRefreshNeeded, performTokenRefresh, updateTokensWithRefreshed) for better readability and maintainability. This includes handling scenarios where tokens are expired or about to expire. (frontend/src/common/services/auth/direct-cognito-auth-service.ts, [1] [2]
  • Error Handling During Refresh: Enhanced error handling for token refresh failures, including clearing invalid refresh tokens and retrying refresh operations when authentication errors occur. (frontend/src/common/services/auth/direct-cognito-auth-service.ts, frontend/src/common/services/auth/direct-cognito-auth-service.tsL556-R710)

Localization:

@adamrefaey adamrefaey requested review from GuidoBR and Copilot May 5, 2025 21:47
@adamrefaey adamrefaey self-assigned this May 5, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the authentication service by extracting the token expiration from the ID token and improving the token refresh logic.

  • Extracts the expiration time from the ID token and converts it to a local ISO string
  • Refactors and improves the token refresh functions with additional error handling and forced refresh logic when necessary
Files not reviewed (1)
  • frontend/src/common/utils/i18n/resources/en/common.json: Language not supported

@adamrefaey adamrefaey merged commit 5012094 into main May 5, 2025
1 check passed
@adamrefaey adamrefaey deleted the NO-TICKET-FIX-AUTH branch May 5, 2025 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants