@@ -85,23 +85,9 @@ class OAuthImplicit {
8585 // This API method is common for many IdP systems.
8686 // But the exact format of the response tends to vary.
8787 // The following works for the DocuSign IdP.
88- let userInfoResponse ;
89- try {
90- userInfoResponse = await this . fetchUserInfo ( ) ;
91- } catch ( e ) {
92- const msg = `Problem while completing login.\nPlease retry.\nError: ${ e . toString ( ) } ` ;
93- log ( msg ) ;
94- toast . error ( msg , { autoClose : 10000 } ) ;
95- return ;
96- }
97- if ( ! userInfoResponse || ! userInfoResponse . ok ) {
98- const msg = `Problem while completing login.\nPlease retry.\nError: ${ userInfoResponse . statusText } ` ;
99- log ( msg ) ;
100- toast . error ( msg , { autoClose : 10000 } ) ;
101- return ;
102- }
103- const userInfo = await userInfoResponse . json ( ) ;
104- const defaultAccount = userInfo . accounts . filter ( ( acc ) => acc . is_default ) [ 0 ] ;
88+ const userInfo = await this . fetchUserInfo ( ) ;
89+ const defaultAccountArray = userInfo . accounts . filter ( ( acc ) => acc . is_default ) ;
90+ const defaultAccount = defaultAccountArray . length > 0 && defaultAccountArray [ 0 ] ;
10591 if ( ! defaultAccount ) {
10692 const msg = `Problem: the user does not have a default account. Contact DocuSign Customer Service to fix.` ;
10793 log ( msg ) ;
@@ -149,23 +135,58 @@ class OAuthImplicit {
149135 `scope=${ window . config . IMPLICIT_SCOPES } &` +
150136 `client_id=${ window . config . DS_CLIENT_ID } &` +
151137 `state=${ oauthStateValue } &` +
152- `redirect_uri=${ window . config . DS_APP_URL } ` ;
138+ `redirect_uri=${ encodeURIComponent ( window . config . DS_APP_URL ) } ` ;
139+
140+ window . location = url ;
141+ }
142+
143+ /**
144+ * logout of the DocuSign IdP.
145+ * If SSO is used, the upstream IdP may not redirect the
146+ * browser back to this app
147+ */
148+ logout ( ) {
149+ const url =
150+ `${ window . config . DS_IDP } /logout?` +
151+ //`response_type=code&` +
152+ `response_type=token&` +
153+ `scope=${ window . config . IMPLICIT_SCOPES } &` +
154+ `client_id=${ window . config . DS_CLIENT_ID } &` +
155+ `redirect_uri=${ encodeURIComponent ( window . config . DS_APP_URL ) } &` +
156+ `response_mode=logout_redirect` ;
153157
154158 window . location = url ;
155159 }
156160
157161 /**
158162 * A relatively common OAuth API endpoint for obtaining information
159163 * on the user associated with the accessToken
164+ * @returns userInfoResponse JSON
160165 */
161166 async fetchUserInfo ( ) {
162- return fetch ( `${ window . config . DS_AUTHENTICATION } /oauth/userinfo` , {
163- headers : new Headers ( {
164- Authorization : `Bearer ${ this . accessToken } ` ,
165- Accept : `application/json` ,
166- 'X-DocuSign-SDK' : sdkString ,
167- } ) ,
168- } )
167+ let userInfoResponse
168+ try {
169+ userInfoResponse = await fetch (
170+ `${ window . config . DS_AUTHENTICATION } /oauth/userinfo` , {
171+ headers : new Headers ( {
172+ Authorization : `Bearer ${ this . accessToken } ` ,
173+ Accept : `application/json` ,
174+ 'X-DocuSign-SDK' : sdkString ,
175+ } ) ,
176+ } )
177+ } catch ( e ) {
178+ const msg = `Problem while completing login.\nPlease retry.\nError: ${ e . toString ( ) } ` ;
179+ log ( msg ) ;
180+ toast . error ( msg , { autoClose : 10000 } ) ;
181+ return null ;
182+ }
183+ if ( ! userInfoResponse || ! userInfoResponse . ok ) {
184+ const msg = `Problem while completing login.\nPlease retry.\nError: ${ userInfoResponse . statusText } ` ;
185+ log ( msg ) ;
186+ toast . error ( msg , { autoClose : 10000 } ) ;
187+ return null ;
188+ }
189+ return await userInfoResponse . json ( ) ;
169190 }
170191
171192 /**
0 commit comments