debian-mirror-gitlab/workhorse/internal/secret/jwt.go
2022-07-29 14:03:07 +02:00

25 lines
521 B
Go

package secret
import (
"fmt"
"github.com/golang-jwt/jwt/v4"
)
var (
DefaultClaims = jwt.RegisteredClaims{Issuer: "gitlab-workhorse"}
)
func JWTTokenString(claims jwt.Claims) (string, error) {
secretBytes, err := Bytes()
if err != nil {
return "", fmt.Errorf("secret.JWTTokenString: %v", err)
}
tokenString, err := jwt.NewWithClaims(jwt.SigningMethodHS256, claims).SignedString(secretBytes)
if err != nil {
return "", fmt.Errorf("secret.JWTTokenString: sign JWT: %v", err)
}
return tokenString, nil
}