Reputation: 109
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:
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
Upvotes: 1
Views: 1491
Reputation: 225
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 :
Upvotes: 0