Documentation
¶
Overview ¶
Package auth provides JWT authentication middleware for gin.
Index ¶
- Constants
- Variables
- func Auth(opts ...AuthOption) gin.HandlerFunc
- func GenerateToken(uid string, opts ...GenerateTokenOption) (string, error)
- func GetClaims(c *gin.Context) (*jwt.Claims, bool)
- func InitAuth(signingKey []byte, expire time.Duration, opts ...InitAuthOption)
- func ParseToken(token string) (*jwt.Claims, error)
- func RefreshToken(claims *jwt.Claims) (string, error)
- type AuthOption
- type Claims
- type ExtraVerifyFn
- type GenerateTokenOption
- type InitAuthOption
- type SigningMethodHMAC
Constants ¶
const HeaderAuthorizationKey = "Authorization"
HeaderAuthorizationKey http header authorization key, value is "Bearer token"
Variables ¶
Functions ¶
func Auth ¶
func Auth(opts ...AuthOption) gin.HandlerFunc
Auth authorization middleware, support custom extra verify.
func GenerateToken ¶
func GenerateToken(uid string, opts ...GenerateTokenOption) (string, error)
GenerateToken generates a jwt token with the given uid and options.
func InitAuth ¶
func InitAuth(signingKey []byte, expire time.Duration, opts ...InitAuthOption)
InitAuth initializes jwt options.
func ParseToken ¶
ParseToken parses the given token and returns the claims.
Types ¶
type AuthOption ¶
type AuthOption func(*authOptions)
AuthOption set the auth options.
func WithExtraVerify ¶
func WithExtraVerify(fn ExtraVerifyFn) AuthOption
WithExtraVerify set extra verify function
func WithReturnErrReason ¶
func WithReturnErrReason() AuthOption
WithReturnErrReason set return error reason
type ExtraVerifyFn ¶
ExtraVerifyFn extra verify function
type GenerateTokenOption ¶
type GenerateTokenOption func(*generateTokenOptions)
GenerateTokenOption set the jwt options.
func WithGenerateTokenFields ¶
func WithGenerateTokenFields(fields map[string]interface{}) GenerateTokenOption
WithGenerateTokenFields set custom fields value
type InitAuthOption ¶
type InitAuthOption func(*initAuthOptions)
InitAuthOption set the jwt initAuthOptions.
func WithInitAuthIssuer ¶
func WithInitAuthIssuer(issuer string) InitAuthOption
WithInitAuthIssuer set issuer value
func WithInitAuthSigningMethod ¶
func WithInitAuthSigningMethod(sm *jwt.SigningMethodHMAC) InitAuthOption
WithInitAuthSigningMethod set signing method value
type SigningMethodHMAC ¶
type SigningMethodHMAC = jwt.SigningMethodHMAC