Node.js 授予时客户端id未定义类型=密码(oauth2orize)
我正在nodejs中使用oauth2orize和passport创建一个API,但是当我请求令牌时,client_id参数未定义 Oauth2orize:Node.js 授予时客户端id未定义类型=密码(oauth2orize),node.js,oauth2orize,Node.js,Oauth2orize,我正在nodejs中使用oauth2orize和passport创建一个API,但是当我请求令牌时,client_id参数未定义 Oauth2orize: server.exchange(oauth2orize.exchange.password(function (client, username, password, scope, callback) { console.log(client); // This is undefined 职位: 为什么客户端参数未定义 非常感
server.exchange(oauth2orize.exchange.password(function (client, username, password, scope, callback) {
console.log(client); // This is undefined
职位:
为什么客户端参数未定义
非常感谢您至少需要创建一个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)
});
}
));
然后,您需要绑定您的路由,以便您的请求能够通过以下策略:使用express
app.post('/url', passport.authenticate('clientPassword'), server.token());
最后,要请求令牌,POST参数必须为:
客户识别码
客户机密
用户名
暗语
授权类型:密码
app.post('/url', passport.authenticate('clientPassword'), server.token());