diff options
Diffstat (limited to 'backend/auth/jwt.go')
| -rw-r--r-- | backend/auth/jwt.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/backend/auth/jwt.go b/backend/auth/jwt.go index 0b92155..b7abc68 100644 --- a/backend/auth/jwt.go +++ b/backend/auth/jwt.go @@ -33,6 +33,21 @@ func NewJWT(user *db.User) (string, error) { return token.SignedString([]byte("TODO")) } +func NewShortLivedJWT(claims *JWTClaims) (string, error) { + newClaims := &JWTClaims{ + UserID: claims.UserID, + Username: claims.Username, + DisplayName: claims.DisplayName, + IconPath: claims.IconPath, + IsAdmin: claims.IsAdmin, + RegisteredClaims: jwt.RegisteredClaims{ + ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * 5)), + }, + } + token := jwt.NewWithClaims(jwt.SigningMethodHS256, newClaims) + return token.SignedString([]byte("TODO")) +} + func ParseJWT(token string) (*JWTClaims, error) { claims := new(JWTClaims) t, err := jwt.ParseWithClaims(token, claims, func(t *jwt.Token) (interface{}, error) { |
