0
votes

Trying to create a demo using passport-wordpress https://www.npmjs.org/package/passport-wordpress

passport-wordpress allows you to login to a node.js app using your credentials at wordpress.com

I set up my Wordpress app at developer.wordpress.com/apps:

OAuth Information
Client ID <removed>
Client Secret <removed>
Redirect URL  http://greendept.com/wp-pass/
Javascript Origins    http://wp-node2.herokuapp.com
Type  Web
Request token URL https://public-api.wordpress.com/oauth2/token
Authorize URL https://public-api.wordpress.com/oauth2/authorize
Authenticate URL  https://public-api.wordpress.com/oauth2/authenticate

In my node.js app:

    var CLIENT_ID = <removed>;
    var CLIENT_SECRET = <removed>;
    passport.use(new WordpressStrategy({
    clientID: CLIENT_ID,
    clientSecret: CLIENT_SECRET
  },
  function(accessToken, refreshToken, profile, done) {
    User.findOrCreate({ WordpressId: profile.id }, function (err, user) {
      return done(err, user);
    });
  }

When I try to authorize, it goes to this URL (as one line, I've divided into two here for readability):

https://public-api.wordpress.com/oauth2/authorize?

response_type=code&redirect_uri=&client_id= removed

I can see that the redirect_uri is missing in that URL, so it's not surprising that I get this error:

Invalid request, please go back and try again.

Error Code: invalid_request

Error Message: The required "redirect_uri" parameter is missing.

Not sure where or how in my code I should be submitting the redirect_uri.

1

1 Answers

1
votes

You need to pass a callback url as option.

From passport-wordpress

The strategy requires a verify callback, which accepts these credentials and 
calls done providing a user, as well as options specifying a client ID, 
client secret, and callback URL.

And from lib/strategy.js

Examples:

  passport.use(new WordpressStrategy({
      clientID: '123-456-789',
      clientSecret: 'shhh-its-a-secret',
      callbackURL: 'https://www.example.net/auth/wordpress/callback'
    },
    function(accessToken, refreshToken, profile, done) {
      User.findOrCreate(..., function (err, user) {
        done(err, user);
      });
    }
  ));