You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add robust OAuth2 refresh token support and management (#14)
* feat: add robust OAuth2 refresh token support and management
- Add comprehensive refresh token support (RFC 6749) with both fixed (multi-device friendly) and rotation (high security) modes
- Implement refresh token issuance during device code exchange and support refresh token grant type at the token endpoint
- Update documentation: clarify architecture, describe refresh token flow, add new environment variables and endpoint details
- Extend CLI client to persist tokens, support auto-refresh on expiration, and demo seamless re-authentication
- Add settings for refresh token expiration, feature enabling/disabling, and mode selection via environment variables
- Enhance token model with category, status, tracking fields, and management utilities (active/disabled/revoked states)
- Add new token provider methods for refresh token issuance, validation, and rotation (both local and HTTP API)
- Refactor service logic to handle access/refresh tokens in transactional manner, enforce scope, and support rotation
- Provide new store/database utilities for token status management and queries by category
- Update and extend tests for device code flow to cover dual token issuance and user token queries
- Improve .gitignore and example env to exclude new token files
- Add references and improve documentation for refresh token concepts and standards
Signed-off-by: appleboy <appleboy.tw@gmail.com>
* refactor: standardize token type usage and centralize JWT handling
- Replace hardcoded token provider mode strings with constants from config for improved maintainability
- Refactor local token provider to centralize JWT creation, reducing code duplication
- Introduce a helper function for HTTP API token validation, simplifying ValidateToken and ValidateRefreshToken logic
- Set token type using a constant rather than a string literal to avoid typos
- Define a TokenTypeBearer constant for standardized usage across the token logic
Signed-off-by: appleboy <appleboy.tw@gmail.com>
---------
Signed-off-by: appleboy <appleboy.tw@gmail.com>
2. User visits verification_uri (`/device`) in browser, must login first if not authenticated
42
42
3. User submits user_code via `POST /device/verify` → device code marked as authorized
43
-
4. CLI polls `POST /oauth/token` with device_code every 5s → receives JWT when authorized
43
+
4. CLI polls `POST /oauth/token` with device_code every 5s → receives access_token + refresh_token when authorized
44
+
5. CLI uses access_token for API calls (expires in 1 hour)
45
+
6. When access_token expires, CLI calls `POST /oauth/token` with `grant_type=refresh_token` → receives new access_token (fixed mode) or new access_token + refresh_token (rotation mode)
0 commit comments