【问题标题】:Passport.js Module, undefined callbackURLPassport.js 模块,未定义的 callbackURL
【发布时间】:2014-08-19 15:09:39
【问题描述】:

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

没有,我收到InternalOAuthError: Failed to obtain request 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');

非常感谢任何关于原因或想法的线索

【问题讨论】:

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


    【解决方案1】:

    如果查看库passport-drupalstrategy.js 代码,您将看到DrupalStrategy 构造函数不期望选项参数对象中的callbackURL 属性,并且它也没有将其进一步传递给OAuthStrategy

    这是为 oauth 策略创建参数的代码 sn-p:

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

    【讨论】:

    • 谢谢,我最终创建了一个问题。
    • 你说得对。我要请他修改他的文档。缺少很多东西。
    猜你喜欢
    • 2021-04-22
    • 2015-07-18
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    • 2018-10-09
    • 2015-06-21
    • 2021-01-06
    • 2021-07-17
    相关资源
    最近更新 更多