Skip to content

Commit a73d8a1

Browse files
committed
Unbreak some stuff
1 parent ca0f5b0 commit a73d8a1

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

map_claims_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ func TestVerifyAud(t *testing.T) {
5656

5757
for _, test := range tests {
5858
t.Run(test.Name, func(t *testing.T) {
59-
var opts []ParserOption
59+
var opts []ParserOption[MapClaims]
6060

6161
if test.Required {
62-
opts = append(opts, WithAudience(test.Comparison))
62+
opts = append(opts, WithAudience[MapClaims](test.Comparison))
6363
}
6464

65-
validator := newValidator(opts...)
65+
validator := newValidator[MapClaims](opts...)
6666
got := validator.Validate(test.MapClaims)
6767

6868
if (got == nil) != test.Expected {
@@ -77,7 +77,7 @@ func TestMapclaimsVerifyIssuedAtInvalidTypeString(t *testing.T) {
7777
"iat": "foo",
7878
}
7979
want := false
80-
got := newValidator(WithIssuedAt()).Validate(mapClaims)
80+
got := newValidator[MapClaims](WithIssuedAt[MapClaims]()).Validate(mapClaims)
8181
if want != (got == nil) {
8282
t.Fatalf("Failed to verify claims, wanted: %v got %v", want, (got == nil))
8383
}
@@ -88,7 +88,7 @@ func TestMapclaimsVerifyNotBeforeInvalidTypeString(t *testing.T) {
8888
"nbf": "foo",
8989
}
9090
want := false
91-
got := newValidator().Validate(mapClaims)
91+
got := newValidator[MapClaims]().Validate(mapClaims)
9292
if want != (got == nil) {
9393
t.Fatalf("Failed to verify claims, wanted: %v got %v", want, (got == nil))
9494
}
@@ -99,7 +99,7 @@ func TestMapclaimsVerifyExpiresAtInvalidTypeString(t *testing.T) {
9999
"exp": "foo",
100100
}
101101
want := false
102-
got := newValidator().Validate(mapClaims)
102+
got := newValidator[MapClaims]().Validate(mapClaims)
103103

104104
if want != (got == nil) {
105105
t.Fatalf("Failed to verify claims, wanted: %v got %v", want, (got == nil))
@@ -112,22 +112,22 @@ func TestMapClaimsVerifyExpiresAtExpire(t *testing.T) {
112112
"exp": float64(exp.Unix()),
113113
}
114114
want := false
115-
got := newValidator(WithTimeFunc(func() time.Time {
115+
got := newValidator[MapClaims](WithTimeFunc[MapClaims](func() time.Time {
116116
return exp
117117
})).Validate(mapClaims)
118118
if want != (got == nil) {
119119
t.Fatalf("Failed to verify claims, wanted: %v got %v", want, (got == nil))
120120
}
121121

122-
got = newValidator(WithTimeFunc(func() time.Time {
122+
got = newValidator[MapClaims](WithTimeFunc[MapClaims](func() time.Time {
123123
return exp.Add(1 * time.Second)
124124
})).Validate(mapClaims)
125125
if want != (got == nil) {
126126
t.Fatalf("Failed to verify claims, wanted: %v got %v", want, (got == nil))
127127
}
128128

129129
want = true
130-
got = newValidator(WithTimeFunc(func() time.Time {
130+
got = newValidator[MapClaims](WithTimeFunc[MapClaims](func() time.Time {
131131
return exp.Add(-1 * time.Second)
132132
})).Validate(mapClaims)
133133
if want != (got == nil) {

request/request.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212
// the logic for extracting a token. Several useful implementations are provided.
1313
//
1414
// You can provide options to modify parsing behavior
15-
func ParseFromRequest(req *http.Request, extractor Extractor, keyFunc jwt.Keyfunc, options ...ParseFromRequestOption) (token *jwt.Token, err error) {
15+
func ParseFromRequest(req *http.Request, extractor Extractor, keyFunc jwt.Keyfunc[jwt.MapClaims], options ...ParseFromRequestOption[jwt.MapClaims]) (token *jwt.Token[jwt.MapClaims], err error) {
1616
// Create basic parser struct
17-
p := &fromRequestParser{req, extractor, nil, nil}
17+
p := &fromRequestParser[jwt.MapClaims]{req, extractor, nil, nil}
1818

1919
// Handle options
2020
for _, option := range options {
@@ -26,7 +26,7 @@ func ParseFromRequest(req *http.Request, extractor Extractor, keyFunc jwt.Keyfun
2626
p.claims = jwt.MapClaims{}
2727
}
2828
if p.parser == nil {
29-
p.parser = &jwt.Parser{}
29+
p.parser = &jwt.Parser[jwt.MapClaims]{}
3030
}
3131

3232
// perform extract
@@ -42,29 +42,29 @@ func ParseFromRequest(req *http.Request, extractor Extractor, keyFunc jwt.Keyfun
4242
// ParseFromRequestWithClaims is an alias for ParseFromRequest but with custom Claims type.
4343
//
4444
// Deprecated: use ParseFromRequest and the WithClaims option
45-
func ParseFromRequestWithClaims(req *http.Request, extractor Extractor, claims jwt.Claims, keyFunc jwt.Keyfunc) (token *jwt.Token, err error) {
45+
func ParseFromRequestWithClaims[T jwt.Claims](req *http.Request, extractor Extractor, claims T, keyFunc jwt.Keyfunc[T]) (token *jwt.Token[T], err error) {
4646
return ParseFromRequest(req, extractor, keyFunc, WithClaims(claims))
4747
}
4848

49-
type fromRequestParser struct {
49+
type fromRequestParser[T jwt.Claims] struct {
5050
req *http.Request
5151
extractor Extractor
52-
claims jwt.Claims
53-
parser *jwt.Parser
52+
claims T
53+
parser *jwt.Parser[T]
5454
}
5555

56-
type ParseFromRequestOption func(*fromRequestParser)
56+
type ParseFromRequestOption[T jwt.Claims] func(*fromRequestParser[T])
5757

5858
// WithClaims parses with custom claims
59-
func WithClaims(claims jwt.Claims) ParseFromRequestOption {
60-
return func(p *fromRequestParser) {
59+
func WithClaims[T jwt.Claims](claims T) ParseFromRequestOption[T] {
60+
return func(p *fromRequestParser[T]) {
6161
p.claims = claims
6262
}
6363
}
6464

6565
// WithParser parses using a custom parser
66-
func WithParser(parser *jwt.Parser) ParseFromRequestOption {
67-
return func(p *fromRequestParser) {
66+
func WithParser[T jwt.Claims](parser *jwt.Parser[T]) ParseFromRequestOption[T] {
67+
return func(p *fromRequestParser[T]) {
6868
p.parser = parser
6969
}
7070
}

validator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type CustomClaims interface {
4848

4949
// newValidator can be used to create a stand-alone validator with the supplied
5050
// options. This validator can then be used to validate already parsed claims.
51-
func newValidator[T Claims](opts ...ParserOption) *validator {
51+
func newValidator[T Claims](opts ...ParserOption[T]) *validator {
5252
p := NewParser[T](opts...)
5353
return p.validator
5454
}

0 commit comments

Comments
 (0)