Skip to content

Commit 69b1670

Browse files
ponimasericchiang
authored andcommitted
refactor: Remove unused time injection from RemoteKeySet
Remove the time injection parameter and now function field from RemoteKeySet as they were not being used in the codebase. This simplifies the constructor signature and reduces unnecessary complexity in the JWKS key set implementation. The time package import was also removed as it's no longer needed.
1 parent 8d1e57e commit 69b1670

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

oidc/jwks.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"io"
1212
"net/http"
1313
"sync"
14-
"time"
1514

1615
jose "github.com/go-jose/go-jose/v4"
1716
)
@@ -57,16 +56,12 @@ func (s *StaticKeySet) VerifySignature(ctx context.Context, jwt string) ([]byte,
5756
// The returned KeySet is a long lived verifier that caches keys based on any
5857
// keys change. Reuse a common remote key set instead of creating new ones as needed.
5958
func NewRemoteKeySet(ctx context.Context, jwksURL string) *RemoteKeySet {
60-
return newRemoteKeySet(ctx, jwksURL, time.Now)
59+
return newRemoteKeySet(ctx, jwksURL)
6160
}
6261

63-
func newRemoteKeySet(ctx context.Context, jwksURL string, now func() time.Time) *RemoteKeySet {
64-
if now == nil {
65-
now = time.Now
66-
}
62+
func newRemoteKeySet(ctx context.Context, jwksURL string) *RemoteKeySet {
6763
return &RemoteKeySet{
6864
jwksURL: jwksURL,
69-
now: now,
7065
// For historical reasons, this package uses contexts for configuration, not just
7166
// cancellation. In hindsight, this was a bad idea.
7267
//
@@ -81,7 +76,6 @@ func newRemoteKeySet(ctx context.Context, jwksURL string, now func() time.Time)
8176
// a jwks_uri endpoint.
8277
type RemoteKeySet struct {
8378
jwksURL string
84-
now func() time.Time
8579

8680
// Used for configuration. Cancelation is ignored.
8781
ctx context.Context

oidc/jwks_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func TestKeyVerifyContextCanceled(t *testing.T) {
157157
}))
158158
defer s.Close()
159159

160-
rks := newRemoteKeySet(ctx, s.URL, nil)
160+
rks := newRemoteKeySet(ctx, s.URL)
161161

162162
cancel()
163163

@@ -195,7 +195,7 @@ func testKeyVerify(t *testing.T, good, bad *signingKey, verification ...*signing
195195
s := httptest.NewServer(&keyServer{keys: keySet})
196196
defer s.Close()
197197

198-
rks := newRemoteKeySet(ctx, s.URL, nil)
198+
rks := newRemoteKeySet(ctx, s.URL)
199199

200200
// Ensure the token verifies.
201201
gotPayload, err := rks.verify(ctx, jws)
@@ -242,7 +242,6 @@ func TestRotation(t *testing.T) {
242242
}
243243

244244
cacheForSeconds := 1200
245-
now := time.Now()
246245

247246
server := &keyServer{
248247
keys: jose.JSONWebKeySet{
@@ -255,7 +254,7 @@ func TestRotation(t *testing.T) {
255254
s := httptest.NewServer(server)
256255
defer s.Close()
257256

258-
rks := newRemoteKeySet(ctx, s.URL, func() time.Time { return now })
257+
rks := newRemoteKeySet(ctx, s.URL)
259258

260259
if _, err := rks.verify(ctx, jws1); err != nil {
261260
t.Errorf("failed to verify valid signature: %v", err)

0 commit comments

Comments
 (0)