MCPcopy Create free account
hub / github.com/cloud-native-go/examples / verifyToken

Function verifyToken

ch12/jwt/token.go:54–70  ·  view source on GitHub ↗
(tokenString string)

Source from the content-addressed store, hash-verified

52}
53
54func verifyToken(tokenString string) (*CustomClaims, error) {
55 token, err := jwt.ParseWithClaims(tokenString, &CustomClaims{}, keyFunc)
56 if err != nil {
57 return nil, err
58 }
59
60 claims, ok := token.Claims.(*CustomClaims)
61 if !ok {
62 return nil, fmt.Errorf("unknown claims type")
63 }
64
65 if time.Now().After(claims.ExpiresAt.Time) {
66 return nil, fmt.Errorf("token expired")
67 }
68
69 return claims, nil
70}

Callers 2

TestBuildAndVerifyTokenFunction · 0.85
verifyHandlerFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestBuildAndVerifyTokenFunction · 0.68