auth

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSupported = errors.New("not supported")

Functions

func AuthMiddlewareFunc added in v0.1.6

func AuthMiddlewareFunc(af AuthFunc) iris.Handler

如果授权函数返回有效的用户, 则设置到ctx.User()中 如果授权还是没提供或者没有返回有效用户, 则设置一个空的用户到ctx.User()中 空的User默认为未授权状态

func LoginRequire added in v0.1.9

func LoginRequire(ctx iris.Context)

登录请求中间件

Types

type AuthFunc added in v0.1.6

type AuthFunc = func(ctx iris.Context) *User

type IModel added in v0.2.0

type IModel interface {
	GetID() string
}

数据库model, 用来存储动态数据

type User

type User struct {
	Model        IModel `json:"fields,omitempty"` // User Model
	Id           string `json:"id"`
	Username     string `json:"username"`
	Phone        string `json:"phone"`
	IsAuthorized bool   `json:"is_authorized"`
}

实现 iris 的 User 接口: https://github.com/kataras/iris/blob/master/context/context_user.go

func GetUser added in v0.1.6

func GetUser(ctx iris.Context) *User

* 获取系统用户

func NewUser

func NewUser(id string, phone string, username string, isAuthorized bool, um IModel) *User

新建用户

func UserIDAuth

func UserIDAuth(ctx iris.Context) *User

默认提供授权函数

func (*User) GetAuthorization

func (u *User) GetAuthorization() (string, error)

GetAuthorization should return the authorization method, e.g. Basic Authentication.

func (*User) GetAuthorizedAt

func (u *User) GetAuthorizedAt() (time.Time, error)

func (*User) GetEmail

func (u *User) GetEmail() (string, error)

func (*User) GetField

func (u *User) GetField(key string) (interface{}, error)

func (*User) GetID

func (u *User) GetID() (string, error)

func (*User) GetModel added in v0.2.0

func (u *User) GetModel() IModel

获取 UserModel

func (*User) GetPassword

func (u *User) GetPassword() (string, error)

func (*User) GetRaw

func (u *User) GetRaw() (interface{}, error)

GetRaw should return the raw instance of the user, if supported.

func (*User) GetRoles

func (u *User) GetRoles() ([]string, error)

func (*User) GetToken

func (u *User) GetToken() ([]byte, error)

func (*User) GetUsername

func (u *User) GetUsername() (string, error)

func (*User) SetModel added in v0.2.0

func (u *User) SetModel(au IModel)

设置用户 UserModel

Jump to

Keyboard shortcuts

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