Commit 92aa8c4
Return 401 for expired OAuth access tokens (#768)
## Summary
- Expired OAuth access tokens were causing the API to return **403** on
writes (e.g. `POST /v1/tracks?user_id=…`) because the bearer token
failed to resolve to a wallet and the downstream authorization check ran
with an empty wallet.
- 403 implies the caller is authenticated but unauthorized, which keeps
clients from realizing they need to refresh their token. Now we return
**401 "Invalid or expired access token"** whenever a Bearer token was
supplied but no auth path resolved it (and the route asserts an identity
via `?user_id=` or `:wallet`).
- Anonymous/unauthenticated requests are unchanged. Endpoints with no
identity assertion still pass through silently if a stale bearer is
sent.
## Test plan
- [x] `go test ./api/ -run
"TestAuthMiddlewareInvalidBearerReturns401|TestAuthorized|TestRequireAuthMiddleware|TestRequireWriteScope|TestGetApiSigner"`
passes
- [x] New `TestAuthMiddlewareInvalidBearerReturns401` covers the three
cases: invalid bearer + `myId` → 401, invalid bearer + `:wallet` → 401,
invalid bearer with no identity assertion → pass-through
- [ ] Manually verify a real expired OAuth token against `POST
/v1/tracks` returns 401
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>1 parent c5647da commit 92aa8c4
2 files changed
+70
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
258 | 269 | | |
259 | 270 | | |
260 | 271 | | |
261 | 272 | | |
262 | 273 | | |
263 | 274 | | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
264 | 280 | | |
265 | 281 | | |
266 | 282 | | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | 283 | | |
274 | 284 | | |
275 | 285 | | |
276 | 286 | | |
| 287 | + | |
277 | 288 | | |
278 | 289 | | |
279 | 290 | | |
| |||
288 | 299 | | |
289 | 300 | | |
290 | 301 | | |
| 302 | + | |
291 | 303 | | |
292 | 304 | | |
293 | 305 | | |
| |||
324 | 336 | | |
325 | 337 | | |
326 | 338 | | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
327 | 350 | | |
328 | 351 | | |
329 | 352 | | |
| |||
337 | 360 | | |
338 | 361 | | |
339 | 362 | | |
340 | | - | |
341 | 363 | | |
342 | 364 | | |
343 | 365 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
131 | 172 | | |
132 | 173 | | |
133 | 174 | | |
| |||
0 commit comments