我正在使用oauth2orize和passport在nodejs中创建一个API,但是当我要求令牌时,client_id参数是未定义的。
Oauth2orize:
server.exchange(oauth2orize.exchange.password(function (client, username, password, scope, callback) {
console.log(client); // This is undefined
发表:
grant_type: password,
client: id_client, // I tried with client_id, clientId, id...
username: username,
password: password
为什么客户端参数未定义?
非常感谢
答案 0 :(得分:0)
您需要创建至少一个这样的Passport策略:
var passport = require('passport'),
ClientPasswordStrategy = require('passport-oauth2-client-password').Strategy ;
passport.use("clientPassword", new ClientPasswordStrategy(
function (clientId, clientSecret, done) {
Clients.findOne({clientId: clientId}, function (err, client) {
if (err) return done(err)
if (!client) return done(null, false)
if (!client.trustedClient) return done(null, false)
if (client.clientSecret == clientSecret) return done(null, client)
else return done(null, false)
});
}
));
然后你需要绑定你的路线,以便你的请求将通过这个策略:(带快递)
app.post('/url', passport.authenticate('clientPassword'), server.token());
最后,要请求您的令牌,POST参数必须是: