Skip to content

Instantly share code, notes, and snippets.

@DSDevCenter
Created February 19, 2018 21:44
Show Gist options
  • Save DSDevCenter/c8a77fbf86b4a17c0bf8a7e6dfaf8a03 to your computer and use it in GitHub Desktop.
Save DSDevCenter/c8a77fbf86b4a17c0bf8a7e6dfaf8a03 to your computer and use it in GitHub Desktop.
DocuSign NODE SDK Example - Get OAuth access token
// Configure Passport
passport.use(new docusign.OAuthClient({
sandbox: true,
clientID: '{CLIENT_ID}',
clientSecret: '{CLIENT_SECRET}',
callbackURL: hostUrl + '/auth/callback'
},
function (accessToken, refreshToken, user, done) {
// Here we're just assigning the tokens to the user profile object but we
// could be using session storage or any other form of transient-ish storage
user.accessToken = accessToken;
user.refreshToken = refreshToken;
return done(null, user);
}
));
app.get('/auth', function (req, res) {
passport.authenticate('docusign'/*, {state: 'optional state'}*/)(req, res);
});
app.get('/auth/callback', function (req, res) {
passport.authenticate('docusign'/*, {state: 'optional state'}*/, function (err, user) {
if (err) {
return res.send(err);
}
if (!user) {
return res.redirect('/auth');
}
// getting the API client ready
var apiClient = new docusign.ApiClient();
// currently pointing to demo (sandbox) environment
var RestApiUrl = 'https://demo.docusign.net/restapi';
apiClient.setBasePath(RestApiUrl);
apiClient.addDefaultHeader('Authorization', 'Bearer ' + user.accessToken);
console.log("API Client configured with new access_token!");
})(req, res);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment