Skip to content

Commit 76874cd

Browse files
DavidS-ovmactions-user
authored andcommitted
fix(deps): update module github.com/auth0/go-jwt-middleware/v2 to v3 (#4145)
📹 https://www.loom.com/share/4049912c73734143a8dde39ebf3f4fe6 📹 This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [github.com/auth0/go-jwt-middleware/v2](https://redirect.github.com/auth0/go-jwt-middleware) | `v2.3.1` → `v3.0.0` | ![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fauth0%2fgo-jwt-middleware%2fv2/v3.0.0?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fauth0%2fgo-jwt-middleware%2fv2/v2.3.1/v3.0.0?slim=true) | --- > [!WARNING] > Some dependencies could not be looked up. Check the [Dependency Dashboard](../issues/370) for more information. --- ### Release Notes <details> <summary>auth0/go-jwt-middleware (github.com/auth0/go-jwt-middleware/v2)</summary> ### [`v3.0.0`](https://redirect.github.com/auth0/go-jwt-middleware/blob/HEAD/CHANGELOG.md#v300-2026-01-19) [Compare Source](https://redirect.github.com/auth0/go-jwt-middleware/compare/v2.3.1...v3.0.0) [Full Changelog](https://redirect.github.com/auth0/go-jwt-middleware/compare/v2.3.1...v3.0.0) **BEFORE YOU UPGRADE** - This is a major release that includes breaking changes. Please see [MIGRATION\_GUIDE.md](MIGRATION_GUIDE.md) before upgrading. This release will require changes to your application. ##### Added - Pure options pattern for validator, middleware, and JWKS provider ([#&#8203;357](https://redirect.github.com/auth0/go-jwt-middleware/pull/357), [#&#8203;358](https://redirect.github.com/auth0/go-jwt-middleware/pull/358), [#&#8203;360](https://redirect.github.com/auth0/go-jwt-middleware/pull/360)) - DPoP (Demonstrating Proof-of-Possession) support per RFC 9449 ([#&#8203;363](https://redirect.github.com/auth0/go-jwt-middleware/pull/363)) - Framework-agnostic core package for reusable validation logic ([#&#8203;356](https://redirect.github.com/auth0/go-jwt-middleware/pull/356)) - Type-safe claims retrieval with generics (`GetClaims[T]()`, `MustGetClaims[T]()`, `HasClaims()`) - Structured logging support compatible with `log/slog` - Support for 14 signature algorithms (HS256/384/512, RS256/384/512, PS256/384/512, ES256/384/512, ES256K, EdDSA) - Enhanced error responses with RFC 6750 compliance - Trusted proxy configuration for DPoP behind reverse proxies - Multiple issuer and audience support with new APIs - Documentation and linting configuration ([#&#8203;361](https://redirect.github.com/auth0/go-jwt-middleware/pull/361)) ##### Changed - Migrated from square/go-jose to lestrrat-go/jwx v3 ([#&#8203;358](https://redirect.github.com/auth0/go-jwt-middleware/pull/358)) - Module path updated to `github.com/auth0/go-jwt-middleware/v3` ([#&#8203;355](https://redirect.github.com/auth0/go-jwt-middleware/pull/355)) - Minimum Go version updated to 1.24 ([#&#8203;355](https://redirect.github.com/auth0/go-jwt-middleware/pull/355)) - Update examples for v3 module path and new APIs ##### Breaking - Pure options pattern: All constructors (`New()`) now require functional options instead of positional parameters - Context key: `ContextKey{}` is no longer exported - use `GetClaims[T]()` helper function - Custom claims now use generics for type safety - `TokenExtractor` returns `ExtractedToken` (with scheme) instead of `string` - Type naming: `ExclusionUrlHandler` renamed to `ExclusionURLHandler` ##### Migration Example **v2:** ```go // Validator with positional parameters jwtValidator, err := validator.New( keyFunc, validator.RS256, "https://issuer.example.com/", []string{"my-api"}, ) // Middleware middleware := jwtmiddleware.New(jwtValidator.ValidateToken) // Claims access via context key claims := r.Context().Value(jwtmiddleware.ContextKey{}).(*validator.ValidatedClaims) ``` **v3:** ```go // Validator with pure options jwtValidator, err := validator.New( validator.WithKeyFunc(keyFunc), validator.WithAlgorithm(validator.RS256), validator.WithIssuer("https://issuer.example.com/"), validator.WithAudience("my-api"), ) // Middleware with options middleware, err := jwtmiddleware.New( jwtmiddleware.WithValidator(jwtValidator), ) // Type-safe claims with generics claims, err := jwtmiddleware.GetClaims[*validator.ValidatedClaims](r.Context()) ``` See [MIGRATION\_GUIDE.md](MIGRATION_GUIDE.md) for complete migration instructions. *** </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 10am on friday" in timezone Europe/London, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/overmindtech/workspace). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My41NS40IiwidXBkYXRlZEluVmVyIjoiNDMuNTYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIiwiZ29sYW5nIl19--> <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **High Risk** > Upgrades a major authentication dependency and rewrites JWT validation/claim extraction paths, so mistakes could break auth enforcement or token parsing across the API server. > > **Overview** > Migrates the codebase from `github.com/auth0/go-jwt-middleware/v2` to `v3`, updating JWKS provider/validator/middleware construction to the new options-based APIs and adjusting token extraction/claims retrieval. > > Because `v3` no longer exposes `ContextKey{}`, the auth middleware now stores `*validator.ValidatedClaims` under a new `auth.ValidatedClaimsContextKey{}` and updates downstream callers (e.g. token expiry in `ManagementServiceHandler.CreateToken`) accordingly. The API server init path now skips validator setup when `AllowUnauthenticated` is enabled and tightens startup validation/error logging for missing Auth0 config; related tests set `AllowUnauthenticated: true` to accommodate `v3` rejecting empty audience/domain values. > > Also updates `go.mod`/`go.sum` for new transitive deps pulled in by `v3` (e.g. `lestrrat-go/jwx/v3`) and adds `github.com/resend/resend-go/v3` to the main require block. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit e8a54151abc72beb9973302047684ad983aa5b8e. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> GitOrigin-RevId: f8185846b5c05bebfd88c56b76c4d1bb95a592db
1 parent 096a0a5 commit 76874cd

4 files changed

Lines changed: 85 additions & 46 deletions

File tree

go.mod

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ require (
6666
github.com/anthropics/anthropic-sdk-go v0.2.0-alpha.4
6767
github.com/antihax/optional v1.0.0
6868
github.com/auth0/go-auth0/v2 v2.6.0
69-
github.com/auth0/go-jwt-middleware/v2 v2.3.1
69+
github.com/auth0/go-jwt-middleware/v3 v3.0.0
7070
github.com/aws/aws-sdk-go-v2 v1.41.3
7171
github.com/aws/aws-sdk-go-v2/config v1.32.11
7272
github.com/aws/aws-sdk-go-v2/credentials v1.19.11
@@ -150,6 +150,7 @@ require (
150150
github.com/posthog/posthog-go v1.10.0
151151
github.com/projectdiscovery/subfinder/v2 v2.12.0
152152
github.com/qhenkart/anthropic-tokenizer-go v0.0.0-20231011194518-5519949e0faf
153+
github.com/resend/resend-go/v3 v3.1.1
153154
github.com/riverqueue/river v0.31.0
154155
github.com/riverqueue/river/riverdriver/riverpgxv5 v0.31.0
155156
github.com/riverqueue/river/rivertype v0.31.0
@@ -367,12 +368,17 @@ require (
367368
github.com/klauspost/pgzip v1.2.6 // indirect
368369
github.com/kylelemons/godebug v1.1.0 // indirect
369370
github.com/leodido/go-urn v1.4.0 // indirect
370-
github.com/lestrrat-go/blackmagic v1.0.3 // indirect
371+
github.com/lestrrat-go/blackmagic v1.0.4 // indirect
372+
github.com/lestrrat-go/dsig v1.0.0 // indirect
373+
github.com/lestrrat-go/dsig-secp256k1 v1.0.0 // indirect
371374
github.com/lestrrat-go/httpcc v1.0.1 // indirect
372375
github.com/lestrrat-go/httprc v1.0.6 // indirect
376+
github.com/lestrrat-go/httprc/v3 v3.0.3 // indirect
373377
github.com/lestrrat-go/iter v1.0.2 // indirect
374378
github.com/lestrrat-go/jwx/v2 v2.1.6 // indirect
379+
github.com/lestrrat-go/jwx/v3 v3.0.12 // indirect
375380
github.com/lestrrat-go/option v1.0.1 // indirect
381+
github.com/lestrrat-go/option/v2 v2.0.0 // indirect
376382
github.com/lib/pq v1.10.9 // indirect
377383
github.com/lithammer/fuzzysearch v1.1.8
378384
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
@@ -437,7 +443,7 @@ require (
437443
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect
438444
github.com/samber/lo v1.52.0 // indirect
439445
github.com/samber/slog-common v0.20.0 // indirect
440-
github.com/segmentio/asm v1.2.0 // indirect
446+
github.com/segmentio/asm v1.2.1 // indirect
441447
github.com/segmentio/encoding v0.5.3 // indirect
442448
github.com/shirou/gopsutil/v3 v3.23.7 // indirect
443449
github.com/shoenig/go-m1cpu v0.1.6 // indirect
@@ -466,6 +472,7 @@ require (
466472
github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80 // indirect
467473
github.com/ulikunitz/xz v0.5.15 // indirect
468474
github.com/uptrace/opentelemetry-go-extra/otelutil v0.3.2 // indirect
475+
github.com/valyala/fastjson v1.6.7 // indirect
469476
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
470477
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
471478
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
@@ -511,7 +518,6 @@ require (
511518
google.golang.org/genproto/googleapis/api v0.0.0-20260209200024-4cfbd4190f57 // indirect
512519
gopkg.in/djherbis/times.v1 v1.3.0 // indirect
513520
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
514-
gopkg.in/go-jose/go-jose.v2 v2.6.3 // indirect
515521
gopkg.in/inf.v0 v0.9.1 // indirect
516522
k8s.io/apiextensions-apiserver v0.35.0 // indirect
517523
k8s.io/apiserver v0.35.0 // indirect
@@ -527,5 +533,3 @@ require (
527533
sigs.k8s.io/structured-merge-diff/v6 v6.3.2
528534
sigs.k8s.io/yaml v1.6.0 // indirect
529535
)
530-
531-
require github.com/resend/resend-go/v3 v3.1.1

go.sum

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:W
234234
github.com/atomicgo/cursor v0.0.1/go.mod h1:cBON2QmmrysudxNBFthvMtN32r3jxVRIvzkUiF/RuIk=
235235
github.com/auth0/go-auth0/v2 v2.6.0 h1:KCoLxTcH8qXPYbwKZxxFrL/6P+P+Zc58BQPL6w0Kt30=
236236
github.com/auth0/go-auth0/v2 v2.6.0/go.mod h1:XVRck9fw1EIw1z4guYcbKFGmElnexb+xOvQ/0U1hHd0=
237-
github.com/auth0/go-jwt-middleware/v2 v2.3.1 h1:lbDyWE9aLydb3zrank+Gufb9qGJN9u//7EbJK07pRrw=
238-
github.com/auth0/go-jwt-middleware/v2 v2.3.1/go.mod h1:mqVr0gdB5zuaFyQFWMJH/c/2hehNjbYUD4i8Dpyf+Hc=
237+
github.com/auth0/go-jwt-middleware/v3 v3.0.0 h1:+rvUPCT+VbAuK4tpS13fWfZrMyqTwLopt3VoY0Y7kvA=
238+
github.com/auth0/go-jwt-middleware/v3 v3.0.0/go.mod h1:iU42jqjRyeKbf9YYSnRnolr836gk6Ty/jnUNuVq2b0o=
239239
github.com/aws/aws-sdk-go-v2 v1.41.3 h1:4kQ/fa22KjDt13QCy1+bYADvdgcxpfH18f0zP542kZA=
240240
github.com/aws/aws-sdk-go-v2 v1.41.3/go.mod h1:mwsPRE8ceUUpiTgF7QmQIJ7lgsKUPQOUl3o72QBrE1o=
241241
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.6 h1:N4lRUXZpZ1KVEUn6hxtco/1d2lgYhNn1fHkkl8WhlyQ=
@@ -770,18 +770,28 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
770770
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
771771
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
772772
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
773-
github.com/lestrrat-go/blackmagic v1.0.3 h1:94HXkVLxkZO9vJI/w2u1T0DAoprShFd13xtnSINtDWs=
774-
github.com/lestrrat-go/blackmagic v1.0.3/go.mod h1:6AWFyKNNj0zEXQYfTMPfZrAXUWUfTIZ5ECEUEJaijtw=
773+
github.com/lestrrat-go/blackmagic v1.0.4 h1:IwQibdnf8l2KoO+qC3uT4OaTWsW7tuRQXy9TRN9QanA=
774+
github.com/lestrrat-go/blackmagic v1.0.4/go.mod h1:6AWFyKNNj0zEXQYfTMPfZrAXUWUfTIZ5ECEUEJaijtw=
775+
github.com/lestrrat-go/dsig v1.0.0 h1:OE09s2r9Z81kxzJYRn07TFM9XA4akrUdoMwr0L8xj38=
776+
github.com/lestrrat-go/dsig v1.0.0/go.mod h1:dEgoOYYEJvW6XGbLasr8TFcAxoWrKlbQvmJgCR0qkDo=
777+
github.com/lestrrat-go/dsig-secp256k1 v1.0.0 h1:JpDe4Aybfl0soBvoVwjqDbp+9S1Y2OM7gcrVVMFPOzY=
778+
github.com/lestrrat-go/dsig-secp256k1 v1.0.0/go.mod h1:CxUgAhssb8FToqbL8NjSPoGQlnO4w3LG1P0qPWQm/NU=
775779
github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE=
776780
github.com/lestrrat-go/httpcc v1.0.1/go.mod h1:qiltp3Mt56+55GPVCbTdM9MlqhvzyuL6W/NMDA8vA5E=
777781
github.com/lestrrat-go/httprc v1.0.6 h1:qgmgIRhpvBqexMJjA/PmwSvhNk679oqD1RbovdCGW8k=
778782
github.com/lestrrat-go/httprc v1.0.6/go.mod h1:mwwz3JMTPBjHUkkDv/IGJ39aALInZLrhBp0X7KGUZlo=
783+
github.com/lestrrat-go/httprc/v3 v3.0.3 h1:WjLHWkDkgWXeIUrKi/7lS/sGq2DjkSAwdTbH5RHXAKs=
784+
github.com/lestrrat-go/httprc/v3 v3.0.3/go.mod h1:mSMtkZW92Z98M5YoNNztbRGxbXHql7tSitCvaxvo9l0=
779785
github.com/lestrrat-go/iter v1.0.2 h1:gMXo1q4c2pHmC3dn8LzRhJfP1ceCbgSiT9lUydIzltI=
780786
github.com/lestrrat-go/iter v1.0.2/go.mod h1:Momfcq3AnRlRjI5b5O8/G5/BvpzrhoFTZcn06fEOPt4=
781787
github.com/lestrrat-go/jwx/v2 v2.1.6 h1:hxM1gfDILk/l5ylers6BX/Eq1m/pnxe9NBwW6lVfecA=
782788
github.com/lestrrat-go/jwx/v2 v2.1.6/go.mod h1:Y722kU5r/8mV7fYDifjug0r8FK8mZdw0K0GpJw/l8pU=
789+
github.com/lestrrat-go/jwx/v3 v3.0.12 h1:p25r68Y4KrbBdYjIsQweYxq794CtGCzcrc5dGzJIRjg=
790+
github.com/lestrrat-go/jwx/v3 v3.0.12/go.mod h1:HiUSaNmMLXgZ08OmGBaPVvoZQgJVOQphSrGr5zMamS8=
783791
github.com/lestrrat-go/option v1.0.1 h1:oAzP2fvZGQKWkvHa1/SAcFolBEca1oN+mQ7eooNBEYU=
784792
github.com/lestrrat-go/option v1.0.1/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I=
793+
github.com/lestrrat-go/option/v2 v2.0.0 h1:XxrcaJESE1fokHy3FpaQ/cXW8ZsIdWcdFzzLOcID3Ss=
794+
github.com/lestrrat-go/option/v2 v2.0.0/go.mod h1:oSySsmzMoR0iRzCDCaUfsCzxQHUEuhOViQObyy7S6Vg=
785795
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
786796
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
787797
github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4=
@@ -1026,8 +1036,8 @@ github.com/samber/slog-logrus/v2 v2.5.3 h1:N6YGgQ9CQjUQXe75/iWKtE55EENjG67HYUsJQ
10261036
github.com/samber/slog-logrus/v2 v2.5.3/go.mod h1:W3njRsspuMRCd33S0ibPyK1ohRaMhuXKZ1BK8pNiM+c=
10271037
github.com/sashabaranov/go-openai v1.41.2 h1:vfPRBZNMpnqu8ELsclWcAvF19lDNgh1t6TVfFFOPiSM=
10281038
github.com/sashabaranov/go-openai v1.41.2/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
1029-
github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys=
1030-
github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
1039+
github.com/segmentio/asm v1.2.1 h1:DTNbBqs57ioxAD4PrArqftgypG4/qNpXoJx8TVXxPR0=
1040+
github.com/segmentio/asm v1.2.1/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
10311041
github.com/segmentio/encoding v0.5.3 h1:OjMgICtcSFuNvQCdwqMCv9Tg7lEOXGwm1J5RPQccx6w=
10321042
github.com/segmentio/encoding v0.5.3/go.mod h1:HS1ZKa3kSN32ZHVZ7ZLPLXWvOVIiZtyJnO1gPH1sKt0=
10331043
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
@@ -1146,6 +1156,8 @@ github.com/uptrace/opentelemetry-go-extra/otellogrus v0.3.2 h1:H8wwQwTe5sL6x30z7
11461156
github.com/uptrace/opentelemetry-go-extra/otellogrus v0.3.2/go.mod h1:/kR4beFhlz2g+V5ik8jW+3PMiMQAPt29y6K64NNY53c=
11471157
github.com/uptrace/opentelemetry-go-extra/otelutil v0.3.2 h1:3/aHKUq7qaFMWxyQV0W2ryNgg8x8rVeKVA20KJUkfS0=
11481158
github.com/uptrace/opentelemetry-go-extra/otelutil v0.3.2/go.mod h1:Zit4b8AQXaXvA68+nzmbyDzqiyFRISyw1JiD5JqUBjw=
1159+
github.com/valyala/fastjson v1.6.7 h1:ZE4tRy0CIkh+qDc5McjatheGX2czdn8slQjomexVpBM=
1160+
github.com/valyala/fastjson v1.6.7/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
11491161
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
11501162
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
11511163
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
@@ -1544,8 +1556,6 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
15441556
gopkg.in/evanphx/json-patch.v4 v4.13.0 h1:czT3CmqEaQ1aanPc5SdlgQrrEIb8w/wwCvWWnfEbYzo=
15451557
gopkg.in/evanphx/json-patch.v4 v4.13.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M=
15461558
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
1547-
gopkg.in/go-jose/go-jose.v2 v2.6.3 h1:nt80fvSDlhKWQgSWyHyy5CfmlQr+asih51R8PTWNKKs=
1548-
gopkg.in/go-jose/go-jose.v2 v2.6.3/go.mod h1:zzZDPkNNw/c9IE7Z9jr11mBZQhKQTMzoEEIoEdZlFBI=
15491559
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
15501560
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
15511561
gopkg.in/ini.v1 v1.67.1 h1:tVBILHy0R6e4wkYOn3XmiITt/hEVH4TFMYvAX2Ytz6k=

go/auth/middleware.go

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
"strings"
1212
"time"
1313

14-
jwtmiddleware "github.com/auth0/go-jwt-middleware/v2"
15-
"github.com/auth0/go-jwt-middleware/v2/jwks"
16-
"github.com/auth0/go-jwt-middleware/v2/validator"
14+
jwtmiddleware "github.com/auth0/go-jwt-middleware/v3"
15+
"github.com/auth0/go-jwt-middleware/v3/jwks"
16+
"github.com/auth0/go-jwt-middleware/v3/validator"
1717
"github.com/getsentry/sentry-go"
1818
log "github.com/sirupsen/logrus"
1919
"go.opentelemetry.io/otel/attribute"
@@ -42,6 +42,11 @@ type UserTokenContextKey struct{}
4242
// This will be the auth0 `user_id` from the tokens `sub` claim.
4343
type CurrentSubjectContextKey struct{}
4444

45+
// ValidatedClaimsContextKey stores the full *validator.ValidatedClaims in
46+
// context. In v3 the middleware's context key is unexported, so we use our own
47+
// for code that needs the full validated claims (e.g. token expiry lookup).
48+
type ValidatedClaimsContextKey struct{}
49+
4550
// MiddlewareConfig Configuration for the auth middleware
4651
type MiddlewareConfig struct {
4752
Auth0Domain string
@@ -214,7 +219,7 @@ func WithAccount(account string) OverrideAuthOptionFunc {
214219
}
215220

216221
// Sets the auth info in the context directly from the validated claims produced
217-
// by the `github.com/auth0/go-jwt-middleware/v2/validator` package. This is
222+
// by the `github.com/auth0/go-jwt-middleware/v3/validator` package. This is
218223
// essentially what the middleware already does when receiving a request, and
219224
// therefore should only be used in exceptional circumstances, like testing, when the
220225
// middleware is not being used.
@@ -224,7 +229,7 @@ func WithAccount(account string) OverrideAuthOptionFunc {
224229
func WithValidatedClaims(claims *validator.ValidatedClaims) OverrideAuthOptionFunc {
225230
return func(ctx context.Context) context.Context {
226231
customClaims := claims.CustomClaims.(*CustomClaims)
227-
ctx = context.WithValue(ctx, jwtmiddleware.ContextKey{}, claims)
232+
ctx = context.WithValue(ctx, ValidatedClaimsContextKey{}, claims)
228233
ctx = context.WithValue(ctx, CustomClaimsContextKey{}, customClaims)
229234
ctx = context.WithValue(ctx, CurrentSubjectContextKey{}, claims.RegisteredClaims.Subject)
230235
ctx = context.WithValue(ctx, AccountNameContextKey{}, customClaims.AccountName)
@@ -282,9 +287,23 @@ func withCustomClaims(modify func(*CustomClaims)) OverrideAuthOptionFunc {
282287
//
283288
// This middleware also extract custom claims form the token and stores them in
284289
// CustomClaimsContextKey
290+
//
291+
// NOTE: This function uses log.Fatalf for startup-time configuration errors
292+
// because its signature returns http.Handler, not (http.Handler, error).
293+
// Propagating errors would require changing every caller of NewAuthMiddleware.
285294
func ensureValidTokenHandler(config MiddlewareConfig, next http.Handler) http.Handler {
286-
if config.Auth0Domain == "" && config.IssuerURL == "" && config.Auth0Audience == "" {
287-
log.Fatalf("Auth0 configuration is missing")
295+
if config.BypassAuth {
296+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
297+
span := trace.SpanFromContext(r.Context())
298+
span.SetAttributes(attribute.Bool("ovm.auth.bypass", true))
299+
ctx := OverrideAuth(r.Context(), WithBypassScopeCheck())
300+
next.ServeHTTP(w, r.Clone(ctx))
301+
})
302+
}
303+
304+
if config.Auth0Audience == "" || (config.Auth0Domain == "" && config.IssuerURL == "") {
305+
log.Fatalf("Auth0 configuration is incomplete: audience=%q, domain=%q, issuerURL=%q",
306+
config.Auth0Audience, config.Auth0Domain, config.IssuerURL)
288307
}
289308

290309
var issuerURL *url.URL
@@ -299,22 +318,26 @@ func ensureValidTokenHandler(config MiddlewareConfig, next http.Handler) http.Ha
299318
log.Fatalf("Failed to parse the issuer url: %v", err)
300319
}
301320

302-
provider := jwks.NewCachingProvider(issuerURL, 5*time.Minute)
321+
provider, err := jwks.NewCachingProvider(
322+
jwks.WithIssuerURL(issuerURL),
323+
jwks.WithCacheTTL(5*time.Minute),
324+
)
325+
if err != nil {
326+
log.Fatalf("Failed to set up the jwks provider: %v", err)
327+
}
303328

304329
jwtValidator, err := validator.New(
305-
provider.KeyFunc,
306-
validator.RS256,
307-
issuerURL.String(),
308-
[]string{config.Auth0Audience},
309-
validator.WithCustomClaims(
310-
func() validator.CustomClaims {
311-
return &CustomClaims{}
312-
},
313-
),
330+
validator.WithKeyFunc(provider.KeyFunc),
331+
validator.WithAlgorithm(validator.RS256),
332+
validator.WithIssuer(issuerURL.String()),
333+
validator.WithAudience(config.Auth0Audience),
334+
validator.WithCustomClaims(func() *CustomClaims {
335+
return &CustomClaims{}
336+
}),
314337
validator.WithAllowedClockSkew(time.Minute),
315338
)
316339
if err != nil {
317-
log.Fatalf("Failed to set up the jwt validator")
340+
log.Fatalf("Failed to set up the jwt validator: %v", err)
318341
}
319342

320343
errorHandler := func(w http.ResponseWriter, r *http.Request, err error) {
@@ -382,17 +405,24 @@ func ensureValidTokenHandler(config MiddlewareConfig, next http.Handler) http.Ha
382405

383406
tokenExtractor := jwtmiddleware.MultiTokenExtractor(extractors...)
384407

385-
middleware := jwtmiddleware.New(
386-
jwtValidator.ValidateToken,
408+
middleware, err := jwtmiddleware.New(
409+
jwtmiddleware.WithValidator(jwtValidator),
387410
jwtmiddleware.WithErrorHandler(errorHandler),
388411
jwtmiddleware.WithTokenExtractor(tokenExtractor),
389412
)
413+
if err != nil {
414+
log.Fatalf("Failed to set up the jwt middleware: %v", err)
415+
}
390416

391417
jwtValidationMiddleware := middleware.CheckJWT(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
392418
// extract account name and setup otel attributes after the JWT was validated, but before the actual handler runs
393-
claims := r.Context().Value(jwtmiddleware.ContextKey{}).(*validator.ValidatedClaims)
419+
claims, err := jwtmiddleware.GetClaims[*validator.ValidatedClaims](r.Context())
420+
if err != nil {
421+
errorHandler(w, r, fmt.Errorf("error getting validated claims: %w", err))
422+
return
423+
}
394424

395-
token, err := tokenExtractor(r)
425+
extractedToken, err := tokenExtractor(r)
396426
// we should never hit this as the middleware wouldn't call the handler
397427
if err != nil {
398428
// This is not ErrJWTMissing because an error here means that the
@@ -412,7 +442,8 @@ func ensureValidTokenHandler(config MiddlewareConfig, next http.Handler) http.Ha
412442
// note that the values are looked up in last-in-first-out order, so
413443
// there is an absolutely minor perf optimisation to have the context
414444
// values set in ascending order of access frequency.
415-
ctx = context.WithValue(ctx, UserTokenContextKey{}, token)
445+
ctx = context.WithValue(ctx, UserTokenContextKey{}, extractedToken.Token)
446+
ctx = context.WithValue(ctx, ValidatedClaimsContextKey{}, claims)
416447
ctx = context.WithValue(ctx, CustomClaimsContextKey{}, customClaims)
417448
ctx = context.WithValue(ctx, CurrentSubjectContextKey{}, claims.RegisteredClaims.Subject)
418449
ctx = context.WithValue(ctx, AccountNameContextKey{}, customClaims.AccountName)
@@ -445,14 +476,8 @@ func ensureValidTokenHandler(config MiddlewareConfig, next http.Handler) http.Ha
445476

446477
var shouldBypass bool
447478

448-
// If config.BypassAuth is true then bypass
449-
if config.BypassAuth {
450-
shouldBypass = true
451-
}
452-
453-
// If we aren't bypassing always and we have a regex then check if we
454-
// should bypass
455-
if !shouldBypass && config.BypassAuthForPaths != nil {
479+
// Check if the request path matches the bypass regex
480+
if config.BypassAuthForPaths != nil {
456481
shouldBypass = config.BypassAuthForPaths.MatchString(r.URL.Path)
457482
if shouldBypass {
458483
span.SetAttributes(attribute.String("ovm.auth.bypassedPath", r.URL.Path))

go/auth/middleware_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"testing"
1313
"time"
1414

15-
"github.com/auth0/go-jwt-middleware/v2/validator"
15+
"github.com/auth0/go-jwt-middleware/v3/validator"
1616
"github.com/go-jose/go-jose/v4"
1717
"github.com/go-jose/go-jose/v4/jwt"
1818
log "github.com/sirupsen/logrus"

0 commit comments

Comments
 (0)