Skip to content

Commit dd6500a

Browse files
committed
fix bug where mytokens that are not yet valid cannot be created
1 parent 19c16b2 commit dd6500a

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
- Fixed PKCE code verifier length.
3737
- Fixed Datetimepicker issues on consent page.
3838
- Fixed response type if an (oidc) error occures on the redirect step of the authorization code flow.
39+
- Fixed a bug where mytokens that are not yet valid could not be created
3940

4041
## mytoken 0.3.2
4142

internal/endpoints/token/mytoken/polling/pollingEndpoint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func handlePollingCode(req response.PollingCodeRequest, networkData api.ClientMe
6565
Response: api.ErrorAuthorizationPending,
6666
}
6767
}
68-
mt, err := mytoken.ParseJWT(token)
68+
mt, err := mytoken.ParseJWTWithoutClaimsValidation(token)
6969
if err != nil {
7070
log.Errorf("%s", errorfmt.Full(err))
7171
return model.ErrorToInternalServerErrorResponse(err)

shared/mytoken/pkg/mytoken.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,31 @@ func (mt *Mytoken) ToJWT() (string, error) {
255255
return mt.jwt, nil
256256
}
257257
var err error
258-
mt.jwt, err = jwt.NewWithClaims(jwt.GetSigningMethod(config.Get().Signing.Alg), mt).SignedString(jws.GetPrivateKey())
258+
mt.jwt, err = jwt.NewWithClaims(
259+
jwt.GetSigningMethod(config.Get().Signing.Alg), mt,
260+
).SignedString(jws.GetPrivateKey())
259261
return mt.jwt, errors.WithStack(err)
260262
}
261263

262264
// ParseJWT parses a token string into a Mytoken
263265
func ParseJWT(token string) (*Mytoken, error) {
264-
tok, err := jwt.ParseWithClaims(token, &Mytoken{}, func(t *jwt.Token) (interface{}, error) {
265-
return jws.GetPublicKey(), nil
266-
})
266+
return parseJWT(token, false)
267+
}
268+
269+
// ParseJWTWithoutClaimsValidation parses a token string into a Mytoken
270+
func ParseJWTWithoutClaimsValidation(token string) (*Mytoken, error) {
271+
return parseJWT(token, true)
272+
}
273+
274+
func parseJWT(token string, skipCalimsValidation bool) (*Mytoken, error) {
275+
parser := jwt.Parser{
276+
SkipClaimsValidation: skipCalimsValidation,
277+
}
278+
tok, err := parser.ParseWithClaims(
279+
token, &Mytoken{}, func(t *jwt.Token) (interface{}, error) {
280+
return jws.GetPublicKey(), nil
281+
},
282+
)
267283
if err != nil {
268284
return nil, errors.WithStack(err)
269285
}

0 commit comments

Comments
 (0)