[英]client_id undefinded on grant_type=password (oauth2orize)
I am creating an API in nodejs with oauth2orize and passport, but when I ask for the token, the client_id parameter is undefined. 我正在使用oauth2orize和护照在nodejs中创建一个API,但是当我请求令牌时,client_id参数是未定义的。
Oauth2orize: Oauth2orize:
server.exchange(oauth2orize.exchange.password(function (client, username, password, scope, callback) {
console.log(client); // This is undefined
Post: 帖子:
grant_type: password,
client: id_client, // I tried with client_id, clientId, id...
username: username,
password: password
Why is the client parameter is undefined? 为什么客户端参数未定义?
Thanks a lot 非常感谢
You need to create at least one Passport Strategy like this : 您需要至少创建一个这样的护照策略:
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)
});
}
));
Then you need to bind your route so that your request will pass threw this Strategy : (with express) 然后,您需要绑定您的路线,以便您的请求能够通过该策略:
app.post('/url', passport.authenticate('clientPassword'), server.token());
Finally, to request your token, the POST parameters must be : 最后,要请求您的令牌,POST参数必须为:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.