Skip to content

Instantly share code, notes, and snippets.

@DSDevCenter
Created February 19, 2018 21:22
Show Gist options
  • Save DSDevCenter/f418ddf8c72f4dacbfe3bc9f22de0637 to your computer and use it in GitHub Desktop.
Save DSDevCenter/f418ddf8c72f4dacbfe3bc9f22de0637 to your computer and use it in GitHub Desktop.
DocuSign NODE SDK Auth Code example for eSignature REST API
const express = require('express');
const passport = require('passport');
const util = require('util')
var session = require('express-session');
var docusign = require('./src/index');
const app = express();
const port = process.env.PORT || 3000;
const host = process.env.HOST || 'localhost';
app.use(session({
secret: 'secret token',
resave: true,
saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());
var hostUrl = 'http://' + host + ':' + port;
// 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) {
// successfully retrieved an authorization code
console.log("Got a new authorization code!\n");
});
app.listen(port, host, function (err) {
if (err) {
throw err;
}
console.log('server is running on http://' + host + ':' + port + '. Open following link to begin the authorization process: \n');
console.log('http://' + host + ':' + port + '/auth');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment