【发布时间】:2016-11-28 14:57:36
【问题描述】:
我们正在使用 hapijs 和 oauth 服务器进行身份验证。我们需要在 hapijs 中实现基于角色的授权。下面的方式对 hapijs 来说很好。
-
注册认证方案
server.auth.scheme('custom', function (server, options) { return { authenticate: function (request, reply) { // calling oauth flow for roles match } }); -
在server.route中注册认证策略并添加auth、roles
server.auth.strategy('default', 'custom'); server.route({ method: 'GET', path: API_Path, config: { roles: ['ADMIN', 'USER'], auth : 'default' }, handler: function (request, reply) { return reply.act({ role: 'admin', cmd: 'getInfo', id: request.params.id }); } });
【问题讨论】:
标签: oauth-2.0 authorization hapijs