refresh token in cookie

This commit is contained in:
nquidox 2025-09-08 22:38:30 +03:00
parent 51ee003b24
commit 20a5361a06
2 changed files with 17 additions and 20 deletions

View file

@ -4,6 +4,7 @@ import (
"fmt"
"github.com/golang-jwt/jwt/v5"
log "github.com/sirupsen/logrus"
"net/http"
"strconv"
"strings"
"time"
@ -51,26 +52,17 @@ func (j *JWT) CreateAccessToken(userUuid string) (string, error) {
return signedToken, nil
}
func (j *JWT) CreateRefreshToken(userUuid, tokenUuid string) (string, int64, error) {
now := time.Now()
exp := now.Add(j.RefreshExpire).Unix()
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"exp": exp,
"iat": now.Unix(),
"iss": j.Issuer,
"nbf": now.Unix(),
"sub": userUuid,
"tkn": tokenUuid,
})
signedToken, err := token.SignedString([]byte(j.SecretKey))
if err != nil {
return "", 0, err
func (j *JWT) CreateRefreshToken(refreshUuid string, expires time.Time) *http.Cookie {
return &http.Cookie{
Name: "refresh_uuid",
Value: refreshUuid,
Path: "",
Expires: expires,
Secure: true,
HttpOnly: true,
SameSite: 3,
Partitioned: false,
}
return signedToken, exp, nil
}
func (j *JWT) Parse(token string) (string, string, error) {