NPM授予OAuth中间件"invalid_redirect"错误 [英] NPM Grant OAuth Middleware "invalid_redirect" error
问题描述
我一直在尝试使用这个优雅的程序包来通过Jawbone API进行身份验证.但我不断收到此错误-
我已使用Jawbone API服务配置应用"以使用这些重定向URI-
我的配置文件如下所示-
module.exports = {
'server': {
'protocol' : 'https',
'host' : 'localhost',
'port' : 5000,
'callback' : '/done',
'transport' : 'session',
'state' : true
},
'jawbone' : {
'key' : '6f*********',
'secret' : '9b************************',
'callback' : '/connect/jawbone/callback',
'scope' : ['basic_read', 'sleep_read'],
}
}
如上面注释中所述,您的配置应如下所示:
{
'server': {
'protocol' : 'https',
'host' : 'localhost:5000',
'transport' : 'session',
'state' : true
},
'jawbone' : {
'key' : '6f*********',
'secret' : '9b************************',
'callback' : '/handle_jawbone_callback',
'scope' : ['basic_read', 'sleep_read'],
}
}
当前没有单独的port
选项,因此,如果您的应用程序顶部没有某种虚拟主机,则应将端口号附加到host
值-host:'localhost:5000
./p>
对于callback
键,您应该始终在服务器上设置要从OAuth流接收结果的路径.您为OAuth应用程序的redirect_uri
指定的/connect/jawbone/callback
路由是为Grant保留的,因此您不能直接使用该路由.
例如,您可以这样设置最终路线:callback:'/handle_jawbone_callback'
.
所有这些都记录在模块的自述文件中.
I have been trying to use this elegant looking package to authenticate with Jawbone API. But I keep getting this error -
I have configured my "app" with the Jawbone API service to use these Redirect URIs -
My config file looks like this -
module.exports = {
'server': {
'protocol' : 'https',
'host' : 'localhost',
'port' : 5000,
'callback' : '/done',
'transport' : 'session',
'state' : true
},
'jawbone' : {
'key' : '6f*********',
'secret' : '9b************************',
'callback' : '/connect/jawbone/callback',
'scope' : ['basic_read', 'sleep_read'],
}
}
I've tried to follow the authors examples to produce an app.js like this -
var config = require('./config');
var express = require('express');
var session = require('express-session');
var Grant = require('grant-express');
var grant = new Grant(require('./config.js'));
var bodyParser = require('body-parser')
var app = express()
var Purest = require('purest');
var jawbone = new Purest({provider:'jawbone'});
var https = require('https');
var fs = require('fs');
var logger = require('morgan')
app.use(logger('dev'))
app.use(bodyParser.urlencoded({extended:true}));
app.use(session({secret:'grant'}));
app.use(grant);
app.get('/done', function (req, res) {
console.log(req.query);
res.end(JSON.stringify(req.query, null, 2));
});
/*
jawbone.get('users/@me', {
auth:{bearer:'[ACCESS_TOKEN]'}
}, function (err, res, body) {
// body is a parsed JSON object containing the response data
console.log(body);
})
*/
var sslOptions = {
key: fs.readFileSync('./.server.key'),
cert: fs.readFileSync('./.server.crt')
};
var secureServer = https.createServer(sslOptions, app).listen(config.server.port, function(){
console.log('Listening on port ' + config.server.port);
});
I assume I'm making a noob-error and probably misreading the documentation or examples. Can someone point out what I have misconfigured?
As noted in the comments above your configuration should look like this:
{
'server': {
'protocol' : 'https',
'host' : 'localhost:5000',
'transport' : 'session',
'state' : true
},
'jawbone' : {
'key' : '6f*********',
'secret' : '9b************************',
'callback' : '/handle_jawbone_callback',
'scope' : ['basic_read', 'sleep_read'],
}
}
Currently there is no separate port
option, so in case you don't have some sort of virtual host on top of your app, you should append the port number to the host
value - host:'localhost:5000
.
For callback
key you should always set the path on your server where you want to receive the results from the OAuth flow. The /connect/jawbone/callback
route that you specify for redirect_uri
of your OAuth application is reserved for Grant, so you can't use that route directly.
For example you can set the final route like this: callback:'/handle_jawbone_callback'
.
All of this is documented in the module's readme file as well.
这篇关于NPM授予OAuth中间件"invalid_redirect"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!