Skip to content

Commit 025b614

Browse files
committed
Improve the README about customized authorizer.
1 parent b450b40 commit 025b614

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

README.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,27 @@ app.use(router.routes(), router.allowedMethods())
5757
app.listen(3000)
5858
```
5959

60-
## Customize authorizer
61-
default koa-authz provide BasicAuthorizer, if you want customize just extends BasicAuthorizer
62-
```
63-
class CustomizeAuthorizer extends BasicAuthorizer {
60+
## Use a customized authorizer
61+
62+
This package provides ``BasicAuthorizer``, it uses ``HTTP Basic Authentication`` as the authentication method.
63+
If you want to use another authentication method like OAuth, you needs to extends ``BasicAuthorizer`` as below:
64+
65+
```js
66+
class MyAuthorizer extends BasicAuthorizer {
6467
// override function
6568
getUserName () {
6669
const { username } = this.ctx.state.user
6770
return username
6871
}
6972
}
73+
7074
app.use(authz({
7175
newEnforcer: async () => {
7276
// load the casbin model and policy from files, database is also supported.
7377
const enforcer = await Enforcer.newEnforcer('examples/authz_model.conf', 'examples/authz_policy.csv')
7478
return enforcer
7579
},
76-
authorizer: (ctx, option) => new CustomizeAuthorizer(ctx, option)
80+
authorizer: (ctx, option) => new MyAuthorizer(ctx, option)
7781
}))
7882
```
7983

0 commit comments

Comments
 (0)