1414'use strict' ;
1515
1616const moment = require ( 'moment' )
17- , docusign = require ( 'docusign-esign' )
1817 , dsConfig = require ( '../ds_configuration.js' ) . config
1918 , passport = require ( 'passport' )
2019 , baseUriSuffix = '/restapi'
@@ -35,22 +34,8 @@ let DSAuthCodeGrant = function _DSAuthCodeGrant(req) {
3534 // For production use, you'd want to store the refresh token in non-volatile storage since it is
3635 // good for 30 days. You'd probably want to encrypt it too.
3736 this . _tokenExpiration = req . user && req . user . tokenExpirationTimestamp ; // when does the token expire?
38- this . _accountId = req . session && req . session . accountId ; // current account
39- this . _accountName = req . session && req . session . accountName ; // current account's name
40- this . _basePath = req . session && req . session . basePath ; // current base path. eg https://na2.docusign.net/restapi
41- this . _dsApiClient = null ; // the docusign sdk instance
42- this . _dsConfig = null ;
4337 this . _debug = true ; // ### DEBUG ### setting
4438
45- // INITIALIZE
46- this . _dsApiClient = new docusign . ApiClient ( ) ;
47- if ( this . _basePath ) {
48- this . _dsApiClient . setBasePath ( this . _basePath ) ;
49- }
50- if ( this . _accessToken ) {
51- this . _dsApiClient . addDefaultHeader ( 'Authorization' , 'Bearer ' + this . _accessToken ) ;
52- }
53-
5439} // end of DSAuthCodeGrant constructor function
5540
5641// Public constants
@@ -82,12 +67,11 @@ DSAuthCodeGrant.prototype.oauth_callback1 = (req, res, next) => {
8267 passport . authenticate ( 'docusign' , { failureRedirect : '/ds/login' } ) ( req , res , next )
8368}
8469DSAuthCodeGrant . prototype . oauth_callback2 = function _oauth_callback2 ( req , res , next ) {
85- //console.log(`Received access_token: ${ req.user.accessToken.substring(0,15)}...`) ;
70+ this . _accessToken = req . user . accessToken ;
8671 console . log ( `Received access_token: |${ req . user . accessToken } |` ) ;
8772 console . log ( `Expires at ${ req . user . tokenExpirationTimestamp . format ( "dddd, MMMM Do YYYY, h:mm:ss a" ) } ` ) ;
8873 req . flash ( 'info' , 'You have authenticated with DocuSign.' ) ;
89- this . _dsApiClient . addDefaultHeader ( 'Authorization' , 'Bearer ' + req . user . accessToken ) ;
90-
74+
9175 // The DocuSign Passport strategy looks up the user's account information via OAuth::userInfo.
9276 // See https://developers.docusign.com/esign-rest-api/guides/authentication/user-info-endpoints
9377 // The data includes the user's information and information on the accounts the user has access too.
@@ -171,12 +155,7 @@ DSAuthCodeGrant.prototype.logoutCallback = function _logout (req, res) {
171155 * @function
172156 */
173157DSAuthCodeGrant . prototype . internalLogout = function _internalLogout ( req , res ) {
174- this . _accessToken = null ;
175- this . _refreshToken = null ;
176158 this . _tokenExpiration = null ;
177- this . _accountId = null ;
178- this . _accountName = null ;
179- this . _basePath = null ;
180159 req . session . accountId = null ;
181160 req . session . accountName = null ;
182161 req . session . basePath = null ;
@@ -202,20 +181,14 @@ DSAuthCodeGrant.prototype.getDefaultAccountInfo = function _getDefaultAccountInf
202181 throw new Error ( this . Error_account_not_found )
203182 }
204183 } else {
205- account = accounts . find ( a => a . is_default ) ;
184+ account = accounts . find ( a => a . is_default ) ;
206185 }
207186
208187 // Save the account information
209- this . _accountId = account . account_id ;
210- this . _accountName = account . account_name ;
211- this . _basePath = account . base_uri + baseUriSuffix ;
212-
213- req . session . accountId = this . _accountId ;
214- req . session . accountName = this . _accountName ;
215- req . session . basePath = this . _basePath ;
216-
217- this . _dsApiClient . setBasePath ( this . _basePath ) ;
218- console . log ( `Using account ${ this . _accountId } : ${ this . _accountName } ` ) ;
188+ req . session . accountId = account . account_id ;
189+ req . session . accountName = account . account_name ;
190+ req . session . basePath = account . base_uri + baseUriSuffix ;
191+ console . log ( `Using account ${ account . account_id } : ${ account . account_name } ` ) ;
219192}
220193
221194/**
@@ -255,41 +228,6 @@ DSAuthCodeGrant.prototype.setEg = function _setEg(req, eg) {
255228 req . session . eg = eg
256229}
257230
258- /**
259- * Getter for the object's <tt>dsApiClient</tt>
260- * @function
261- * @returns {DSApiClient } dsApiClient
262- */
263- DSAuthCodeGrant . prototype . getDSApi = function ( ) { return this . _dsApiClient } ;
264-
265- /**
266- * Getter for the object's <tt>accessToken</tt>
267- * First check its validity via checkToken
268- * @function
269- * @returns {BearerToken } accessToken
270- */
271- DSAuthCodeGrant . prototype . getAccessToken = function ( ) { return this . _accessToken } ;
272-
273- /**
274- * Getter for the <tt>accountId</tt>
275- * @function
276- * @returns {string } accountId
277- */
278- DSAuthCodeGrant . prototype . getAccountId = function ( ) { return this . _accountId } ;
279-
280- /**
281- * Getter for the <tt>accountName</tt>
282- * @function
283- * @returns {string } accountName
284- */
285- DSAuthCodeGrant . prototype . getAccountName = function ( ) { return this . _accountName } ;
286-
287- /**
288- * Getter for the <tt>baseUri</tt>
289- * @function
290- * @returns {string } baseUri
291- */
292- DSAuthCodeGrant . prototype . getBasePath = function ( ) { return this . _basePath } ;
293231
294232/**
295233 * If in debug mode, prints message to the console
0 commit comments