debian-mirror-gitlab/workhorse/internal/secret/jwt.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
521 B
Go
Raw Normal View History

2021-02-22 17:27:13 +05:30
package secret
import (
"fmt"
2021-11-11 11:23:49 +05:30
"github.com/golang-jwt/jwt/v4"
2021-02-22 17:27:13 +05:30
)
var (
2022-07-23 23:45:48 +05:30
DefaultClaims = jwt.RegisteredClaims{Issuer: "gitlab-workhorse"}
2021-02-22 17:27:13 +05:30
)
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
}