Skip to content

Commit aa7dbfb

Browse files
committed
refactor(provider): initialize logger and audience in OAuthValidator
Signed-off-by: Tommy Nguyen <tuannvm@hotmail.com>
1 parent 250922d commit aa7dbfb

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

CLAUDE.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ make vuln
5353

5454
### Integration Flow
5555

56-
```
56+
```text
5757
1. HTTP request with "Authorization: Bearer <token>" header
5858
2. CreateHTTPContextFunc() extracts token → adds to context via WithOAuthToken()
5959
3. OAuth middleware (Server.Middleware()) validates token:
@@ -83,10 +83,12 @@ The codebase has extensive test coverage across multiple scenarios:
8383
- **provider/provider_test.go** - Token validator tests
8484

8585
Run single test:
86+
8687
```bash
8788
go test -v -run TestName ./...
8889
```
8990

91+
9092
## Important Notes
9193

9294
1. **User Context**: Always use `GetUserFromContext(ctx)` in tool handlers to access authenticated user

provider/provider.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ func (v *OIDCValidator) Initialize(cfg *Config) error {
166166
return fmt.Errorf("OIDC audience is required for OIDC provider")
167167
}
168168

169+
v.logger = cfg.Logger
170+
if v.logger == nil {
171+
v.logger = &noOpLogger{}
172+
}
173+
v.audience = cfg.Audience
174+
169175
// Use standard library context with timeout
170176
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
171177
defer cancel()
@@ -207,7 +213,6 @@ func (v *OIDCValidator) Initialize(cfg *Config) error {
207213

208214
v.provider = provider
209215
v.verifier = verifier
210-
v.audience = cfg.Audience
211216
return nil
212217
}
213218

@@ -331,3 +336,11 @@ func getStringClaim(claims jwt.MapClaims, key string) string {
331336
}
332337
return ""
333338
}
339+
340+
// noOpLogger is a no-op logger used when cfg.Logger is nil
341+
type noOpLogger struct{}
342+
343+
func (l *noOpLogger) Debug(msg string, args ...interface{}) {}
344+
func (l *noOpLogger) Info(msg string, args ...interface{}) {}
345+
func (l *noOpLogger) Warn(msg string, args ...interface{}) {}
346+
func (l *noOpLogger) Error(msg string, args ...interface{}) {}

0 commit comments

Comments
 (0)