auth

package
v0.0.0-...-900783e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package auth provides OAuth-based authentication logic.

This file was generated by setup_project.sh script.

Index

Constants

View Source
const (
	BearerSchema        = "Bearer "
	HeaderAuthorization = "Authorization"
	UserCtxKey          = "UserID"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type JWTService

type JWTService struct {
	// contains filtered or unexported fields
}

JWTService 提供JWT令牌的服务

func NewJWTService

func NewJWTService(secretKey, issuer string) *JWTService

NewJWTService 创建JWT服务的新实例

func (*JWTService) AuthMiddleware

func (s *JWTService) AuthMiddleware() gin.HandlerFunc

AuthMiddleware 是一个检查JWT是否有效的中间件

func (*JWTService) GenerateToken

func (s *JWTService) GenerateToken(userID uint) (string, error)

GenerateToken 生成JWT令牌

func (*JWTService) ValidateToken

func (s *JWTService) ValidateToken(tokenString string) (*jwt.Token, error)

ValidateToken 验证JWT令牌

type JwtCustomClaims

type JwtCustomClaims struct {
	UserID uint `json:"userId"`
	jwt.StandardClaims
}

JwtCustomClaims 包含JWT的声明

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL