Support refresh tokens#17
Conversation
WalkthroughAdds grant-type routing to the token endpoint: implements explicit Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant TokenEndpoint as Token Endpoint
participant OAuth2Cfg as OAuth2 Config
participant TokenSrc as Token Source
Client->>TokenEndpoint: POST /token (grant_type, params)
alt grant_type == authorization_code
TokenEndpoint->>TokenEndpoint: Validate `code`
TokenEndpoint->>TokenEndpoint: Resolve `redirect_uri` (fallbacks / allowlist)
TokenEndpoint->>TokenEndpoint: Configure PKCE if `code_verifier`
TokenEndpoint->>OAuth2Cfg: Exchange code for tokens
OAuth2Cfg-->>TokenEndpoint: Token response (access, id, refresh, scope)
else grant_type == refresh_token
TokenEndpoint->>TokenEndpoint: Validate `refresh_token`
TokenEndpoint->>TokenSrc: Create TokenSource from refresh token
TokenSrc-->>TokenEndpoint: New access token
else unsupported grant_type
TokenEndpoint-->>Client: 400 Unsupported grant type
end
TokenEndpoint-->>Client: 200 Token response (when successful)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (1)**/*.go📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
handlers.go (1)
579-597: Refresh token implementation looks correct.The usage of
oauth2.Config.TokenSourcewith a token containing only theRefreshTokenfield is the idiomatic way to perform token refresh with thegolang.org/x/oauth2library. WhenToken()is called, it will detect the token needs refreshing and use the refresh token appropriately.Minor inconsistency: Line 576 returns
http.StatusInternalServerError(500) for authorization code exchange failures, while line 595 returnshttp.StatusBadGateway(502) for refresh token failures. Both are upstream OAuth provider errors, so consider using consistent status codes.♻️ Optional: Use consistent error status codes
token, err = h.oauth2Config.Exchange(ctx, code) if err != nil { h.logger.Error("OAuth2: Token exchange failed: %v", err) - http.Error(w, "Token exchange failed", http.StatusInternalServerError) + http.Error(w, "Token exchange failed", http.StatusBadGateway) return }
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
handlers.go
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go
📄 CodeRabbit inference engine (CLAUDE.md)
Never log raw OAuth tokens; only log SHA-256 hash of token formatted as fmt.Sprintf("%x", sha256.Sum256([]byte(token)))[:16]
Files:
handlers.go
🧠 Learnings (1)
📚 Learning: 2025-12-13T17:03:53.298Z
Learnt from: CR
Repo: tuannvm/oauth-mcp-proxy PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-13T17:03:53.298Z
Learning: Applies to **/*.go : Never log raw OAuth tokens; only log SHA-256 hash of token formatted as fmt.Sprintf("%x", sha256.Sum256([]byte(token)))[:16]
Applied to files:
handlers.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Build Verification
🔇 Additional comments (4)
handlers.go (4)
527-527: LGTM!Extracting
refresh_tokenfrom form values is appropriate for this grant type.
535-536: LGTM!Declaring
tokenanderroutside the switch block allows proper scoping for the response handling after the switch.
538-578: LGTM!The
authorization_codeflow is correctly refactored into the switch case, preserving the existing PKCE handling and redirect URI logic.
598-601: LGTM!Proper handling of unsupported grant types with appropriate logging and HTTP 400 response.
dcd76c3 to
7437fb2
Compare
|
@tuannvm There seems to be a CI issue blocking Cursor Code Review |
Signed-off-by: Christian Troelsen <christian.troelsen@tryg.dk>
7437fb2 to
54b0d20
Compare
|
thanks @WhammyLeaf |
Summary
Support refresh tokens so that an authenticated session can be extended by more than 1 hour (or whatever the expiration on your access token is)
Changes
handle_tokenmethod in thehandlers.gofile so thatrefresh_tokengrant is supported in addition toauthorization_codegrantTesting
Related Issues
#18
Summary by CodeRabbit
New Features
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.