Skip to content

Commit 23a36ad

Browse files
committed
minor
1 parent 3a246fa commit 23a36ad

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ Read more about GCM at: https://en.wikipedia.org/wiki/Galois/Counter_Mode
563563
Here is what helped me to implement JWT in Go:
564564

565565
- The JWT RFC: https://tools.ietf.org/html/rfc7519
566+
- The JWK RFC: See https://tools.ietf.org/html/rfc7517#section-5
566567
- The official JWT book, all you need to learn: https://auth0.com/resources/ebooks/jwt-handbook
567568
- Create Your JWTs From Scratch (PHP): https://dzone.com/articles/create-your-jwts-from-scratch
568569
- How to make your own JWT (Javascript): https://medium.com/code-wave/how-to-make-your-own-jwt-c1a32b5c3898

claims.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,11 @@ func (c Claims) ApplyClaims(dest *Claims) {
234234
// See the `Clock` package-level variable to modify
235235
// the current time function.
236236
func MaxAge(maxAge time.Duration) SignOptionFunc {
237+
if maxAge <= time.Second {
238+
return NoMaxAge
239+
}
240+
237241
return func(c *Claims) {
238-
if maxAge <= time.Second {
239-
return
240-
}
241242
now := Clock()
242243
c.Expiry = now.Add(maxAge).Unix()
243244
c.IssuedAt = now.Unix()

kid_keys.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,12 @@ func (keys Keys) VerifyToken(token []byte, claimsPtr any, validators ...TokenVal
250250
return verifiedToken.Claims(&claimsPtr)
251251
}
252252

253-
// JWKS returns the JSON Web Key Set (JWKS) based on the registered keys (RSA or EdDSA).
253+
// JWKS returns the JSON Web Key Set (JWKS) based on the registered keys.
254+
// Its result is ready for serving the JWKS on /.well-known/jwks.json.
255+
//
256+
// See https://tools.ietf.org/html/rfc7517#section-5 for more.
254257
func (keys Keys) JWKS() (*JWKS, error) {
255-
jkeys := make([]*JWK, 0, len(keys))
258+
sets := make([]*JWK, 0, len(keys))
256259

257260
for _, key := range keys {
258261
alg := ""
@@ -263,9 +266,9 @@ func (keys Keys) JWKS() (*JWKS, error) {
263266
if err != nil {
264267
return nil, err
265268
}
266-
jkeys = append(jkeys, jwk)
269+
sets = append(sets, jwk)
267270
}
268271

269-
jwks := JWKS{Keys: jkeys}
272+
jwks := JWKS{Keys: sets}
270273
return &jwks, nil
271274
}

sign_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
func TestSignOption(t *testing.T) {
1212
now := time.Date(2020, 10, 26, 1, 1, 1, 1, time.Local)
13-
exp := now.Add(time.Second).Unix()
13+
exp := now.Add(time.Second * 2).Unix()
1414
iat := now.Unix()
1515
type claims struct {
1616
Foo string `json:"foo"`
@@ -35,7 +35,7 @@ func TestSignOption(t *testing.T) {
3535
return now
3636
}
3737

38-
token, err := Sign(testAlg, testSecret, Map{"foo": "bar"}, expectedStdClaims, MaxAge(time.Second))
38+
token, err := Sign(testAlg, testSecret, Map{"foo": "bar"}, expectedStdClaims, MaxAge(time.Second*2))
3939

4040
if err != nil {
4141
t.Fatal(err)

0 commit comments

Comments
 (0)