Skip to content

Commit 2dea22f

Browse files
authored
chore: Update github.com/zitadel/oidc v1 to v3 (#2585)
Also removes dependency on gopkg.in/square/go-jose.v2 Signed-off-by: Andrei Aaron <[email protected]>
1 parent fa4b699 commit 2dea22f

File tree

7 files changed

+44
-35
lines changed

7 files changed

+44
-35
lines changed

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ require (
5858
github.com/swaggo/http-swagger v1.3.4
5959
github.com/swaggo/swag v1.16.3
6060
github.com/vektah/gqlparser/v2 v2.5.16
61-
github.com/zitadel/oidc v1.13.5
61+
github.com/zitadel/oidc/v3 v3.26.0
6262
go.etcd.io/bbolt v1.3.10
6363
golang.org/x/crypto v0.25.0
6464
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
@@ -269,7 +269,6 @@ require (
269269
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
270270
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
271271
github.com/gopherjs/gopherjs v1.17.2 // indirect
272-
github.com/gorilla/schema v1.4.1 // indirect
273272
github.com/gorilla/websocket v1.5.3 // indirect
274273
github.com/gosuri/uitable v0.0.4 // indirect
275274
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
@@ -346,6 +345,7 @@ require (
346345
github.com/modern-go/reflect2 v1.0.2 // indirect
347346
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
348347
github.com/mozillazg/docker-credential-acr-helper v0.3.0 // indirect
348+
github.com/muhlemmer/gu v0.3.1 // indirect
349349
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
350350
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
351351
github.com/ncruces/go-strftime v0.1.9 // indirect
@@ -432,6 +432,8 @@ require (
432432
github.com/zclconf/go-cty v1.15.0 // indirect
433433
github.com/zclconf/go-cty-yaml v1.0.3 // indirect
434434
github.com/zeebo/errs v1.3.0 // indirect
435+
github.com/zitadel/logging v0.6.0 // indirect
436+
github.com/zitadel/schema v1.3.0 // indirect
435437
go.mongodb.org/mongo-driver v1.16.0 // indirect
436438
go.mozilla.org/pkcs7 v0.0.0-20210826202110-33d05740a352 // indirect
437439
go.opencensus.io v0.24.0 // indirect
@@ -479,7 +481,6 @@ require (
479481
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
480482
gopkg.in/inf.v0 v0.9.1 // indirect
481483
gopkg.in/ini.v1 v1.67.0 // indirect
482-
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
483484
gopkg.in/warnings.v0 v0.1.2 // indirect
484485
gopkg.in/yaml.v3 v3.0.1 // indirect
485486
helm.sh/helm/v3 v3.15.3 // indirect

go.sum

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,8 @@ github.com/go-asn1-ber/asn1-ber v1.5.7 h1:DTX+lbVTWaTw1hQ+PbZPlnDZPEIs0SS/GCZAl5
682682
github.com/go-asn1-ber/asn1-ber v1.5.7/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
683683
github.com/go-chi/chi v4.1.2+incompatible h1:fGFk2Gmi/YKXk0OmGfBh0WgmN3XB8lVnEyNz34tQRec=
684684
github.com/go-chi/chi v4.1.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
685+
github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
686+
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
685687
github.com/go-errors/errors v1.5.1 h1:ZwEMSLRCapFLflTpT7NKaAc7ukJ8ZPEjzlxt8rPN8bk=
686688
github.com/go-errors/errors v1.5.1/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
687689
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
@@ -924,8 +926,6 @@ github.com/gorilla/handlers v1.5.2 h1:cLTUSsNkgcwhgRqvCNmdbRWG0A3N4F+M2nWKdScwyE
924926
github.com/gorilla/handlers v1.5.2/go.mod h1:dX+xVpaxdSw+q0Qek8SSsl3dfMk3jNddUkMzo0GtH0w=
925927
github.com/gorilla/mux v1.8.2-0.20240619235004-db9d1d0073d2 h1:oZRjfKe/6Qh676XFYvylkCWd0gu8KVZeZYZwkNw6NAU=
926928
github.com/gorilla/mux v1.8.2-0.20240619235004-db9d1d0073d2/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
927-
github.com/gorilla/schema v1.4.1 h1:jUg5hUjCSDZpNGLuXQOgIWGdlgrIdYvgQ0wZtdK1M3E=
928-
github.com/gorilla/schema v1.4.1/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM=
929929
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
930930
github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA=
931931
github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo=
@@ -1180,6 +1180,10 @@ github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
11801180
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
11811181
github.com/mozillazg/docker-credential-acr-helper v0.3.0 h1:DVWFZ3/O8BP6Ue3iS/Olw+G07u1hCq1EOVCDZZjCIBI=
11821182
github.com/mozillazg/docker-credential-acr-helper v0.3.0/go.mod h1:cZlu3tof523ujmLuiNUb6JsjtHcNA70u1jitrrdnuyA=
1183+
github.com/muhlemmer/gu v0.3.1 h1:7EAqmFrW7n3hETvuAdmFmn4hS8W+z3LgKtrnow+YzNM=
1184+
github.com/muhlemmer/gu v0.3.1/go.mod h1:YHtHR+gxM+bKEIIs7Hmi9sPT3ZDUvTN/i88wQpZkrdM=
1185+
github.com/muhlemmer/httpforwarded v0.1.0 h1:x4DLrzXdliq8mprgUMR0olDvHGkou5BJsK/vWUetyzY=
1186+
github.com/muhlemmer/httpforwarded v0.1.0/go.mod h1:yo9czKedo2pdZhoXe+yDkGVbU0TJ0q9oQ90BVoDEtw0=
11831187
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
11841188
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
11851189
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
@@ -1543,10 +1547,12 @@ github.com/zclconf/go-cty-yaml v1.0.3 h1:og/eOQ7lvA/WWhHGFETVWNduJM7Rjsv2RRpx1sd
15431547
github.com/zclconf/go-cty-yaml v1.0.3/go.mod h1:9YLUH4g7lOhVWqUbctnVlZ5KLpg7JAprQNgxSZ1Gyxs=
15441548
github.com/zeebo/errs v1.3.0 h1:hmiaKqgYZzcVgRL1Vkc1Mn2914BbzB0IBxs+ebeutGs=
15451549
github.com/zeebo/errs v1.3.0/go.mod h1:sgbWHsvVuTPHcqJJGQ1WhI5KbWlHYz+2+2C/LSEtCw4=
1546-
github.com/zitadel/logging v0.3.4 h1:9hZsTjMMTE3X2LUi0xcF9Q9EdLo+FAezeu52ireBbHM=
1547-
github.com/zitadel/logging v0.3.4/go.mod h1:aPpLQhE+v6ocNK0TWrBrd363hZ95KcI17Q1ixAQwZF0=
1548-
github.com/zitadel/oidc v1.13.5 h1:7jhh68NGZitLqwLiVU9Dtwa4IraJPFF1vS+4UupO93U=
1549-
github.com/zitadel/oidc v1.13.5/go.mod h1:rHs1DhU3Sv3tnI6bQRVlFa3u0lCwtR7S21WHY+yXgPA=
1550+
github.com/zitadel/logging v0.6.0 h1:t5Nnt//r+m2ZhhoTmoPX+c96pbMarqJvW1Vq6xFTank=
1551+
github.com/zitadel/logging v0.6.0/go.mod h1:Y4CyAXHpl3Mig6JOszcV5Rqqsojj+3n7y2F591Mp/ow=
1552+
github.com/zitadel/oidc/v3 v3.26.0 h1:BG3OUK+JpuKz7YHJIyUxL5Sl2JV6ePkG42UP4Xv3J2w=
1553+
github.com/zitadel/oidc/v3 v3.26.0/go.mod h1:Cx6AYPTJO5q2mjqF3jaknbKOUjpq1Xui0SYvVhkKuXU=
1554+
github.com/zitadel/schema v1.3.0 h1:kQ9W9tvIwZICCKWcMvCEweXET1OcOyGEuFbHs4o5kg0=
1555+
github.com/zitadel/schema v1.3.0/go.mod h1:NptN6mkBDFvERUCvZHlvWmmME+gmZ44xzwRXwhzsbtc=
15501556
go.etcd.io/bbolt v1.3.10 h1:+BqfJTcCzTItrop8mq/lbzL8wSGtj94UO/3U31shqG0=
15511557
go.etcd.io/bbolt v1.3.10/go.mod h1:bK3UQLPJZly7IlNmV7uVHJDxfe5aK9Ll93e/74Y9oEQ=
15521558
go.mongodb.org/mongo-driver v1.16.0 h1:tpRsfBJMROVHKpdGyc1BBEzzjDUWjItxbVSZ8Ls4BQ4=
@@ -2232,8 +2238,6 @@ gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
22322238
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
22332239
gopkg.in/resty.v1 v1.12.0 h1:CuXP0Pjfw9rOuY6EP+UvtNvt5DSqHpIxILZKT/quCZI=
22342240
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
2235-
gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI=
2236-
gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
22372241
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
22382242
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
22392243
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=

pkg/api/authn.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import (
2525
"github.com/gorilla/securecookie"
2626
"github.com/gorilla/sessions"
2727
godigest "github.com/opencontainers/go-digest"
28-
"github.com/zitadel/oidc/pkg/client/rp"
29-
httphelper "github.com/zitadel/oidc/pkg/http"
30-
"github.com/zitadel/oidc/pkg/oidc"
28+
"github.com/zitadel/oidc/v3/pkg/client/rp"
29+
httphelper "github.com/zitadel/oidc/v3/pkg/http"
30+
"github.com/zitadel/oidc/v3/pkg/oidc"
3131
"golang.org/x/crypto/bcrypt"
3232
"golang.org/x/oauth2"
3333
githubOAuth "golang.org/x/oauth2/github"
@@ -334,7 +334,7 @@ func (amw *AuthnMiddleware) tryAuthnHandlers(ctlr *Controller) mux.MiddlewareFun
334334

335335
for provider := range ctlr.Config.HTTP.Auth.OpenID.Providers {
336336
if config.IsOpenIDSupported(provider) {
337-
rp := NewRelyingPartyOIDC(ctlr.Config, provider, ctlr.Log)
337+
rp := NewRelyingPartyOIDC(context.TODO(), ctlr.Config, provider, ctlr.Log)
338338
ctlr.RelyingParties[provider] = rp
339339
} else if config.IsOauth2Supported(provider) {
340340
rp := NewRelyingPartyGithub(ctlr.Config, provider, ctlr.Log)
@@ -610,10 +610,10 @@ func (rh *RouteHandler) AuthURLHandler() http.HandlerFunc {
610610
}
611611
}
612612

613-
func NewRelyingPartyOIDC(config *config.Config, provider string, log log.Logger) rp.RelyingParty {
613+
func NewRelyingPartyOIDC(ctx context.Context, config *config.Config, provider string, log log.Logger) rp.RelyingParty {
614614
issuer, clientID, clientSecret, redirectURI, scopes, options := getRelyingPartyArgs(config, provider, log)
615615

616-
relyingParty, err := rp.NewRelyingPartyOIDC(issuer, clientID, clientSecret, redirectURI, scopes, options...)
616+
relyingParty, err := rp.NewRelyingPartyOIDC(ctx, issuer, clientID, clientSecret, redirectURI, scopes, options...)
617617
if err != nil {
618618
log.Panic().Err(err).Str("issuer", issuer).Str("redirectURI", redirectURI).Strs("scopes", scopes).
619619
Msg("failed to get new relying party oicd")

pkg/api/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"time"
1616

1717
"github.com/gorilla/mux"
18-
"github.com/zitadel/oidc/pkg/client/rp"
18+
"github.com/zitadel/oidc/v3/pkg/client/rp"
1919

2020
"zotregistry.dev/zot/errors"
2121
"zotregistry.dev/zot/pkg/api/config"

pkg/api/controller_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4068,6 +4068,7 @@ func TestBearerAuthWithAllowReadAccess(t *testing.T) {
40684068
func TestNewRelyingPartyOIDC(t *testing.T) {
40694069
Convey("Test NewRelyingPartyOIDC", t, func() {
40704070
conf := config.New()
4071+
ctx := context.Background()
40714072

40724073
mockOIDCServer, err := authutils.MockOIDCRun()
40734074
if err != nil {
@@ -4098,15 +4099,15 @@ func TestNewRelyingPartyOIDC(t *testing.T) {
40984099
}
40994100

41004101
Convey("provider not found in config", func() {
4101-
So(func() { _ = api.NewRelyingPartyOIDC(conf, "notDex", log.NewLogger("debug", "")) }, ShouldPanic)
4102+
So(func() { _ = api.NewRelyingPartyOIDC(ctx, conf, "notDex", log.NewLogger("debug", "")) }, ShouldPanic)
41024103
})
41034104

41044105
Convey("key path not found on disk", func() {
41054106
oidcProviderCfg := conf.HTTP.Auth.OpenID.Providers["oidc"]
41064107
oidcProviderCfg.KeyPath = "path/to/file"
41074108
conf.HTTP.Auth.OpenID.Providers["oidc"] = oidcProviderCfg
41084109

4109-
So(func() { _ = api.NewRelyingPartyOIDC(conf, "oidc", log.NewLogger("debug", "")) }, ShouldPanic)
4110+
So(func() { _ = api.NewRelyingPartyOIDC(ctx, conf, "oidc", log.NewLogger("debug", "")) }, ShouldPanic)
41104111
})
41114112

41124113
Convey("https callback", func() {
@@ -4115,7 +4116,7 @@ func TestNewRelyingPartyOIDC(t *testing.T) {
41154116
Key: ServerKey,
41164117
}
41174118

4118-
rp := api.NewRelyingPartyOIDC(conf, "oidc", log.NewLogger("debug", ""))
4119+
rp := api.NewRelyingPartyOIDC(ctx, conf, "oidc", log.NewLogger("debug", ""))
41194120
So(rp, ShouldNotBeNil)
41204121
})
41214122

@@ -4124,7 +4125,7 @@ func TestNewRelyingPartyOIDC(t *testing.T) {
41244125
oidcProvider.ClientSecret = ""
41254126
conf.HTTP.Auth.OpenID.Providers["oidc"] = oidcProvider
41264127

4127-
rp := api.NewRelyingPartyOIDC(conf, "oidc", log.NewLogger("debug", ""))
4128+
rp := api.NewRelyingPartyOIDC(ctx, conf, "oidc", log.NewLogger("debug", ""))
41284129
So(rp, ShouldNotBeNil)
41294130
})
41304131

@@ -4133,7 +4134,7 @@ func TestNewRelyingPartyOIDC(t *testing.T) {
41334134
oidcProvider.Issuer = ""
41344135
conf.HTTP.Auth.OpenID.Providers["oidc"] = oidcProvider
41354136

4136-
So(func() { _ = api.NewRelyingPartyOIDC(conf, "oidc", log.NewLogger("debug", "")) }, ShouldPanic)
4137+
So(func() { _ = api.NewRelyingPartyOIDC(ctx, conf, "oidc", log.NewLogger("debug", "")) }, ShouldPanic)
41374138
})
41384139
})
41394140
}

pkg/api/routes.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import (
2929
"github.com/opencontainers/distribution-spec/specs-go/v1/extensions"
3030
godigest "github.com/opencontainers/go-digest"
3131
ispec "github.com/opencontainers/image-spec/specs-go/v1"
32-
"github.com/zitadel/oidc/pkg/client/rp"
33-
"github.com/zitadel/oidc/pkg/oidc"
32+
"github.com/zitadel/oidc/v3/pkg/client/rp"
33+
"github.com/zitadel/oidc/v3/pkg/oidc"
3434

3535
zerr "zotregistry.dev/zot/errors"
3636
"zotregistry.dev/zot/pkg/api/config"
@@ -1873,9 +1873,9 @@ func (rh *RouteHandler) Logout(response http.ResponseWriter, request *http.Reque
18731873
}
18741874

18751875
// github Oauth2 CodeExchange callback.
1876-
func (rh *RouteHandler) GithubCodeExchangeCallback() rp.CodeExchangeCallback {
1876+
func (rh *RouteHandler) GithubCodeExchangeCallback() rp.CodeExchangeCallback[*oidc.IDTokenClaims] {
18771877
return func(w http.ResponseWriter, r *http.Request,
1878-
tokens *oidc.Tokens, state string, relyingParty rp.RelyingParty,
1878+
tokens *oidc.Tokens[*oidc.IDTokenClaims], state string, relyingParty rp.RelyingParty,
18791879
) {
18801880
ctx := r.Context()
18811881

@@ -1908,11 +1908,14 @@ func (rh *RouteHandler) GithubCodeExchangeCallback() rp.CodeExchangeCallback {
19081908
}
19091909

19101910
// Openid CodeExchange callback.
1911-
func (rh *RouteHandler) OpenIDCodeExchangeCallback() rp.CodeExchangeUserinfoCallback {
1912-
return func(w http.ResponseWriter, r *http.Request, tokens *oidc.Tokens, state string,
1913-
relyingParty rp.RelyingParty, info oidc.UserInfo,
1911+
func (rh *RouteHandler) OpenIDCodeExchangeCallback() rp.CodeExchangeUserinfoCallback[
1912+
*oidc.IDTokenClaims,
1913+
*oidc.UserInfo,
1914+
] {
1915+
return func(w http.ResponseWriter, r *http.Request, tokens *oidc.Tokens[*oidc.IDTokenClaims], state string,
1916+
relyingParty rp.RelyingParty, info *oidc.UserInfo,
19141917
) {
1915-
email := info.GetEmail()
1918+
email := info.UserInfoEmail.Email
19161919
if email == "" {
19171920
rh.c.Log.Error().Msg("failed to set user record for empty email value")
19181921
w.WriteHeader(http.StatusUnauthorized)
@@ -1922,7 +1925,7 @@ func (rh *RouteHandler) OpenIDCodeExchangeCallback() rp.CodeExchangeUserinfoCall
19221925

19231926
var groups []string
19241927

1925-
val, ok := info.GetClaim("groups").([]interface{})
1928+
val, ok := info.Claims["groups"].([]interface{})
19261929
if !ok {
19271930
rh.c.Log.Info().Msgf("failed to find any 'groups' claim for user %s", email)
19281931
}

pkg/api/routes_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import (
1919
ispec "github.com/opencontainers/image-spec/specs-go/v1"
2020
"github.com/project-zot/mockoidc"
2121
. "github.com/smartystreets/goconvey/convey"
22-
"github.com/zitadel/oidc/pkg/client/rp"
23-
"github.com/zitadel/oidc/pkg/oidc"
22+
"github.com/zitadel/oidc/v3/pkg/client/rp"
23+
"github.com/zitadel/oidc/v3/pkg/oidc"
2424
"golang.org/x/oauth2"
2525

2626
zerr "zotregistry.dev/zot/errors"
@@ -105,7 +105,7 @@ func TestRoutes(t *testing.T) {
105105
request, _ := http.NewRequestWithContext(ctx, http.MethodGet, baseURL, nil)
106106
response := httptest.NewRecorder()
107107

108-
tokens := &oidc.Tokens{}
108+
tokens := &oidc.Tokens[*oidc.IDTokenClaims]{}
109109
relyingParty, err := rp.NewRelyingPartyOAuth(&oauth2.Config{})
110110
So(err, ShouldBeNil)
111111

0 commit comments

Comments
 (0)