Commit 025b614 1 parent b450b40 commit 025b614 Copy full SHA for 025b614
File tree 1 file changed +9
-5
lines changed
1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -57,23 +57,27 @@ app.use(router.routes(), router.allowedMethods())
57
57
app .listen (3000 )
58
58
```
59
59
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 {
64
67
// override function
65
68
getUserName () {
66
69
const { username } = this .ctx .state .user
67
70
return username
68
71
}
69
72
}
73
+
70
74
app .use (authz ({
71
75
newEnforcer: async () => {
72
76
// load the casbin model and policy from files, database is also supported.
73
77
const enforcer = await Enforcer .newEnforcer (' examples/authz_model.conf' , ' examples/authz_policy.csv' )
74
78
return enforcer
75
79
},
76
- authorizer: (ctx, option) => new CustomizeAuthorizer (ctx, option)
80
+ authorizer : (ctx , option ) => new MyAuthorizer (ctx, option)
77
81
}))
78
82
```
79
83
You can’t perform that action at this time.
0 commit comments