未知身份验证策略:hapi-auth-bearer-simple

Unknown authentication strategy: hapi-auth-bearer-simple

我正在尝试使用 hapi-auth-bearer-simple 模块在我的应用程序上启用不记名令牌。但是,我收到标题中显示的错误。

我正在尝试实现此模块以在我的应用程序中启用令牌授权但是我收到下面提到的错误

e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\node_modules\hoek\lib\index.js:723

我有一个路由文件

module.exports = [
    {
        method: 'GET',
        path: '/api/{_id?}',
        handler: function (request, reply) {
           Controller.control.get(request.params, function (err, success) {
                console.log(request.params);
                if (err) {  
                    reply(unifunc.sendError(err));
                } else {
                    reply(unifunc.sendSuccess(SuccessMsg,success)).code(200);
                }
            });
        },
        config: {
            description: 'desc',
            tags: ['api', 'oV'],
            validate: {
                headers: unifunc.authorizationHeaderObj,
                params: {
                    o_id: Joi.string().required().trim(),
                    _id: Joi.string().optional().trim()
                },
                failAction: unifunc.failActionFunction
            },
            auth: {
                strategy: 'bearer',
                scope: ['admin', 'user-{params.id}']
                },
            plugins: {
                'hapi-swagger': {
                    responseMessages: msgs
                }](url)

以及我在其中提到策略的控制器文件

var bearerSimple= require('hapi-auth-bearer-simple')
authorization = Authorization.auth; // This plugin has the logic to validate the token and return the error in case it fails and I am passing accesstoken as parameter in a function in that file
var getV = function(server, params, callbackRoute){  
    server.register(
        [{
            register: bearerSimple
        }], function(err){
     if(err){
         console.log("Failed to log the plugin",err);
         throw err;
     }
     server.auth.strategy('bearer', 'bearerAuth', {
        authorization : authorization
     });
    });
    console.log(params);
    async.series([
        function(cb){}
        ]}

完整的错误信息是:

Error: Unknown authentication strategy: bearer in path: /api/orders/{order_id}/vehicles/{_id?}
    at Object.exports.assert (e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\node_modules\hoek\lib\index.js:723:11)
    at e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\lib\auth.js:152:14
    at Array.forEach (native)
    at internals.Auth._setupRoute (e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\lib\auth.js:149:24)
    at new module.exports.internals.Route (e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\lib\route.js:142:47)
    at internals.Connection._addRoute (e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\lib\connection.js:375:17)
    at internals.Connection._route (e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\lib\connection.js:367:18)
    at wrappedRoute [as _route] (e:\python_training\Training\Node\Test\Project\Backend\node_modules\newrelic\lib\instrumentation\hapi.js:222:29)
    at internals.Plugin._apply (e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\lib\plugin.js:460:14)
    at internals.Plugin.route 

有什么办法可以解决这个问题吗?

编辑:
我修改了 server.js 文件并从控制器文件

中删除了策略

我把攻略放在了server.js

var validationFunction = Authorization.auth;
console.log(validationFunction);

server.register(
    [{
        register: bearerSimple
    }], function(err){
 if(err){
     console.log("Failed to log the plugin",err);
     throw err;
 }

 server.auth.strategy('bearer', 'bearerAuth', {
    validationFunction : validationFunction
 });
});

授权文件看起来像这样

function rauth(accessToken, cb) {
    var criteria = {accessToken: accessToken};
    var projection = {};
    var options = {limit: 1};
    Service.AdminService.getadmin(criteria, projection, options, function (err, data) {
        if (err) {
            cb(err);
        } else if (data && data.length > 0 && data[0]._id) {
            console.log(data);
            console.log(data.length);
            adminId = data[0]._id;
            cb()
        } else {
            cb(UniversalFunctions.CONFIG.APP_CONSTANTS.STATUS_MSG.ERROR.INVALID_ACCESS_TOKEN);
        }
    });

现在我收到这个错误:

Error: options.validateFunc must be a valid function in bearerAuthentication scheme

几天来我一直在为这个问题绞尽脑汁。谁能建议这里可能是什么问题?

我发现的唯一问题是在 validateFunction 中传递的回调函数的参数,但我无法删除这些参数,因为这些参数是在另一个名为 getadmin 的函数中定义的。有人可以为此提出解决方法吗?

已解决此问题 https://github.com/Salesflare/hapi-auth-bearer-simple/issues/69。 问题是打字错误,需要在成功授权时传回更多信息。