MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / Sign

Function Sign

pkg/wavejwt/wavejwt.go:117–143  ·  view source on GitHub ↗
(claims *WaveJwtClaims)

Source from the content-addressed store, hash-verified

115}
116
117func Sign(claims *WaveJwtClaims) (string, error) {
118 globalLock.Lock()
119 privKey := privateKey
120 globalLock.Unlock()
121
122 if privKey == nil {
123 return "", fmt.Errorf("private key not set")
124 }
125
126 if claims.IssuedAt == nil {
127 claims.IssuedAt = jwt.NewNumericDate(time.Now())
128 }
129 if claims.Issuer == "" {
130 claims.Issuer = IssuerWaveTerm
131 }
132 if claims.ExpiresAt == nil {
133 claims.ExpiresAt = jwt.NewNumericDate(time.Now().Add(time.Hour * 24 * 365))
134 }
135
136 token := jwt.NewWithClaims(jwt.SigningMethodEdDSA, claims)
137 tokenStr, err := token.SignedString(privKey)
138 if err != nil {
139 return "", fmt.Errorf("error signing token: %w", err)
140 }
141
142 return tokenStr, nil
143}

Callers 3

MakeClientJWTTokenFunction · 0.92
StartJobFunction · 0.92
doReconnectJobFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected