1
我们使用hapijs和oauth服务器进行身份验证。我们需要在hapijs中实施基于角色的授权。以下方式对hapijs来说不错。使用Hapijs和oauth 2的API授权流程
注册认证方案
server.auth.scheme('custom', function (server, options) { return { authenticate: function (request, reply) { // calling oauth flow for roles match } });
注册认证策略&添加auth,在server.route角色
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 }); } });