Skip to content

Replace custom JWT refresh logic with standardized HxClient#6398

Merged
pditommaso merged 2 commits intomasterfrom
fix/tower-fusion-token-refresh-test
Sep 13, 2025
Merged

Replace custom JWT refresh logic with standardized HxClient#6398
pditommaso merged 2 commits intomasterfrom
fix/tower-fusion-token-refresh-test

Conversation

@pditommaso
Copy link
Member

Summary

Replaces custom JWT refresh and retry logic in TowerFusionToken with the standardized HxClient from libseqera, fixing a failing test and improving code maintainability.

Background

The TowerFusionToken class previously implemented its own custom JWT token refresh logic using:

  • Custom HttpClient with cookie management
  • Custom RetryPolicy with Failsafe library
  • Manual token refresh flow with custom cookie parsing
  • Custom retry logic for 401 responses

This approach was error-prone and duplicated functionality already available in the standardized HxClient.

Changes Made

Replaced Custom Implementation with HxClient

Before:

  • Custom HTTP client with cookies (~200 lines)
  • Manual OAuth request construction
  • Custom cookie parsing and token updates
  • Custom retry policy implementation

After:

  • Standardized HxClient with built-in token refresh
  • Automatic OAuth 2.0 compliance
  • Thread-safe coordinated refresh mechanism
  • Consistent retry logic across Nextflow

Benefits of HxClient Integration

  1. Automatic OAuth 2.0 Token Refresh: Handles 401 responses automatically
  2. Thread-Safe Coordinated Refresh: Prevents concurrent refresh calls
  3. Standard Cookie/JSON Response Handling: Supports both token response formats
  4. Consistent Retry Logic: Uses proven retry mechanisms from libseqera
  5. Reduced Code Complexity: ~150 lines of custom code removed

Fixed Test Configuration

Updated TowerFusionEnvTest to match HxClient actual behavior:

  • Cookie-based token refresh responses with Set-Cookie headers
  • Correct verification: 1 refresh call + 2 license endpoint calls
  • Proper OAuth 2.0 flow validation

Technical Details

The HxClient automatically handles the complete OAuth 2.0 refresh flow:

  1. 401 Detection: Recognizes unauthorized responses
  2. Token Refresh: POST to /oauth/access_token with refresh token
  3. Token Update: Parses new tokens from cookies or JSON
  4. Request Retry: Automatically retries with new bearer token

This eliminates the need for custom retry logic and ensures consistency with other Nextflow components using HxClient.

Test Results

  • ✅ All 73 nf-tower tests pass (100% success rate)
  • ✅ Token refresh flow validated with proper OAuth 2.0 compliance
  • ✅ Reduced code complexity and maintenance burden

🤖 Generated with Claude Code

This commit fixes a failing test in TowerFusionEnvTest.groovy that was testing
the token refresh functionality of the TowerFusionToken class.

The main issue was in the test setup and verification expectations:

1. **Updated TowerFusionToken to use HxClient**: Replaced the custom HTTP client
   implementation with the standardized HxClient which provides built-in token
   refresh capabilities following OAuth 2.0 patterns.

2. **Fixed WireMock test configuration**: Updated the test stubs to match the
   actual behavior of HxClient token refresh:
   - Use cookie-based token refresh with Set-Cookie headers
   - Simplified scenario state management
   - Corrected request/response patterns

3. **Updated test verification**: Changed verification logic to match the actual
   flow: 1 refresh call + 2 total requests to the license endpoint (initial 401
   + retry with new token).

The token refresh now works correctly following the OAuth 2.0 standard:
- Initial request with expired token returns 401
- HxClient automatically calls refresh endpoint
- HxClient retries original request with new token
- Request succeeds with valid license token

All 73 tests in the nf-tower plugin now pass (100% success rate).

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
@netlify
Copy link

netlify bot commented Sep 11, 2025

Deploy Preview for nextflow-docs-staging canceled.

Name Link
🔨 Latest commit 996eedd
🔍 Latest deploy log https://app.netlify.com/projects/nextflow-docs-staging/deploys/68c3cfc52196b300085ec21a

Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
@pditommaso pditommaso merged commit c68c1e9 into master Sep 13, 2025
23 checks passed
@pditommaso pditommaso deleted the fix/tower-fusion-token-refresh-test branch September 13, 2025 06:27
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.

2 participants