Created
February 19, 2018 21:44
-
-
Save DSDevCenter/c8a77fbf86b4a17c0bf8a7e6dfaf8a03 to your computer and use it in GitHub Desktop.
DocuSign NODE SDK Example - Get OAuth access token
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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