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的声明
Click to show internal directories.
Click to hide internal directories.