Constructor
new RBACAuth(options)
- Source:
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | 鉴权失败的配置参数对象
Properties
|
Members
authenticationBody :object
- Source:
- Default Value:
- {code: 401,msg: 'unauthorized'}
认证失败的响应体JSON
Type:
- object
authenticationFailedUrl :string
- Source:
认证失败的跳转地址
Type:
- string
authorizationFailedBody :object
- Source:
- Default Value:
- {code: 401,msg: 'unauthorized'}
授权失败的响应体JSON
Type:
- object
authorizationFailedCode :number
- Source:
- Default Value:
- 401
授权失败的 HTTP 状态码
Type:
- number
Methods
(async) authenticationFailed(ctx)
- Source:
未认证的处理逻辑
Parameters:
Name | Type | Description |
---|---|---|
ctx |
object | egg的ctx |
(async) authorizationFailed(ctx)
- Source:
未授权的处理逻辑
Parameters:
Name | Type | Description |
---|---|---|
ctx |
object | egg的ctx |
checkLogin() → {middleWare}
- Source:
检查当前会话的用户是否登录(认证成功与否)
Example
rbac.checkLogin()
Returns:
中间件异步函数
- Type
- middleWare
checkPermissions(permissions) → {middleWare}
- Source:
检查当前会话的用户是否拥有指定权限
Example
rbac.checkPermissions(['admin:user'])
Parameters:
Name | Type | Description |
---|---|---|
permissions |
array.<string> | 权限名称集合 |
Returns:
中间件异步函数
- Type
- middleWare
checkRoles(roleNames) → {middleWare}
- Source:
检查当前会话的用户是否拥有指定角色
Example
rbac.checkRoles(['admin'])
Parameters:
Name | Type | Description |
---|---|---|
roleNames |
array.<string> | 角色名称集合 |
Returns:
中间件异步函数
- Type
- middleWare