(tokenStr string)
| 88 | } |
| 89 | |
| 90 | func ValidateAndExtract(tokenStr string) (*WaveJwtClaims, error) { |
| 91 | globalLock.Lock() |
| 92 | pubKey := publicKey |
| 93 | globalLock.Unlock() |
| 94 | |
| 95 | if pubKey == nil { |
| 96 | return nil, fmt.Errorf("public key not set") |
| 97 | } |
| 98 | |
| 99 | token, err := jwt.ParseWithClaims(tokenStr, &WaveJwtClaims{}, func(token *jwt.Token) (interface{}, error) { |
| 100 | if _, ok := token.Method.(*jwt.SigningMethodEd25519); !ok { |
| 101 | return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) |
| 102 | } |
| 103 | return pubKey, nil |
| 104 | }) |
| 105 | if err != nil { |
| 106 | return nil, fmt.Errorf("failed to parse token: %w", err) |
| 107 | } |
| 108 | |
| 109 | claims, ok := token.Claims.(*WaveJwtClaims) |
| 110 | if !ok || !token.Valid { |
| 111 | return nil, fmt.Errorf("invalid token") |
| 112 | } |
| 113 | |
| 114 | return claims, nil |
| 115 | } |
| 116 | |
| 117 | func Sign(claims *WaveJwtClaims) (string, error) { |
| 118 | globalLock.Lock() |
no outgoing calls
no test coverage detected