Skip to content

Add refresh token support for Docker mode authentication#375

Merged
Edwardvaneechoud merged 4 commits intomainfrom
claude/fix-flowfile-token-refresh-zj3Vx
Mar 30, 2026
Merged

Add refresh token support for Docker mode authentication#375
Edwardvaneechoud merged 4 commits intomainfrom
claude/fix-flowfile-token-refresh-zj3Vx

Conversation

@Edwardvaneechoud
Copy link
Copy Markdown
Owner

Summary

Implements refresh token functionality to enable long-lived sessions in Docker mode while maintaining security through short-lived access tokens. This allows users to remain logged in without re-entering credentials when their access token expires.

Key Changes

Backend (flowfile_core):

  • Added create_refresh_token() and decode_refresh_token() functions to handle refresh token generation and validation
  • Implemented new /auth/refresh endpoint that exchanges a valid refresh token for new access and refresh tokens
  • Updated login endpoint to return both access and refresh tokens in Docker mode
  • Added token type validation to prevent refresh tokens from being used as access tokens
  • Added user status checks (disabled/deleted) during token refresh to maintain security
  • Moved ACCESS_TOKEN_EXPIRE_MINUTES to settings and added REFRESH_TOKEN_EXPIRE_DAYS constant (7 days)
  • Comprehensive test suite covering refresh token functionality, edge cases, and security scenarios

Frontend (flowfile_frontend):

  • Updated AuthResponse interface to include optional refresh_token field
  • Implemented refreshAccessToken() method to exchange refresh tokens for new access tokens
  • Added proactive token refresh in Docker mode when token expires within 5 minutes
  • Updated login flow to store refresh token in localStorage
  • Modified axios interceptor to attempt refresh token exchange before redirecting to login on 401 errors
  • Added refresh token cleanup on logout

Implementation Details

  • Refresh tokens are stored in localStorage and sent via form data to the /auth/refresh endpoint
  • Access tokens include a "type": "access" claim; refresh tokens include "type": "refresh" to prevent token type confusion attacks
  • Refresh tokens expire after 7 days; access tokens expire after 60 minutes
  • User account state is validated during refresh (checks if user is disabled or deleted)
  • Electron mode behavior unchanged - continues to use its existing token refresh mechanism
  • Docker mode now supports seamless session continuation without manual re-login

Users in Docker mode had to re-login every ~1 hour when the access token
expired. This adds a refresh token mechanism (7-day JWT) so the frontend
can silently obtain new access tokens without requiring re-login.

Backend changes:
- Add refresh_token field to Token response model
- Issue refresh tokens alongside access tokens on Docker login
- Add POST /auth/refresh endpoint for token rotation
- Add type claim to JWTs to distinguish access vs refresh tokens
- Reject refresh tokens used as Bearer tokens for API auth
- Fix ACCESS_TOKEN_EXPIRE_MINUTES import (was 60 in jwt.py, 120 in settings.py)

Frontend changes:
- Store refresh token in localStorage on login
- Attempt silent refresh on 401 before redirecting to login page
- Proactively refresh access tokens expiring within 5 minutes
- Clear refresh tokens on logout

https://claude.ai/code/session_018c9637emA3RsjJhg9aLUz6
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 29, 2026

Deploy Preview for flowfile-wasm canceled.

Name Link
🔨 Latest commit b0cc48e
🔍 Latest deploy log https://app.netlify.com/projects/flowfile-wasm/deploys/69c903d9559d5600089039ad

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 29, 2026

Deploy Preview for flowfile-wasm canceled.

Name Link
🔨 Latest commit 696d3e0
🔍 Latest deploy log https://app.netlify.com/projects/flowfile-wasm/deploys/69c9935430ff220007c39fda

@Edwardvaneechoud Edwardvaneechoud merged commit e5ca96c into main Mar 30, 2026
25 checks passed
@Edwardvaneechoud Edwardvaneechoud deleted the claude/fix-flowfile-token-refresh-zj3Vx branch March 30, 2026 18:54
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