Commit dd2fd20
fix(plugin-auth): collapse the three basePath derivations onto one chain (#17002)
`AuthManager` derived its base path in three independent places —
`getBasePath()`, `getAuthIssuer()` and `getMcpResourceUrl()` — each reading
`this.config.basePath` and normalising it its own way. One of them built a
value that is not a URL.
`getMcpResourceUrl()` added no leading slash, so a `basePath` configured
without one produced `http://localhost:3000api/v1/mcp`. Measured: `new URL()`
throws on it (`3000api` is not a port), so `auth-plugin.ts`'s
`new URL(manager.getMcpResourceUrl()).pathname` — which mounts the RFC 9728
§3.1 path-inserted well-known route — throws too, and
`@better-auth/oauth-provider` 1.7.2 refuses it at plugin init:
oauth-provider: skipping resource seed for http://localhost:3000api/v1/mcp
— resource identifier ... must be an absolute URI (RFC 8707 §2)
Post-#16780 that identifier seeds the `sys_oauth_resource` row (`resources`)
and links every DCR client to it (`clientRegistrationDefaultResources`), with
`enforcePerClientResources` at its `true` default — so the row is never
written and every MCP client is refused. That input class could never mint or
match a token, which is why repairing it re-selects nothing.
There is now exactly ONE read of `this.config.basePath` in the file and one
chain above it:
configuredBasePath() the configured value VERBATIM — what better-auth is handed
└─ rootedBasePath() + a leading slash when absent (better-auth's own rule)
├─ getAuthIssuer() = origin + this
└─ getBasePath() = this, trailing slashes stripped
└─ getMcpResourceUrl() = origin + this minus `/auth` + `/mcp`
A fourth normaliser cannot be added without deleting a link of that chain.
⛔ `getAuthIssuer()` is NOT canonicalised, and the card's second defect is not
repaired here because it does not exist on `main`. The card and its triage
both read PR #16380 as having handed better-auth the STRIPPED base path while
`getAuthIssuer()` broadcast the RETAINED one. #16380's last commit ("hand
better-auth the configured basePath verbatim again") reverted exactly that,
having measured that it rejects every token minted under a trailing-slash
`basePath`. Measured here on a real `betterAuth()`, reading
`(await auth.$context).baseURL` — the value the oauth-provider stamps as `iss`
— `getAuthIssuer()` already equals it for all six spellings probed. A new
case pins that equality against the real instance, so the divergence cannot be
introduced by a later "canonicalisation".
`getAuthIssuer()` and `getBasePath()` are byte-identical to before for every
spelling. Only `getMcpResourceUrl()` moves, and only for a non-canonical
`basePath`. The canonical-input control asserts all three getters unchanged.
Refs #16399
Claude-Session: https://claude.ai/code/session_012zTkyNHJ7TkuN2oXtP5x37
Co-authored-by: Claude <noreply@anthropic.com>1 parent ee2cb6b commit dd2fd20
3 files changed
Lines changed: 272 additions & 38 deletions
File tree
- .changeset
- packages/plugins/plugin-auth/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
Lines changed: 160 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
177 | 178 | | |
178 | 179 | | |
179 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5599 | 5599 | | |
5600 | 5600 | | |
5601 | 5601 | | |
| 5602 | + | |
| 5603 | + | |
| 5604 | + | |
| 5605 | + | |
| 5606 | + | |
| 5607 | + | |
| 5608 | + | |
| 5609 | + | |
| 5610 | + | |
| 5611 | + | |
| 5612 | + | |
| 5613 | + | |
| 5614 | + | |
| 5615 | + | |
| 5616 | + | |
| 5617 | + | |
| 5618 | + | |
| 5619 | + | |
| 5620 | + | |
| 5621 | + | |
| 5622 | + | |
| 5623 | + | |
| 5624 | + | |
| 5625 | + | |
| 5626 | + | |
| 5627 | + | |
| 5628 | + | |
| 5629 | + | |
| 5630 | + | |
| 5631 | + | |
| 5632 | + | |
5602 | 5633 | | |
5603 | 5634 | | |
5604 | 5635 | | |
| |||
5638 | 5669 | | |
5639 | 5670 | | |
5640 | 5671 | | |
5641 | | - | |
5642 | | - | |
5643 | | - | |
5644 | | - | |
5645 | | - | |
5646 | | - | |
5647 | | - | |
5648 | | - | |
5649 | | - | |
5650 | | - | |
5651 | | - | |
5652 | | - | |
5653 | | - | |
5654 | | - | |
5655 | | - | |
5656 | | - | |
5657 | | - | |
5658 | | - | |
5659 | | - | |
5660 | | - | |
5661 | | - | |
5662 | | - | |
5663 | | - | |
5664 | | - | |
5665 | | - | |
5666 | | - | |
5667 | | - | |
| 5672 | + | |
| 5673 | + | |
| 5674 | + | |
| 5675 | + | |
| 5676 | + | |
| 5677 | + | |
| 5678 | + | |
| 5679 | + | |
| 5680 | + | |
| 5681 | + | |
| 5682 | + | |
| 5683 | + | |
| 5684 | + | |
| 5685 | + | |
| 5686 | + | |
| 5687 | + | |
5668 | 5688 | | |
5669 | 5689 | | |
5670 | 5690 | | |
| |||
5688 | 5708 | | |
5689 | 5709 | | |
5690 | 5710 | | |
5691 | | - | |
5692 | | - | |
| 5711 | + | |
5693 | 5712 | | |
5694 | 5713 | | |
5695 | 5714 | | |
| |||
6018 | 6037 | | |
6019 | 6038 | | |
6020 | 6039 | | |
| 6040 | + | |
| 6041 | + | |
| 6042 | + | |
| 6043 | + | |
| 6044 | + | |
| 6045 | + | |
| 6046 | + | |
| 6047 | + | |
| 6048 | + | |
6021 | 6049 | | |
6022 | 6050 | | |
6023 | | - | |
6024 | | - | |
| 6051 | + | |
6025 | 6052 | | |
6026 | 6053 | | |
6027 | 6054 | | |
6028 | 6055 | | |
6029 | 6056 | | |
6030 | 6057 | | |
| 6058 | + | |
| 6059 | + | |
| 6060 | + | |
| 6061 | + | |
| 6062 | + | |
| 6063 | + | |
| 6064 | + | |
| 6065 | + | |
| 6066 | + | |
| 6067 | + | |
| 6068 | + | |
| 6069 | + | |
| 6070 | + | |
| 6071 | + | |
| 6072 | + | |
| 6073 | + | |
| 6074 | + | |
| 6075 | + | |
| 6076 | + | |
| 6077 | + | |
6031 | 6078 | | |
6032 | 6079 | | |
6033 | | - | |
6034 | | - | |
| 6080 | + | |
6035 | 6081 | | |
6036 | 6082 | | |
6037 | 6083 | | |
| |||
0 commit comments