Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Passport.js and
* Example for authenticationg against the Public API with
* passport.js and retrieving the authenticated orcid.
* The main difficulty is that will send the authenticated orcid
* in the accessToken request, which is normally not passed on to the
* passport.js-callback. Without the orcid, properly authenticating with
* is impossible though.
* The trick is to pass on the `passReqToCallback`-option to the
* OAuth2Strategy, so that the callback will receive the complete content of
* the accessToken request. We can then use a callback function with the
* signature `(req, accessToken, refreshToken, params, profile, cb)`, where
* the parameter `params` will contain the JSON-parsed values of the
* accessToken answer. The orcid can then be accessed via `params.orcid`.
const passport = require('passport');
const OAuth2Strategy = require('passport-oauth2').Strategy;
const orcid = new OAuth2Strategy(
{ // Configure your OAuth2Stragey as usual, but set `passReqToCallback`
passReqToCallback : true
(req, accessToken, refreshToken, params, profile, cb) => {
// You can now access the orcid and the name of the authenticated user
// in your passport callback and e.g. save it to your database for
// further use.
* The remaining code would just be your usual passport.js configuration.

This comment has been minimized.

Copy link

@nuest nuest commented Aug 8, 2016

The complete application this configuration was originally developed for is

Further comments pointing to other implementations using this approach are very welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment