99import com .fasterxml .jackson .databind .ObjectMapper ;
1010import com .fasterxml .jackson .dataformat .csv .CsvMapper ;
1111import com .fasterxml .jackson .dataformat .csv .CsvSchema ;
12- import com .migcomponents .migbase64 .Base64 ;
13- import org .apache .oltu .oauth2 .client .request .OAuthClientRequest .AuthenticationRequestBuilder ;
14- import org .apache .oltu .oauth2 .client .request .OAuthClientRequest .TokenRequestBuilder ;
15- import org .apache .oltu .oauth2 .common .exception .OAuthSystemException ;
1612import org .glassfish .jersey .client .ClientConfig ;
1713import org .glassfish .jersey .client .ClientProperties ;
1814import org .glassfish .jersey .client .HttpUrlConnectorProvider ;
3430import java .lang .reflect .InvocationTargetException ;
3531import java .lang .reflect .Method ;
3632import java .net .*;
33+ import java .nio .charset .StandardCharsets ;
3734
3835import java .nio .file .Files ;
3936import java .nio .file .StandardCopyOption ;
@@ -84,6 +81,8 @@ public class ApiClient {
8481 protected DateFormat dateFormat ;
8582 private SSLContext sslContext = null ;
8683
84+ private final String HTTPS = "https://" ;
85+
8786 /**
8887 * ApiClient constructor.
8988 *
@@ -96,11 +95,11 @@ public ApiClient() {
9695 String javaVersion = System .getProperty ("java.version" );
9796
9897 // Set default User-Agent.
99- setUserAgent ("Swagger-Codegen/v2.1/6.0.0-RC1 /Java/" + javaVersion );
98+ setUserAgent ("Swagger-Codegen/v2.1/6.0.0-RC2 /Java/" + javaVersion );
10099
101100 // Setup authentications (key: authentication name, value: authentication).
102101 authentications = new HashMap <String , Authentication >();
103- authentications .put ("docusignAccessCode" , new OAuth ());
102+ authentications .put ("docusignAccessCode" , new OAuth (httpClient ));
104103
105104 // Derive the OAuth base path from the Rest API base url
106105 this .deriveOAuthBasePathFromRestBasePath ();
@@ -138,7 +137,7 @@ public ApiClient(String oAuthBasePath, String[] authNames) {
138137 for (String authName : authNames ) {
139138 Authentication auth ;
140139 if ("docusignAccessCode" .equals (authName )) {
141- auth = new OAuth (httpClient , OAuthFlow .accessCode , oAuthBasePath + "/oauth/auth" , oAuthBasePath + "/oauth/token" , "all" );
140+ auth = new OAuth (httpClient , OAuthFlow .accessCode , HTTPS + oAuthBasePath + "/oauth/auth" , HTTPS + oAuthBasePath + "/oauth/token" , "all" );
142141 } else if ("docusignApiKey" .equals (authName )) {
143142 auth = new ApiKeyAuth ("header" , "docusignApiKey" );
144143 } else {
@@ -166,9 +165,11 @@ public ApiClient(String oAuthBasePath, String authName) {
166165 */
167166 public ApiClient (String oAuthBasePath , String authName , String clientId , String secret ) {
168167 this (oAuthBasePath , authName );
169- this .getTokenEndPoint ()
170- .setClientId (clientId )
171- .setClientSecret (secret );
168+ Authentication auth = authentications .get (authName );
169+ if (auth instanceof OAuth ) {
170+ ((OAuth ) auth ).setClientId (clientId );
171+ ((OAuth ) auth ).setClientSecret (secret );
172+ }
172173 }
173174
174175 /**
@@ -378,7 +379,7 @@ public void setAccessToken(final String accessToken, final Long expiresIn) {
378379 return ;
379380 }
380381 }
381- OAuth oAuth = new OAuth (null , null , null );
382+ OAuth oAuth = new OAuth ();
382383 oAuth .setAccessToken (accessToken , expiresIn );
383384 addAuthorization ("docusignAccessCode" , oAuth );
384385 }
@@ -523,35 +524,6 @@ public ApiClient setDateFormat(DateFormat dateFormat) {
523524 return this ;
524525 }
525526
526- /**
527- * Helper method to configure the token endpoint of the first oauth found in the authentications (there should be only one).
528- * @return
529- */
530- public TokenRequestBuilder getTokenEndPoint () {
531- for (Authentication auth : getAuthentications ().values ()) {
532- if (auth instanceof OAuth ) {
533- OAuth oauth = (OAuth ) auth ;
534- return oauth .getTokenRequestBuilder ();
535- }
536- }
537- return null ;
538- }
539-
540-
541- /**
542- * Helper method to configure authorization endpoint of the first oauth found in the authentications (there should be only one).
543- * @return
544- */
545- public AuthenticationRequestBuilder getAuthorizationEndPoint () {
546- for (Authentication auth : authentications .values ()) {
547- if (auth instanceof OAuth ) {
548- OAuth oauth = (OAuth ) auth ;
549- return oauth .getAuthenticationRequestBuilder ();
550- }
551- }
552- return null ;
553- }
554-
555527 /**
556528 * Helper method to configure the OAuth accessCode/implicit flow parameters.
557529 * @param clientId OAuth2 client ID
@@ -562,20 +534,22 @@ public void configureAuthorizationFlow(String clientId, String clientSecret, Str
562534 for (Authentication auth : authentications .values ()) {
563535 if (auth instanceof OAuth ) {
564536 OAuth oauth = (OAuth ) auth ;
565- oauth .getTokenRequestBuilder ()
566- .setClientId (clientId )
567- .setClientSecret (clientSecret )
568- .setRedirectURI (redirectURI );
569- oauth .getAuthenticationRequestBuilder ()
570- .setClientId (clientId )
571- .setRedirectURI (redirectURI );
537+ ((OAuth ) auth ).setClientId (clientId );
538+ ((OAuth ) auth ).setClientSecret (clientSecret );
539+ ((OAuth ) auth ).setRedirectURI (redirectURI );
572540 return ;
573541 }
574542 }
575543 }
576544
577- public String getAuthorizationUri () throws OAuthSystemException {
578- return getAuthorizationEndPoint ().buildQueryMessage ().getLocationUri ();
545+ public String getAuthorizationUri () {
546+ for (Authentication auth : authentications .values ()) {
547+ if (auth instanceof OAuth ) {
548+ OAuth oauth = (OAuth ) auth ;
549+ return oauth .getAuthorizationUrl ();
550+ }
551+ }
552+ return null ;
579553 }
580554
581555 /**
@@ -677,7 +651,7 @@ public OAuth.OAuthToken generateAccessToken(String clientId, String clientSecret
677651
678652 Invocation .Builder invocationBuilder = target .request ();
679653 invocationBuilder = invocationBuilder
680- .header ("Authorization" , "Basic " + Base64 .encodeToString (clientStr .getBytes ("UTF-8" ), false ))
654+ .header ("Authorization" , "Basic " + Base64 .getEncoder (). encodeToString (clientStr .getBytes (StandardCharsets . UTF_8 ) ))
681655 .header ("Cache-Control" , "no-store" )
682656 .header ("Pragma" , "no-cache" );
683657
0 commit comments