refactor: move Claims type from auth to new identity package

Extract Claims struct from auth/types.go into dedicated identity package for better separation of concerns. Update all imports and usages across auth service, token handling, and request context utilities.
This commit is contained in:
2026-03-15 16:39:02 +01:00
parent 298d301ce8
commit 8f73dd3321
5 changed files with 23 additions and 16 deletions

View File

@@ -8,6 +8,8 @@ import (
"github.com/golang-jwt/jwt/v5"
"github.com/google/uuid"
"github.com/nexavpn/nexavpn/backend/internal/identity"
)
func NewRefreshToken() (plain string, hashed string, err error) {
@@ -22,7 +24,7 @@ func NewRefreshToken() (plain string, hashed string, err error) {
return plain, hashed, nil
}
func SignAccessToken(secret, issuer string, ttl time.Duration, claims Claims) (string, error) {
func SignAccessToken(secret, issuer string, ttl time.Duration, claims identity.Claims) (string, error) {
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"iss": issuer,
"sub": claims.UserID.String(),
@@ -36,8 +38,8 @@ func SignAccessToken(secret, issuer string, ttl time.Duration, claims Claims) (s
return token.SignedString([]byte(secret))
}
func ParseAccessToken(secret string, tokenString string) (Claims, error) {
claims := Claims{}
func ParseAccessToken(secret string, tokenString string) (identity.Claims, error) {
claims := identity.Claims{}
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (any, error) {
return []byte(secret), nil