jaredhanson / passport-oauth2

OAuth 2.0 authentication strategy for Passport and Node.js.
https://www.passportjs.org/packages/passport-oauth2/?utm_source=github&utm_medium=referral&utm_campaign=passport-oauth2&utm_content=about
MIT License
607 stars 343 forks source link

Callback not working #103

Open JMedina90 opened 6 years ago

JMedina90 commented 6 years ago

I'm trying to get an authorization code from eBay with passportjs-oauth2, but passport its not returning any data.

passport-config.js

const passport = require("passport");
const OAuth2Strategy = require("passport-oauth2").Strategy;

var authStrategy = new OAuth2Strategy(
{
    authorizationURL: "https://auth.sandbox.ebay.com/oauth2/authorize?",
    tokenURL: "https://api.sandbox.ebay.com/identity/v1/oauth2/token",
    clientID: "client-id"
},
function(accessToken, refreshToken, profile, cb) {
    console.log("Here!");
    console.log(accessToken);
    console.log(refreshToken);
    console.log(profile);
    cb(null, profile);
}
);

authStrategy.authorizationParams = function() {
return {
    redirect_uri: "redirect-uri",
    response_type: "code"
};
};

auth-route.js:

router.get("/redirect", passport.authenticate("ebay"), function(req, res) {
console.log("ebay");
console.log(req.params);
res.redirect("/");
});

And I get the following error: "request is missing a required parameter or malformed."

Any ideas? Edit: The URL does return the code I'm trying to get.

YasharF commented 5 years ago

You are missing a bunch of stuff in

OAuth2Strategy(
{
    authorizationURL: "https://auth.sandbox.ebay.com/oauth2/authorize?",
    tokenURL: "https://api.sandbox.ebay.com/identity/v1/oauth2/token",
    clientID: "client-id"
},

See https://github.com/sahat/hackathon-starter/blob/master/config/passport.js#L484 for a working example