Take a look at passportjs which is an authentication module for node.js which provides different authentication strategies (as of today more than 140). Fortunately there is a OAuth 2 stategy for authenticating against wordpress. The github page of this strategy is located here.
Both, passport and the passport-wordpress, can be installed via npm package manager. Afterwards, you could authenticate every request for example with passport.authorize() route-middleware method if your node application is an express.js application. From the docs of passport-wordpress:
Define the strategy.
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);
});
}
));
Using the strategy via passport.authorize in your routes (example for expressjs):
app.get('/auth/wordpress',
passport.authorize('wordpress'));
app.get('/auth/wordpress/callback',
passport.authorize('wordpress', { failureRedirect: '/login' }),
function(req, res) {
// Successful authentication, redirect home.
res.redirect('/');
});
If you're not using expressjs or don't want to use passportjs, please provide some more information how your wordpress installation and your node.js application is working together and what kind of frameworks you're using on the node.js side.