MCPcopy Create free account
hub / github.com/wavetermdev/waveterm / ValidateAndExtract

Function ValidateAndExtract

pkg/wavejwt/wavejwt.go:90–115  ·  view source on GitHub ↗
(tokenStr string)

Source from the content-addressed store, hash-verified

88}
89
90func 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
117func Sign(claims *WaveJwtClaims) (string, error) {
118 globalLock.Lock()

Calls

no outgoing calls

Tested by

no test coverage detected