auth

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: MIT Imports: 20 Imported by: 26

Documentation

Index

Constants

View Source
const (
	// 管理者
	PermAdmin = UserPerm("admin")
	// 會員
	PermMember = UserPerm("member")
	// 擁有
	PermOwner = UserPerm("owner")
	// 編輯
	PermEditor = UserPerm("editor")
	// 檢視
	PermViewer = UserPerm("viewer")
	// 訪客
	PermGuest = UserPerm("guest")
)
View Source
const (
	CtxUserInfoKey = util.CtxKey("userInfo")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessGuest added in v0.3.0

type AccessGuest interface {
	ReqUser
	GetSource() string
	GetSourceID() string
}

func NewAccessGuest added in v0.3.0

func NewAccessGuest(host, source, sid, acc, name, db string, perm []string) AccessGuest

type CompanyUser added in v0.3.0

type CompanyUser interface {
	ReqUser
	GetCompID() string
	GetComp() string
}

func GetCompUserInfo added in v0.3.0

func GetCompUserInfo(req *http.Request) CompanyUser

func NewCompUser added in v0.3.0

func NewCompUser(host, uid, acc, name, compID, comp string, perm []string) CompanyUser

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) GetCompanyToken

func (j *JwtConf) GetCompanyToken(host, compID, compName, userID, acc, userName string, perm UserPerm) (*string, error)

func (*JwtConf) GetJwtAccessToken

func (j *JwtConf) GetJwtAccessToken(host string, source string, id interface{}, db string, perm UserPerm) (*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) GetTokenWithoutExpired added in v1.1.0

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

func (*JwtConf) NewJwt added in v0.6.5

func (j *JwtConf) NewJwt() JwtToken

func (*JwtConf) ParseToken

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

func (*JwtConf) ParseTokenUnValidate added in v1.3.3

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

type JwtDI

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

type JwtToken

type JwtToken interface {
	GetTokenWithoutExpired(host string, data map[string]interface{}) (*string, error)
	GetToken(host string, data map[string]interface{}, exp uint8) (*string, error)
	ParseToken(tokenStr string) (*jwt.Token, error)
	ParseTokenUnValidate(tokenStr string) (*jwt.Token, error)
	// 對特定資源存取金鑰
	GetJwtAccessToken(host string, source string, id interface{}, db string, perm UserPerm) (*string, error)
	GetCompanyToken(host, compID, compName, userID, acc, userName string, perm UserPerm) (*string, error)
}

type Perms added in v1.1.0

type Perms []string

func (Perms) HasPerm added in v1.1.0

func (p Perms) HasPerm(pp string) bool

type ReqUser added in v0.3.0

type ReqUser interface {
	dao.LogUser
	Host() string
	GetId() string
	GetPerm() []string
	GetDB() string
	Encode() string
	Decode(data string) error
}

func GetUserByGin added in v1.4.0

func GetUserByGin(c *gin.Context) ReqUser

func GetUserInfo added in v0.3.0

func GetUserInfo(req *http.Request) ReqUser

func GetUserInfoByCtx added in v1.0.0

func GetUserInfoByCtx(ctx context.Context) ReqUser

func NewEmptyReqUser added in v1.0.0

func NewEmptyReqUser() ReqUser

func NewGuestUser added in v0.6.0

func NewGuestUser(host, ip string) ReqUser

func NewReqUser added in v0.3.0

func NewReqUser(host, uid, acc, name string, perm []string) ReqUser

type TargetReqUser added in v1.0.0

type TargetReqUser interface {
	ReqUser
	Target() string
}

func GetTargetUserInfo added in v1.0.0

func GetTargetUserInfo(req *http.Request) TargetReqUser

func NewTargetReqUser added in v1.0.0

func NewTargetReqUser(target string, u ReqUser) TargetReqUser

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

type TransmitSecurity

type TransmitSecurity interface {
	GetAuthUrl(redirect string) string
	GetAccessToken(code, redirect string) (string, error)
	GetUserInfo(accessToken string) (string, error)
}

type TransmitSecurityConf

type TransmitSecurityConf struct {
	Host     string
	ClientId string `yaml:"clientId"`
	Secret   string `yaml:"clientSecret"`
}

func (*TransmitSecurityConf) GetAccessToken

func (c *TransmitSecurityConf) GetAccessToken(code, redirect string) (string, error)

func (*TransmitSecurityConf) GetAuthUrl

func (c *TransmitSecurityConf) GetAuthUrl(redirect string) string

func (*TransmitSecurityConf) GetUserInfo

func (c *TransmitSecurityConf) GetUserInfo(accessToken string) (string, error)

type UserPerm

type UserPerm string

func (UserPerm) Validate

func (up UserPerm) Validate() bool

Jump to

Keyboard shortcuts

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