Passport.js模块,未定义的callbackURL

按照本指南设置Drupal后: Drupal-passport我创build了一个简单的节点应用程序来testing它的工作原理。

它不,我得到InternalOAuthError: Failed to obtain request token错误。

通过strategy.js ,我看到我的callbackURL注销undefined不完全确定为什么。 callbackURL是在我的Drupal应用程序中设置的

另外curl -i -XPOST http://extranet.local/rest/system/connect/形成一个curl -i -XPOST http://extranet.local/rest/system/connect/给我正是我需要的

这里是我的node.js代码(记住这只是testingdrupal设置)。

 var express = require('express'); var passport = require('passport'); var dStrategy = require('passport-drupal').DrupalStrategy; var passportDrupal = require('passport-drupal'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser') var session = require('express-session'); var http = require('http'); var app = express(); var server = http.createServer(app); app.use(cookieParser()); app.use(bodyParser()); app.use(session({ secret: 'SECRET' })); app.use(passport.initialize()); app.use(passport.session()); passport.use(new dStrategy({ consumerKey: "emDVp7P2LZFLPcN3cNCjLmrjrhQLnNv6", consumerSecret: "mkbc3UYEuUQLNQRwLWo3B8zEk4ZrErKa", providerURL: "http://extranet.local", resourceEndpoint: "rest/system/connect", // <---- optional. Defaults to `rest/system/connect` callbackURL: 'http://33.33.33.40:8888/auth/drupal/callback' }, function(token, tokenSecret, profile, done) { profile.oauth = { token: token, token_secret: tokenSecret }; done(null, profile); } )); app.get('/', function(req, res) { res.writeHead(200); res.end("This is root"); }); app.get('/auth/drupal', passport.authenticate('drupal'), function(req, res) { // The request will be redirected to the Drupal website for // authentication, so this function will not be called. }); app.get('/auth/drupal/callback', passport.authenticate('drupal', { failureRedirect: '/error' }), function(req, res) { // Successful authentication, redirect home. res.redirect('/signedin'); }); app.get('/error', function(req, res) { res.writeHead(200); res.end("Could not sign in"); }); app.get('/signedin', function(req, res) { res.writeHead(200); res.end("signed in"); }); server.listen(8888, '33.33.33.40'); 

任何线索,为什么或想法,不胜感激

       

网上收集的解决方案 "Passport.js模块,未定义的callbackURL"

如果您查看库passport-drupalstrategy.js代码,您将看到DrupalStrategy构造函数不期待options参数对象中的callbackURL属性,也不会将其传递给OAuthStrategy

这是为oauth策略创build参数的代码片段:

  // Determine all necessary OAuth options var oauthOptions = { requestTokenURL: this._providerURL + '/oauth/request_token', accessTokenURL: this._providerURL + '/oauth/access_token', userAuthorizationURL: this._providerURL + '/oauth/authorize', consumerKey: options.consumerKey, consumerSecret: options.consumerSecret }; OAuthStrategy.call(this, oauthOptions, verify); 

它应该被修改为传递callbackURL,例如像这样:

  // Determine all necessary OAuth options var oauthOptions = { requestTokenURL: this._providerURL + '/oauth/request_token', accessTokenURL: this._providerURL + '/oauth/access_token', userAuthorizationURL: this._providerURL + '/oauth/authorize', consumerKey: options.consumerKey, consumerSecret: options.consumerSecret, callbackURL: options.callbackURL// <==== THIS LINE WAS ADDED }; OAuthStrategy.call(this, oauthOptions, verify); 

我不确定那会解决你的问题。 但是我提出了一个请求