auth

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: MIT Imports: 23 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 {
		Kid string `yaml:"kid"`
	} `yaml:"header"`
	Claims struct {
		ExpDuration time.Duration `yaml:"exp"`
	} `yaml:"claims"`
	RefreshSecret string `yaml:"refresh_secret"`
	// 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) GetTokenWithRefresh

func (j *JwtConf) GetTokenWithRefresh(host string, data map[string]interface{}, exp uint8) (*token, 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)

func (*JwtConf) RefreshAccessToken

func (j *JwtConf) RefreshAccessToken(refreshToken string) (*string, 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)
	GetTokenWithRefresh(host string, data map[string]interface{}, exp uint8) (*token, 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)
	RefreshAccessToken(refreshToken string) (*string, error)
}

type ReqUser

type ReqUser interface {
	GetHost() string
	GetPerms() []string
	GetId() string
	GetAccount() string
	GetName() string
	GetUsage() 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, usage 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