javascript - Passport.js 模块,未定义callbackURL

标签 javascript node.js drupal-7 passport.js

按照本指南所述设置 Drupal 后:Drupal-passport我创建了一个简单的 Node 应用程序来测试它的工作原理。

事实并非如此,我收到 InternalOAuthError: 无法获取请求 token 错误。

浏览strategy.js,我发现我的callbackURL正在注销undefined,但不知道为什么。 callbackURL 在我的 Drupal 应用程序中设置

还执行curl -i -XPOST http://extranet.local/rest/system/connect/给了我我所需要的

这是我的 node.js 代码(请记住,这只是为了测试 drupal 设置)。

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');

任何有关原因或想法的线索都将不胜感激

最佳答案

如果你查看strategy.js图书馆代码passport-drupal ,您将看到 DrupalStrategy 构造函数不需要选项参数对象中的 callbackURL 属性,并且它也不会将其进一步传递到 OAuthStrategy >.

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

  // 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);

但我不确定这是否能解决您的问题。但我做了一个pull request

关于javascript - Passport.js 模块,未定义callbackURL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25386965/

相关文章:

德鲁帕尔 7 : add 'updated by ' to admin content

facebook - 如何使用 Node.js 发布到 facebook 服务器端

drupal - 如何在不带面板的 View Drupal 7 中获取组 ID 作为上下文

php - 德鲁巴 : Override Megamenu module function

javascript - 将 XSL 字符串传递给 Javascript

javascript - 在 Electron 中单击按钮重新打开 BrowserWindow 后对象已被销毁异常

json - 从 Node.js 中的 TCP 套接字读取字符串时出现问题

javascript - document.getElementsByClassName - 跨浏览器修复

php - 不提醒从 onclick php 函数传递的变量值

javascript - 在 React 中使用内联样式对象与使用普通 css 类