Documentation ¶
Index ¶
- Constants
- Variables
- func AuthMiddlewareFunc(af AuthFunc) iris.Handler
- func LoginRequire(ctx iris.Context)
- type AuthFunc
- type IModel
- type User
- func (u *User) GetAuthorization() (string, error)
- func (u *User) GetAuthorizedAt() (time.Time, error)
- func (u *User) GetEmail() (string, error)
- func (u *User) GetField(key string) (interface{}, error)
- func (u *User) GetID() (string, error)
- func (u *User) GetModel() IModel
- func (u *User) GetPassword() (string, error)
- func (u *User) GetRaw() (interface{}, error)
- func (u *User) GetRoles() ([]string, error)
- func (u *User) GetToken() ([]byte, error)
- func (u *User) GetUsername() (string, error)
- func (u *User) SetModel(au IModel)
Constants ¶
View Source
const ( // DefaultAuthKey is the default key for the token in the request header. DefaultAuthKey = "X-Jwt-Payload" DefaultAuthPayloadKey = "AUTH_PAYLOAD" )
Variables ¶
View Source
var ErrNotSupported = errors.New("not supported")
Functions ¶
func AuthMiddlewareFunc ¶
func AuthMiddlewareFunc(af AuthFunc) iris.Handler
如果授权函数返回有效的用户, 则设置到ctx.User()中 如果授权还是没提供或者没有返回有效用户, 则设置一个空的用户到ctx.User()中 空的User默认为未授权状态
Types ¶
type User ¶
type User struct { UserModel IModel `json:"user_model,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 (*User) GetAuthorization ¶
GetAuthorization should return the authorization method, e.g. Basic Authentication.
func (*User) GetPassword ¶
func (*User) GetUsername ¶
Click to show internal directories.
Click to hide internal directories.