auth

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: MIT Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const (
	BearerAuthTokenKey = "Authorization"
)

Variables

This section is empty.

Functions

func SetReqUserToCtx

func SetReqUserToCtx(ctx context.Context, user ReqUser) context.Context

func SetReqUserToGin

func SetReqUserToGin(c *gin.Context, user ReqUser) *gin.Context

Types

type ApiPerm

type ApiPerm string

type GinAuthMidInter

type GinAuthMidInter interface {
	mid.GinMiddle
	AddAuthPath(path string, method string, isAuth bool, group []ApiPerm)
	IsAuth(path string, method string) bool
	HasPerm(path, method string, perm []string) bool
}

func NewGinBearAuthMid

func NewGinBearAuthMid(isMatchHost bool) GinAuthMidInter

func NewMockAuthMid

func NewMockAuthMid() GinAuthMidInter

type JwtConf

type JwtConf struct {
	PrivateKeyFile string `yaml:"privatekey"`
	PublicKeyFile  string `yaml:"publickey"`
	Header         struct {
		Alg string `yaml:"alg"`
		Typ string `yaml:"typ"`
		Kid string `yaml:"kid"`
	} `yaml:"header"`
	Claims struct {
		ExpDuration time.Duration `yaml:"exp"`
	} `yaml:"claims"`
	// contains filtered or unexported fields
}

func (*JwtConf) GetAccessToken

func (j *JwtConf) GetAccessToken(host string, source string, id interface{}, db string, perm ApiPerm) (*string, error)

func (*JwtConf) GetKid

func (j *JwtConf) GetKid() string

func (*JwtConf) GetToken

func (j *JwtConf) GetToken(host string, data map[string]interface{}, exp uint8) (*string, error)

func (*JwtConf) NewJwt

func (j *JwtConf) NewJwt() JwtToken

func (*JwtConf) ParseToken

func (j *JwtConf) ParseToken(tokenStr string) (*jwt.Token, error)

func (*JwtConf) ParseTokenUnValidate

func (j *JwtConf) ParseTokenUnValidate(tokenStr string) (*jwt.Token, error)

type JwtDI

type JwtDI interface {
	GetKid() string
	NewJwt() JwtToken
}

type JwtToken

type JwtToken interface {
	GetToken(host string, data map[string]interface{}, exp uint8) (*string, error)
	ParseToken(tokenStr string) (*jwt.Token, error)
	ParseTokenUnValidate(tokenStr string) (*jwt.Token, error)
	// 對特定資源存取金鑰
	GetAccessToken(host string, source string, id interface{}, db string, perm ApiPerm) (*string, error)
}

type ReqUser

type ReqUser interface {
	GetHost() string
	GetPerms() []string
	GetId() string
	GetAccount() string
	GetName() string
}

func GetReqUserFromCtx

func GetReqUserFromCtx(ctx context.Context) ReqUser

func GetReqUserFromGin

func GetReqUserFromGin(c *gin.Context) ReqUser

func NewReqUser

func NewReqUser(host string, uid string, account string, name string, roles []string) ReqUser

type Totp

type Totp interface {
	GenerateCode() (string, error)
	ValidateCode(code string) (valid bool, err error)
	WriteQRCode(w io.Writer) error
	ShowInfo() error
}

func NewTotp

func NewTotp(host, account, secret string, PeriodSecs uint) Totp

Jump to

Keyboard shortcuts

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