go-sdk/oauthex
Repository files (latest commit first)
Filename Latest commit message Latest commit date
BorisTyshkevich 6a6ade920b
oauthex: add MatchesResource helper (RFC 9728/8707 audience comparison) (#970)
## Summary

- Add an exported \`oauthex.MatchesResource(claims []string, resource
string) bool\` helper that compares an \`aud\` claim slice against an
expected resource URL with the canonical-form (trailing slash) tolerance
required by RFC 9728 and RFC 8707.
- Tests cover the common shape combinations (canonical/trimmed in either
direction, surrounding whitespace, multiple claims) plus negative cases
ensuring scheme + path mismatches still fail.

## Motivation

RFC 9728 §3.3 canonicalises the protected-resource identifier with a
trailing slash, but RFC 8707 resource indicators frequently omit it.
Upstream IdPs vary in which form they emit in the \`aud\` claim (Google
trims, Auth0 retains, some clients round-trip whatever the IdP sent).
Strict byte equality therefore fails routinely on legitimate setups.

Resource servers writing this comparison by hand all converge on the
same trim-trailing-slash + whitespace logic; exporting a canonical
helper saves every consumer from re-deriving it.

## Test plan

- [x] \`go test ./oauthex/... -run MatchesResource\` passes.
- [x] Positive cases: exact match, trailing slash on either side,
surrounding whitespace, multi-claim slice with one match.
- [x] Negative cases: empty slice, no match, path mismatch, scheme
mismatch (HTTPS vs HTTP must still fail).

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Guglielmo Colombo <guglielmoc@google.com>
2026-06-16 15:20:09 +02:00
..
testdata oauthex: move internal/oauthex to oauthex (#559) 2025-10-07 08:39:49 -04:00
audience.go oauthex: add MatchesResource helper (RFC 9728/8707 audience comparison) (#970) 2026-06-16 15:20:09 +02:00
audience_test.go oauthex: add MatchesResource helper (RFC 9728/8707 audience comparison) (#970) 2026-06-16 15:20:09 +02:00
auth_meta.go mcp: add optional issuer validator for pre-registered client validation (SEP-2352) (#946) 2026-05-29 12:46:34 +00:00
auth_meta_test.go Compare auth server metadata issuer ignoring trailing slash (#955) 2026-05-14 07:26:57 +00:00
client.go mcp: add optional issuer validator for pre-registered client validation (SEP-2352) (#946) 2026-05-29 12:46:34 +00:00
client_test.go mcp: add optional issuer validator for pre-registered client validation (SEP-2352) (#946) 2026-05-29 12:46:34 +00:00
dcr.go feat: add automatic application_type inference (#904) 2026-04-27 13:02:01 +02:00
dcr_test.go oauthex: accept 200 in client registration (#877) 2026-04-01 16:51:18 +02:00
oauth2.go all: stabilize client OAuth support (#861) 2026-03-31 12:36:31 +02:00
oauthex.go all: client side OAuth support (#785) 2026-02-27 15:30:13 +01:00
oauthex_test.go all: stabilize client OAuth support (#861) 2026-03-31 12:36:31 +02:00
resource_meta.go all: stabilize client OAuth support (#861) 2026-03-31 12:36:31 +02:00
resource_meta_test.go all: stabilize client OAuth support (#861) 2026-03-31 12:36:31 +02:00
token_exchange.go all: stabilize client OAuth support (#861) 2026-03-31 12:36:31 +02:00
token_exchange_test.go all: stabilize client OAuth support (#861) 2026-03-31 12:36:31 +02:00
url_scheme_test.go all: stabilize client OAuth support (#861) 2026-03-31 12:36:31 +02:00