gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 00:43:53 24 4
gpt4 key购买 nike

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

没有,我得到了 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');

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

最佳答案

如果您查看 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com