Skip to content

[Common] Enhance OAuth2 logout and discovery handling#3534

Open
Sn0w3y wants to merge 5 commits intoOpenEMS:developfrom
Sn0w3y:OAuth-Improvement
Open

[Common] Enhance OAuth2 logout and discovery handling#3534
Sn0w3y wants to merge 5 commits intoOpenEMS:developfrom
Sn0w3y:OAuth-Improvement

Conversation

@Sn0w3y
Copy link
Collaborator

@Sn0w3y Sn0w3y commented Jan 21, 2026

Summary

  • Add proper OAuth logout functionality with OIDC Discovery support
  • Logout correctly revokes refresh tokens at the OAuth provider (Keycloak, Auth0, Okta, etc.)
  • Uses OIDC Discovery to automatically find the correct logout endpoint (end_session_endpoint or revocation_endpoint)

Changes

Backend

  • AuthUserAuthorizationCodeFlowService: Added logout(String oem, String refreshToken) method
  • OAuthUserAuthenticationServiceImpl: Implements OAuth provider logout using OidcClient with OEM-specific client
    credentials
  • OAuthAuthenticationHandler: Added handler for "logout" method that:
    • Calls authService.logout(oem, refreshToken) to revoke token at OAuth provider
    • Calls wsData.logout() to properly clean up the WebSocket session
    • Returns { success: true } on completion

UI

  • jsonrpc.ts: Added OAuthLogoutRequest and OAuthLogoutResponse classes
  • oauth.service.ts: Added logout() method that sends refresh token to backend for revocation
  • websocket.ts: Modified logout() to:
    • First logout at OAuth provider (if OAuth session)
    • Then send normal logout request to backend
    • Always call onLoggedOut() even on error to ensure local cleanup

This update introduces several key enhancements to the OAuth2 authentication flow, focusing on improving logout functionality and the handling of OIDC Discovery. Specifically:

1. **OAuth2 Logout Enhancements**: Implemented a new logout mechanism that revokes the refresh token at the OAuth provider, ensuring a more secure and complete user logout process. This is particularly important for services where session integrity and termination are critical for security.

2. **OIDC Discovery Handling**: Added support for OIDC Discovery, allowing for dynamic fetching of OAuth2 provider configurations. This makes the authentication flow more flexible and adaptable to different providers, ensuring better compatibility and ease of configuration.

3. **Code Refactoring and Cleanup**: Refactored the authentication-related code to improve clarity and maintainability. This includes better separation of concerns, clearer method names, and the removal of hardcoded URLs in favor of dynamically discovered endpoints.

These changes aim to enhance the security and usability of the OAuth2 authentication flow within the application, providing a more robust and user-friendly authentication experience.
This commit cleans up the OAuthService
@codecov
Copy link

codecov bot commented Jan 21, 2026

Codecov Report

❌ Patch coverage is 10.00000% with 18 lines in your changes missing coverage. Please review.

❌ Your patch check has failed because the patch coverage (10.00%) is below the target coverage (75.00%). You can increase the patch coverage or adjust the target coverage.

❗ There is a different number of reports uploaded between BASE (6368edf) and HEAD (d5f24e1). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (6368edf) HEAD (d5f24e1)
java 1 0
Additional details and impacted files
@@              Coverage Diff               @@
##             develop    #3534       +/-   ##
==============================================
- Coverage      59.41%   29.25%   -30.15%     
==============================================
  Files           3068      290     -2778     
  Lines         133081     8315   -124766     
  Branches        9816     1420     -8396     
==============================================
- Hits           79055     2432    -76623     
+ Misses         51043     5751    -45292     
+ Partials        2983      132     -2851     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@da-Kai da-Kai requested a review from michaelgrill January 30, 2026 17:03
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.

1 participant