auth

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

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默认为未授权状态

func LoginRequire

func LoginRequire(ctx iris.Context)

登录请求中间件

Types

type AuthFunc

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

type IModel

type IModel interface {
	GetID() string
}

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

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 GetUser

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

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

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