gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 03:21:10 31 4
gpt4 key购买 nike

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

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

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)

以及一个我在其中提到策略的 Controller 文件

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 文件并从 Controller 文件中删除了策略

我将策略放在 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 。问题是一个拼写错误,需要传回有关成功授权的更多信息。

关于javascript - 未知的身份验证策略 : hapi-auth-bearer-simple,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46570129/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com