(claims *WaveJwtClaims)
| 115 | } |
| 116 | |
| 117 | func 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 | } |
no outgoing calls
no test coverage detected