Documentation ¶
Index ¶
- Constants
- Variables
- type AuthBearer
- type JWTData
- type Option
- func WithAuthErrFn(fn func(err error) string) Option
- func WithAuthOkFn(fn func(token string) string) Option
- func WithAutoKeepAlive(on bool) Option
- func WithSecret(secret []byte) Option
- func WithTTL(ttl time.Duration) Option
- func WithUser(name, pwd string) Option
- func WithUserList(users map[string]string) Option
- type User
Constants ¶
View Source
const ( DefaultHeadersAuthField = "Authorization" DefaultTokenPrefix = "Bearer " )
Variables ¶
View Source
var ( DefaultSecret = []byte("zauth-bearer_secret") DefaultTTL time.Duration = 600e9 )
View Source
var ( DefaultJWTAlgorithm = jwt.SigningMethodHS512 DefaultJWTAlgorithmName = "HS512" )
Functions ¶
This section is empty.
Types ¶
type AuthBearer ¶
type AuthBearer struct {
// contains filtered or unexported fields
}
func New ¶
func New(opts ...Option) *AuthBearer
func (*AuthBearer) Authentication ¶
func (m *AuthBearer) Authentication() func(iris.Context)
认证, 它返回一个iris的Handler
客户端需要传入一个 json 格式的 body 用于验证, 如: {"user":"username","pwd":"youpassword"} 一旦认证通过, 会生成一个认证信息头并返回给客户端, 如: Authorization: Bearer token
func (*AuthBearer) MustAuth ¶
func (m *AuthBearer) MustAuth() func(iris.Context)
鉴权, 它返回一个iris的中间件用于要求用户必须登录
客户端必须将鉴权信息放在 header 的 Authorization 字段中 如 Authorization: Bearer token 如果鉴权成功, 会生成一个新的认证信息头并返回给客户端, 如: Authorization: Bearer token
type JWTData ¶
type JWTData struct { jwt.StandardClaims User string `json:"user"` }
func (*JWTData) ParserString ¶
解析jwt数据
type Option ¶
type Option func(a *AuthBearer)
Click to show internal directories.
Click to hide internal directories.