generated from VLADIMIR/template
fix
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// Package processor_jwt processes JSON Web Tokens.
|
||||
package processor_jwt
|
||||
|
||||
import "context"
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// NewAuthorizationInterceptor creates a gRPC JWT authorization interceptor.
|
||||
func NewAuthorizationInterceptor(
|
||||
publicMethods map[string]bool,
|
||||
processorJWT IProcessorJWT,
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
// JWTClaims contains claims extracted from a JSON Web Token.
|
||||
type JWTClaims struct {
|
||||
UserID int `json:"user_id"`
|
||||
UserEmail string `json:"user_email"`
|
||||
@@ -13,10 +14,12 @@ type JWTClaims struct {
|
||||
jwt.RegisteredClaims
|
||||
}
|
||||
|
||||
// HasRole reports whether the claims contain role.
|
||||
func (c *JWTClaims) HasRole(role string) bool {
|
||||
return slices.Contains(c.Roles, role)
|
||||
}
|
||||
|
||||
// IProcessorJWT validates and creates JSON Web Tokens.
|
||||
type IProcessorJWT interface {
|
||||
GenerateAccessToken(userID int, userEmail string, userRoles []string) (string, error)
|
||||
GenerateRefreshToken(userID int) (string, error)
|
||||
|
||||
@@ -12,6 +12,7 @@ type processor struct {
|
||||
secret []byte
|
||||
}
|
||||
|
||||
// NewProcessor creates a JWT processor.
|
||||
func NewProcessor(secret string) IProcessorJWT {
|
||||
return &processor{
|
||||
secret: []byte(secret),
|
||||
|
||||
Reference in New Issue
Block a user