Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何在hapijs中实现oauth2orize_Node.js_Hapijs_Oauth2_Oauth2orize - Fatal编程技术网

Node.js 如何在hapijs中实现oauth2orize

Node.js 如何在hapijs中实现oauth2orize,node.js,hapijs,oauth2,oauth2orize,Node.js,Hapijs,Oauth2,Oauth2orize,我在hapijs中实现了oauth2orize。但是当我调用api时,什么也没有发生。该函数位于oauth2orize模块的code.js文件中,并挂起在两者之间。请建议我如何在hapjs中实现oauth2orize。hapi-oauth2orize也不能作为移民使用&hapi-oauth2orize插件抛出选项错误 const Hapi = require('hapi'); const server = new Hapi.Server(); const oauth2orize = requir

我在hapijs中实现了oauth2orize。但是当我调用api时,什么也没有发生。该函数位于oauth2orize模块的code.js文件中,并挂起在两者之间。请建议我如何在hapjs中实现oauth2orize。hapi-oauth2orize也不能作为移民使用&hapi-oauth2orize插件抛出选项错误

const Hapi = require('hapi');
const server = new Hapi.Server();
const oauth2orize = require('oauth2orize');
var oauth = oauth2orize.createServer();

server.connection({ 
    host: 'localhost', 
    port: 8000 
});

    server.register([{
        register: require('hapi-mongodb'),
        options: dbOpts
    }], function (err) {
        if (err) {
            console.error(err);
            throw err;
        }
        server.start();

        server.route([
                    {
                      method: 'GET',
                      path: '/oauth/authorizegrant',
                      config: {
                        auth: false,
                        handler: function(request, reply) {
                            var clientId = request.query.client_id,
                                redirectUrl = request.query.redirect_uri,
                                resType = request.query.response_type,
                                state = request.query.state;
                            oauth.grant(oauth2orize.grant.code(function(clientId,redirectUrl,resType,state,callback) {
                              // Create a new authorization code
                                  console.log('client', client);
                                  var db = request.server.plugins['hapi-mongodb'].db;
                                  var code = new Code({
                                    value: uid(16),
                                    clientId: client._id,
                                    redirectUri: redirectUri,
                                    userId: user._id
                                  });

                              // Save the auth code and check for errors
                            db.collection('codes').insert(code, function(err) {
                                if (err) { console.log('err*********', err); return callback(err); }

                                callback(null, code.value);
                              });
                            }));

                        }
                      }
                    },
                ]);
    });

您需要更改传递给oauth.grant函数的参数,回调应该被删除并替换为hapi的reply函数。一个简单的片段是

if (err) {
    return reply(err);
}
return reply(code.value);

我会在插件中提出一个问题,因为这是在hapi和oauth2orize之间进行接口的最佳方式。

您需要更改传递给oauth.grant函数的参数,回调应该被删除并替换为hapi的回复函数。一个简单的片段是

if (err) {
    return reply(err);
}
return reply(code.value);

我会在插件中提出一个问题,因为这是连接hapi和oauth2orize的最佳方式。

谢谢回复。我是hapijs和oauth2orize的新手。我按照您的要求编写了代码,但它不起作用。此外,hapi-oauth2orize已经过时,它抛出了一个插件错误。grant(oauth2orize.grant.code(函数(clientId、redirectUrl、resType、state、reply){}移除回调并使用reply在函数体中使用回调的地方,同时在github上为模块提交一个问题。可能是由于编程错误而引发的。您需要编写所有代码吗?我移除了回调,但没有任何效果。耶,我已经提出了它。是的,您已经打开了3个不同的问题,其中的代码是错误的为什么它不工作。但是我实现了与oauth2orize框架中给出的代码相同的代码。谢谢回复。我是hapijs和oauth2orize的新手。我按照您的要求编写了代码,但它不工作。此外,hapi-oauth2orize已经过时,并且它抛出了一个插件错误。oauth.grant(oauth2orize.grant.code)(函数(clientId、重定向URL、重新类型、状态、回复){ }移除回调并使用reply在函数体中使用回调的地方,同时在github上为模块提交一个问题。可能是由于编程错误而引发的。您需要编写所有代码吗?我移除了回调,但没有任何效果。耶,我已经提出了它。是的,您已经打开了3个不同的问题,其中的代码是错误的但是我实现了与oauth2orize框架中给出的代码相同的代码。