This repository was archived by the owner on Jul 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
This repository was archived by the owner on Jul 13, 2023. It is now read-only.
Server: refactor token verification to use the full verify library #8
Copy link
Copy link
Open
Milestone
Description
authenticator/cmd/server/transaction.go
Lines 183 to 208 in 4ee6ce9
func (rt *requestTx) checkJWT(token string, valid time.Time) (*jwt.Claims, error) { | |
log := rt.log.WithField("token", token) | |
if token == "" { | |
log.WithError(errors.New(errMissingToken)).Warn("checkJWT") | |
return nil, status.Error(codes.InvalidArgument, errMissingToken) | |
} | |
kid, err := verify.ParseJWTHeader(token) | |
if err != nil { | |
log.WithError(err).Warn("tokens.ParseJWTHeader()") | |
return nil, status.Error(codes.Unauthenticated, "Invalid token header") | |
} | |
key, err := rt.findJWTKey(kid) | |
if err != nil { | |
return nil, err | |
} | |
claims, err := jwt.EdDSACheck([]byte(token), []byte(key)) | |
if err != nil { | |
log.WithError(err).Warn("jwt.EdDSACheck()") | |
return nil, status.Error(codes.Unauthenticated, "EdDSA verification failed") | |
} | |
if !claims.Valid(valid) { | |
log.WithError(errors.New(errExpiredToken)).Warn("jwt.EdDSACheck()") | |
return nil, status.Error(codes.Unauthenticated, errExpiredToken) | |
} | |
return claims, nil | |
} |
Metadata
Metadata
Assignees
Labels
No labels