@@ -72,15 +72,38 @@ public ModelAndView mustAuthenticateController(ModelMap model) throws IOExceptio
7272 @ GetMapping (path = "/ds-return" )
7373 public String returnController (@ RequestParam (value = ATTR_STATE , required = false ) String state ,
7474 @ RequestParam (value = ATTR_EVENT , required = false ) String event ,
75- @ RequestParam (required = false ) String envelopeId , ModelMap model , HttpServletResponse response ) throws IOException {
75+ @ RequestParam (required = false ) String envelopeId , ModelMap model , HttpServletResponse response )
76+ throws IOException {
7677 String site = "/eg001" ;
7778 response .setStatus (response .SC_MOVED_TEMPORARILY );
7879 response .setHeader ("Location" , site );
7980 return null ;
8081 }
8182
83+ @ GetMapping ("/pkce" )
84+ public RedirectView pkce (String code , String state , HttpServletRequest req , HttpServletResponse resp )
85+ throws Exception {
86+ String redirectURL = getRedirectURLForJWTAuthentication (req , resp );
87+ RedirectView redirect ;
88+ try {
89+ redirect = new ACGAuthenticationMethod ().exchangeCodeForToken (code , config , session , redirectURL ,
90+ "signature" );
91+ } catch (Exception e ) {
92+ redirect = getRedirectView (getLoginPath ());
93+ this .session .setIsPKCEWorking (false );
94+ }
95+
96+ return redirect ;
97+ }
98+
8299 private RedirectView getRedirectView () {
83- RedirectView redirect = new RedirectView (getLoginPath ());
100+ this .session .setAuthTypeSelected (AuthType .AGC );
101+ if (this .session .getIsPKCEWorking ()) {
102+ RedirectView redirect = new ACGAuthenticationMethod ().initiateAuthorization (config , "signature" );
103+ } else {
104+ RedirectView redirect = getRedirectView (getLoginPath ());
105+ }
106+
84107 redirect .setExposeModelAttributes (false );
85108 return redirect ;
86109 }
@@ -111,8 +134,7 @@ public Object populateLocals() throws IOException {
111134 OAuth2User oauthUser = oauth .getPrincipal ();
112135 OAuth2AuthorizedClient oauthClient = authorizedClientService .loadAuthorizedClient (
113136 oauth .getAuthorizedClientRegistrationId (),
114- oauthUser .getName ()
115- );
137+ oauthUser .getName ());
116138
117139 if (oauth .isAuthenticated ()) {
118140 user .setName (oauthUser .getAttribute ("name" ));
@@ -139,7 +161,7 @@ private String getBaseUrl(OAuth.Account oauthAccount) {
139161
140162 private static List <OAuth .Account > getOAuthAccounts (OAuth2User user ) {
141163 List <Map <String , Object >> oauthAccounts = user .getAttribute ("accounts" );
142- if (oauthAccounts == null ){
164+ if (oauthAccounts == null ) {
143165 return new ArrayList <>();
144166 }
145167
@@ -152,7 +174,7 @@ private OAuth.Account getDefaultAccountInfo(List<OAuth.Account> accounts) {
152174 String targetAccountId = config .getTargetAccountId ();
153175 if (StringUtils .isNotBlank (targetAccountId )) {
154176 OAuth .Account account = getAccountById (accounts , targetAccountId );
155- if (account != null ) {
177+ if (account != null ) {
156178 return account ;
157179 }
158180 }
0 commit comments