按照本指南所述设置 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/