14
14
'use strict' ;
15
15
16
16
const moment = require ( 'moment' )
17
- , docusign = require ( 'docusign-esign' )
18
17
, dsConfig = require ( '../ds_configuration.js' ) . config
19
18
, passport = require ( 'passport' )
20
19
, baseUriSuffix = '/restapi'
@@ -35,22 +34,8 @@ let DSAuthCodeGrant = function _DSAuthCodeGrant(req) {
35
34
// For production use, you'd want to store the refresh token in non-volatile storage since it is
36
35
// good for 30 days. You'd probably want to encrypt it too.
37
36
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 ;
43
37
this . _debug = true ; // ### DEBUG ### setting
44
38
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
-
54
39
} // end of DSAuthCodeGrant constructor function
55
40
56
41
// Public constants
@@ -82,12 +67,11 @@ DSAuthCodeGrant.prototype.oauth_callback1 = (req, res, next) => {
82
67
passport . authenticate ( 'docusign' , { failureRedirect : '/ds/login' } ) ( req , res , next )
83
68
}
84
69
DSAuthCodeGrant . 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 ;
86
71
console . log ( `Received access_token: |${ req . user . accessToken } |` ) ;
87
72
console . log ( `Expires at ${ req . user . tokenExpirationTimestamp . format ( "dddd, MMMM Do YYYY, h:mm:ss a" ) } ` ) ;
88
73
req . flash ( 'info' , 'You have authenticated with DocuSign.' ) ;
89
- this . _dsApiClient . addDefaultHeader ( 'Authorization' , 'Bearer ' + req . user . accessToken ) ;
90
-
74
+
91
75
// The DocuSign Passport strategy looks up the user's account information via OAuth::userInfo.
92
76
// See https://developers.docusign.com/esign-rest-api/guides/authentication/user-info-endpoints
93
77
// 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) {
171
155
* @function
172
156
*/
173
157
DSAuthCodeGrant . prototype . internalLogout = function _internalLogout ( req , res ) {
174
- this . _accessToken = null ;
175
- this . _refreshToken = null ;
176
158
this . _tokenExpiration = null ;
177
- this . _accountId = null ;
178
- this . _accountName = null ;
179
- this . _basePath = null ;
180
159
req . session . accountId = null ;
181
160
req . session . accountName = null ;
182
161
req . session . basePath = null ;
@@ -202,20 +181,14 @@ DSAuthCodeGrant.prototype.getDefaultAccountInfo = function _getDefaultAccountInf
202
181
throw new Error ( this . Error_account_not_found )
203
182
}
204
183
} else {
205
- account = accounts . find ( a => a . is_default ) ;
184
+ account = accounts . find ( a => a . is_default ) ;
206
185
}
207
186
208
187
// 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 } ` ) ;
219
192
}
220
193
221
194
/**
@@ -255,41 +228,6 @@ DSAuthCodeGrant.prototype.setEg = function _setEg(req, eg) {
255
228
req . session . eg = eg
256
229
}
257
230
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 } ;
293
231
294
232
/**
295
233
* If in debug mode, prints message to the console
0 commit comments