Проверка и завершение требований уровней «3» и «4»

This commit is contained in:
Grbisba
2026-11-06 13:58:50 +03:00
parent 711754bbcd
commit 08ee3fe0b8
30 changed files with 1752 additions and 92 deletions
@@ -28,6 +28,7 @@ type claimsParseFunc func(token *dto.Token) (*jwtClaims, error)
type jwtClaims struct {
jwt.RegisteredClaims
Nonce string `json:"nonce,omitempty"`
IsAccess bool `json:"is_access"`
Role role.Role `json:"role"`
}
@@ -1,7 +1,9 @@
package jwtprovider
import (
"crypto/rand"
"crypto/rsa"
"encoding/base64"
"fmt"
"log/slog"
"time"
@@ -127,7 +129,12 @@ func (p *provider) createTokenForUser(userID uuid.UUID, isAccess bool, role role
} else {
tokenExpiresAt = now.Add(p.refreshLifetime)
}
var nonce [32]byte
if _, err := rand.Read(nonce[:]); err != nil {
return nil, fmt.Errorf("generate token nonce: %w", err)
}
claims := &jwtClaims{
Nonce: base64.RawURLEncoding.EncodeToString(nonce[:]),
RegisteredClaims: jwt.RegisteredClaims{
Subject: userID.String(),
ExpiresAt: jwt.NewNumericDate(tokenExpiresAt),