66import com .docusign .core .model .User ;
77import java .io .IOException ;
88import java .util .*;
9+ import javax .servlet .http .HttpServletRequest ;
10+ import javax .servlet .http .HttpServletResponse ;
11+ import com .docusign .core .security .acg .ACGAuthenticationMethod ;
912
1013import com .docusign .core .utils .AccountsConverter ;
1114import org .apache .commons .lang3 .StringUtils ;
2629import com .docusign .esign .client .auth .OAuth ;
2730import java .util .stream .Collectors ;
2831import org .springframework .security .core .Authentication ;
29- import org .springframework .web .bind .annotation .ControllerAdvice ;
30- import org .springframework .web .bind .annotation .ModelAttribute ;
31- import javax .servlet .http .HttpServletResponse ;
3232
3333@ Controller
3434@ ControllerAdvice
3535@ Scope (WebApplicationContext .SCOPE_SESSION )
3636public class IndexController {
37- private static final String ATTR_ENVELOPE_ID = "qpEnvelopeId" ;
37+ private static final List < String > ESIGNATURE_SCOPES = Arrays . asList ( "signature" ) ;
3838 private static final String ATTR_STATE = "state" ;
3939 private static final String ATTR_EVENT = "event" ;
40- private static final String ATTR_TITLE = "title" ;
4140
4241 private static final String ERROR_ACCOUNT_NOT_FOUND = "Could not find account information for the user" ;
43- private static final String SELECTED_API_NOT_SUPPORTED = "Currently selected api is not supported by launcher. Please, check appsettings.json file." ;
4442 private final DSConfiguration config ;
4543 private final Session session ;
4644 private final User user ;
@@ -65,7 +63,7 @@ public String index(ModelMap model, HttpServletResponse response) throws IOExcep
6563 }
6664
6765 @ GetMapping (path = "/ds/mustAuthenticate" )
68- public ModelAndView mustAuthenticateController (ModelMap model ) throws IOException {
66+ public ModelAndView mustAuthenticateController (ModelMap model ) throws IOException , Exception {
6967 return new ModelAndView (getRedirectView ());
7068 }
7169
@@ -83,25 +81,25 @@ public String returnController(@RequestParam(value = ATTR_STATE, required = fals
8381 @ GetMapping ("/pkce" )
8482 public RedirectView pkce (String code , String state , HttpServletRequest req , HttpServletResponse resp )
8583 throws Exception {
86- String redirectURL = getRedirectURLForJWTAuthentication ( req , resp ) ;
84+ String redirectURL = "/" ;
8785 RedirectView redirect ;
8886 try {
8987 redirect = new ACGAuthenticationMethod ().exchangeCodeForToken (code , config , session , redirectURL ,
90- "signature" );
88+ ESIGNATURE_SCOPES );
9189 } catch (Exception e ) {
92- redirect = getRedirectView (getLoginPath ());
90+ redirect = new RedirectView (getLoginPath ());
9391 this .session .setIsPKCEWorking (false );
9492 }
9593
9694 return redirect ;
9795 }
9896
99- private RedirectView getRedirectView () {
100- this . session . setAuthTypeSelected ( AuthType . AGC ) ;
97+ private RedirectView getRedirectView () throws Exception {
98+ RedirectView redirect ;
10199 if (this .session .getIsPKCEWorking ()) {
102- RedirectView redirect = new ACGAuthenticationMethod ().initiateAuthorization (config , "signature" );
100+ redirect = new ACGAuthenticationMethod ().initiateAuthorization (config , ESIGNATURE_SCOPES );
103101 } else {
104- RedirectView redirect = getRedirectView (getLoginPath ());
102+ redirect = new RedirectView (getLoginPath ());
105103 }
106104
107105 redirect .setExposeModelAttributes (false );
@@ -138,7 +136,12 @@ public Object populateLocals() throws IOException {
138136
139137 if (oauth .isAuthenticated ()) {
140138 user .setName (oauthUser .getAttribute ("name" ));
141- user .setAccessToken (oauthClient .getAccessToken ().getTokenValue ());
139+
140+ if (oauthClient != null ) {
141+ user .setAccessToken (oauthClient .getAccessToken ().getTokenValue ());
142+ } else {
143+ user .setAccessToken (((OAuth .OAuthToken ) oauthUser .getAttribute ("access_token" )).getAccessToken ());
144+ }
142145
143146 if (account .isEmpty ()) {
144147 account = Optional .ofNullable (getDefaultAccountInfo (getOAuthAccounts (oauthUser )));
0 commit comments