-
Notifications
You must be signed in to change notification settings - Fork 6
Feat/generic sdk #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3ae4232
chore(docs): Add initial implementation and refactoring plan
tuannvm bf15601
ci(oauth): add OAuth server with token validation and caching support
tuannvm ac44964
chore: update imports to use mark3labs for OAuth setup
tuannvm a41ba57
refactor(core): extract cache and context utilities for SDK-agnostic …
tuannvm dad9dc7
fix(advancd/main.go): Rename file
tuannvm cb5ae40
feat(oauth): add token validation and error handling in WrapHandler
tuannvm a114747
style: Add explanatory comments about PORT and SERVER_URL usage
tuannvm 5437063
chore(github workflow): update example build to find all main.go files
tuannvm 17e9c2c
refactor(advanced/main.go): Enhance TLS detection and Logging for ser…
tuannvm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package oauth | ||
|
|
||
| import ( | ||
| "sync" | ||
| "time" | ||
|
|
||
| "github.com/tuannvm/oauth-mcp-proxy/provider" | ||
| ) | ||
|
|
||
| // Re-export User from provider for backwards compatibility | ||
| type User = provider.User | ||
|
|
||
| // TokenCache stores validated tokens to avoid re-validation | ||
| type TokenCache struct { | ||
| mu sync.RWMutex | ||
| cache map[string]*CachedToken | ||
| } | ||
|
|
||
| // CachedToken represents a cached token validation result | ||
| type CachedToken struct { | ||
| User *User | ||
| ExpiresAt time.Time | ||
| } | ||
|
|
||
| // getCachedToken retrieves a cached token validation result | ||
| func (tc *TokenCache) getCachedToken(tokenHash string) (*CachedToken, bool) { | ||
| tc.mu.RLock() | ||
|
|
||
| cached, exists := tc.cache[tokenHash] | ||
| if !exists { | ||
| tc.mu.RUnlock() | ||
| return nil, false | ||
| } | ||
|
|
||
| if time.Now().After(cached.ExpiresAt) { | ||
| tc.mu.RUnlock() | ||
| go tc.deleteExpiredToken(tokenHash) | ||
| return nil, false | ||
| } | ||
|
|
||
| tc.mu.RUnlock() | ||
| return cached, true | ||
| } | ||
|
|
||
| // deleteExpiredToken safely deletes an expired token from the cache | ||
| func (tc *TokenCache) deleteExpiredToken(tokenHash string) { | ||
| tc.mu.Lock() | ||
| defer tc.mu.Unlock() | ||
|
|
||
| if cached, exists := tc.cache[tokenHash]; exists && time.Now().After(cached.ExpiresAt) { | ||
| delete(tc.cache, tokenHash) | ||
| } | ||
| } | ||
|
|
||
| // setCachedToken stores a token validation result | ||
| func (tc *TokenCache) setCachedToken(tokenHash string, user *User, expiresAt time.Time) { | ||
| tc.mu.Lock() | ||
| defer tc.mu.Unlock() | ||
|
|
||
| tc.cache[tokenHash] = &CachedToken{ | ||
| User: user, | ||
| ExpiresAt: expiresAt, | ||
| } | ||
| } | ||
|
Comment on lines
+55
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make TokenCache zero‑value safe (prevent map panic).
Apply this diff: func (tc *TokenCache) setCachedToken(tokenHash string, user *User, expiresAt time.Time) {
tc.mu.Lock()
defer tc.mu.Unlock()
+ if tc.cache == nil {
+ tc.cache = make(map[string]*CachedToken)
+ }
tc.cache[tokenHash] = &CachedToken{
User: user,
ExpiresAt: expiresAt,
}
}Optionally add: // NewTokenCache constructs a ready-to-use cache.
func NewTokenCache() *TokenCache { return &TokenCache{cache: make(map[string]*CachedToken)} }🤖 Prompt for AI Agents |
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix heading hierarchy: change h3 to h2.
Line 12 is an h3 heading (
###) but should be h2 (##) as a direct child of the "Quick Start" h2 section. Heading levels should increment by one level at a time per markdown linting rules.And similarly for the "Using Official SDK" section at line 138.
🧰 Tools
🪛 markdownlint-cli2 (0.18.1)
12-12: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3
(MD001, heading-increment)
🤖 Prompt for AI Agents