authentication

package
v0.0.0-...-3d9bb29 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicAuthMiddleware

func BasicAuthMiddleware() gin.HandlerFunc

func HashPassword

func HashPassword(password string) (string, error)

func SafeCompareString

func SafeCompareString(a, b string) bool

to prevent time attack

func VerifyPassword

func VerifyPassword(password, hash string) bool

Types

type IJwtAuth

type IJwtAuth interface {
	Sign(userId string, username string) (tokenString string, err error)
	JwtAuthMiddleware() gin.HandlerFunc
}

type JwtAuthImpl

type JwtAuthImpl struct {
	PrivateKey *rsa.PrivateKey
	PublicKey  *rsa.PublicKey
}

func ConstructJwtAuth

func ConstructJwtAuth() (*JwtAuthImpl, error)

Load public-private key pair from env

func (*JwtAuthImpl) JwtAuthMiddleware

func (u *JwtAuthImpl) JwtAuthMiddleware() gin.HandlerFunc

func (*JwtAuthImpl) Sign

func (u *JwtAuthImpl) Sign(userId string, username string) (tokenString string, err error)

Sign will generate new jwt token.

type JwtPayload

type JwtPayload struct {
	jwt.StandardClaims
	Username string `json:"username,omitempty"`
}

func GetJwtUser

func GetJwtUser(c *gin.Context) (user *JwtPayload, err error)

Jump to

Keyboard shortcuts

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