auth

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package auth encrypt and compare password string.

Index

Constants

This section is empty.

Variables

View Source
var (
	TokenExpired     = errors.New("Token is expired")
	TokenNotValidYet = errors.New("Token not active yet")
	TokenMalformed   = errors.New("That's not even a token")
	TokenInvalid     = errors.New("Couldn't handle this token:")
)

Functions

func Compare

func Compare(hashedPassword, password string) error

Compare compares the encrypted text with the plain text if it's the same.

func Encrypt

func Encrypt(source string) (string, error)

Encrypt encrypts the plain text with bcrypt.

func JWTAuth added in v0.0.2

func JWTAuth(signKey string) gin.HandlerFunc

func Sign

func Sign(secretID string, secretKey string, iss, aud string) string

Sign issue a jwt token based on secretID, secretKey, iss and aud.

Types

type CustomClaims added in v0.0.2

type CustomClaims struct {
	ID          uint `json:"userid"`
	NickName    string
	AuthorityId uint
	jwt.StandardClaims
}

type JWT added in v0.0.2

type JWT struct {
	SigningKey []byte
}

func NewJWT added in v0.0.2

func NewJWT(sign string) *JWT

func (*JWT) CreateToken added in v0.0.2

func (j *JWT) CreateToken(claims CustomClaims) (string, error)

创建一个token

func (*JWT) ParseToken added in v0.0.2

func (j *JWT) ParseToken(tokenString string) (*CustomClaims, error)

解析 token

func (*JWT) RefreshToken added in v0.0.2

func (j *JWT) RefreshToken(tokenString string) (string, error)

更新token

Jump to

Keyboard shortcuts

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