Documentation
¶
Index ¶
- func ExtractTokenFromMetadata(ctx context.Context) (string, error)
- func HasPermission(ctx context.Context, permission string) (bool, error)
- func RequirePermission(ctx context.Context, permission string) error
- func SetUserInContext(ctx context.Context, claims *JWTClaims) context.Context
- type AuthMiddleware
- type JWTClaims
- type JWT_CLAIM_KEY
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractTokenFromMetadata ¶
ExtractTokenFromMetadata extracts JWT token from gRPC metadata
func HasPermission ¶
HasPermission checks if the user in the context has the specified permission
func RequirePermission ¶
RequirePermission checks if the user has the required permission and returns an error if not
Types ¶
type AuthMiddleware ¶
type AuthMiddleware struct {
// contains filtered or unexported fields
}
AuthMiddleware provides JWT authentication for gRPC and HTTP requests
func InitAuthMiddleware ¶
func InitAuthMiddleware(secretKey string, enabled bool) *AuthMiddleware
InitAuthMiddleware initializes auth middleware with config
func NewAuthMiddleware ¶
func NewAuthMiddleware(jwtSecret string, enabled bool) *AuthMiddleware
NewAuthMiddleware creates a new auth middleware instance
func (*AuthMiddleware) HTTPMiddleware ¶
func (a *AuthMiddleware) HTTPMiddleware(next http.Handler) http.Handler
HTTPMiddleware provides JWT authentication for HTTP requests
func (*AuthMiddleware) StreamServerInterceptor ¶
func (a *AuthMiddleware) StreamServerInterceptor() grpc.StreamServerInterceptor
StreamServerInterceptor provides JWT authentication for streaming gRPC calls
func (*AuthMiddleware) UnaryServerInterceptor ¶
func (a *AuthMiddleware) UnaryServerInterceptor() grpc.UnaryServerInterceptor
UnaryServerInterceptor provides JWT authentication for unary gRPC calls
type JWTClaims ¶
type JWTClaims struct {
UserID int64 `json:"userId"`
UserUUID string `json:"userUUID"`
SessionUUID string `json:"sessionUUID"`
DeviceID string `json:"deviceId,omitempty"`
Permissions []string `json:"permissions,omitempty"`
jwt.RegisteredClaims
}
Token claims structure
func GetUserFromContext ¶
GetUserFromContext extracts user claims from context
func ParseAndValidateToken ¶
ParseAndValidateToken parses and validates a JWT token
func (*JWTClaims) HasPermission ¶
type JWT_CLAIM_KEY ¶
type JWT_CLAIM_KEY string
const (
JWT_CLAIM_KEY_USER JWT_CLAIM_KEY = "user_claims"
)