@@ -17,7 +17,7 @@ import (
17
17
"sync"
18
18
"time"
19
19
20
- "github.com/golang-jwt/jwt"
20
+ "github.com/golang-jwt/jwt/v5 "
21
21
22
22
log "github.com/sirupsen/logrus"
23
23
)
@@ -63,12 +63,10 @@ type Validator struct {
63
63
}
64
64
65
65
var (
66
- errKeyNotFound = errors .New ("unable to find appropriate key" )
67
- errInvalidAudience = errors .New ("invalid audience" )
68
- errInvalidIssuer = errors .New ("invalid issuer" )
69
- errTokenEmpty = errors .New ("required authorization token not found" )
70
- errTokenInvalid = errors .New ("token is invalid" )
71
- errTokenParsing = errors .New ("token could not be parsed" )
66
+ errKeyNotFound = errors .New ("unable to find appropriate key" )
67
+ errTokenEmpty = errors .New ("required authorization token not found" )
68
+ errTokenInvalid = errors .New ("token is invalid" )
69
+ errTokenParsing = errors .New ("token could not be parsed" )
72
70
)
73
71
74
72
func NewValidator (issuer string , audienceList []string , keysLocation string , idpSignkeyRefreshEnabled bool ) * Validator {
@@ -88,24 +86,6 @@ func NewValidator(issuer string, audienceList []string, keysLocation string, idp
88
86
89
87
func (v * Validator ) getKeyFunc (ctx context.Context ) jwt.Keyfunc {
90
88
return func (token * jwt.Token ) (interface {}, error ) {
91
- // Verify 'aud' claim
92
- var checkAud bool
93
- for _ , audience := range v .audienceList {
94
- checkAud = token .Claims .(jwt.MapClaims ).VerifyAudience (audience , false )
95
- if checkAud {
96
- break
97
- }
98
- }
99
- if ! checkAud {
100
- return token , errInvalidAudience
101
- }
102
-
103
- // Verify 'issuer' claim
104
- checkIss := token .Claims .(jwt.MapClaims ).VerifyIssuer (v .issuer , false )
105
- if ! checkIss {
106
- return token , errInvalidIssuer
107
- }
108
-
109
89
// If keys are rotated, verify the keys prior to token validation
110
90
if v .idpSignkeyRefreshEnabled {
111
91
// If the keys are invalid, retrieve new ones
@@ -144,7 +124,7 @@ func (v *Validator) getKeyFunc(ctx context.Context) jwt.Keyfunc {
144
124
}
145
125
146
126
// ValidateAndParse validates the token and returns the parsed token
147
- func (m * Validator ) ValidateAndParse (ctx context.Context , token string ) (* jwt.Token , error ) {
127
+ func (v * Validator ) ValidateAndParse (ctx context.Context , token string ) (* jwt.Token , error ) {
148
128
// If the token is empty...
149
129
if token == "" {
150
130
// If we get here, the required token is missing
@@ -153,7 +133,13 @@ func (m *Validator) ValidateAndParse(ctx context.Context, token string) (*jwt.To
153
133
}
154
134
155
135
// Now parse the token
156
- parsedToken , err := jwt .Parse (token , m .getKeyFunc (ctx ))
136
+ parsedToken , err := jwt .Parse (
137
+ token ,
138
+ v .getKeyFunc (ctx ),
139
+ jwt .WithAudience (v .audienceList ... ),
140
+ jwt .WithIssuer (v .issuer ),
141
+ jwt .WithIssuedAt (),
142
+ )
157
143
158
144
// Check if there was an error in parsing...
159
145
if err != nil {
0 commit comments