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
Copy file name to clipboardExpand all lines: CLAUDE.md
+102-6Lines changed: 102 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -134,15 +134,76 @@ Run single test:
134
134
go test -v -run TestName ./...
135
135
```
136
136
137
+
### Test Patterns
138
+
139
+
Tests use **table-driven subtests** with `t.Run()`:
140
+
141
+
```go
142
+
tests:= []struct {
143
+
name string
144
+
// test fields
145
+
}{...}
146
+
for_, tt:=range tests {
147
+
t.Run(tt.name, func(t *testing.T) {
148
+
// test body
149
+
})
150
+
}
151
+
```
152
+
153
+
Mock validators implement `TokenValidator` interface. Use `httptest.NewRecorder()` for HTTP handler tests.
154
+
155
+
## Configuration
156
+
157
+
### ConfigBuilder Pattern (Recommended)
158
+
159
+
Use `ConfigBuilder` for production code instead of direct `Config` structs:
160
+
161
+
```go
162
+
cfg, _:= oauth.NewConfigBuilder().
163
+
WithProvider("okta").
164
+
WithIssuer("https://company.okta.com").
165
+
WithAudience("api://my-server").
166
+
WithHost(host).WithPort(port).
167
+
Build()
168
+
```
169
+
170
+
`Build()` validates config and auto-constructs `ServerURL` if not set.
171
+
172
+
### Context Timeouts
173
+
174
+
-**OIDC validation**: 10 seconds
175
+
-**Provider initialization**: 30 seconds
176
+
177
+
## Security Requirements
178
+
179
+
1.**Redirect URI validation**: All URIs must be in explicit allowlist
180
+
2.**State parameter HMAC**: OAuth states are HMAC-signed to prevent CSRF
181
+
3.**Audience validation**: Both HMAC and OIDC validators explicitly check `aud` claim
182
+
4.**No raw token logging**: Only log `fmt.Sprintf("%x", sha256.Sum256([]byte(token)))[:16]`
183
+
5.**TLS in production**: Always warn if `useTLS=false` in `LogStartup()`
137
184
138
185
## Important Notes
139
186
140
187
1.**User Context**: Always use `GetUserFromContext(ctx)` in tool handlers to access authenticated user
141
-
2.**Token Caching**: Tokens cached for 5 minutes - design for this TTL in testing
188
+
2.**Token Caching**: Tokens cached for 5 minutes - design for this TTL in testing. Cache uses `sync.RWMutex` with background cleanup via `deleteExpiredToken()` goroutine
142
189
3.**Logging**: Config.Logger is optional. If nil, uses default logger (log.Printf with level prefixes)
**Note**: `WrapMCPEndpoint()` provides automatic 401 handling with proper WWW-Authenticate headers when Bearer token is missing. It also passes through OPTIONS requests (CORS) and non-Bearer auth schemes.
0 commit comments