@@ -87,11 +87,7 @@ URI uri = URI.create("https://sandbox.api.mastercard.com/service");
8787String method = " POST" ;
8888String payload = " Hello world!" ;
8989Charset charset = StandardCharsets . UTF_8 ;
90- String authHeader = OAuth . getAuthorizationHeader(uri, method, payload, charset, consumerKey, signingKey); // uses RSA_SHA256 as the default signature method
91- ```
92- Alternatively, you can specify the signature method as well:
93- ``` java
94- String authHeader = OAuth . getAuthorizationHeader(uri, method, payload, charset, consumerKey, signingKey, SignatureMethod . RSA_PSS_SHA256 );
90+ String authHeader = OAuth . getAuthorizationHeader(uri, method, payload, charset, consumerKey, signingKey);
9591```
9692
9793### Signing HTTP Client Request Objects <a name =" signing-http-client-request-objects " ></a >
@@ -117,13 +113,7 @@ HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
117113con. setRequestMethod(" POST" );
118114con. setRequestProperty(" Content-Type" , " application/json; charset=" + charset. name());
119115
120- HttpsUrlConnectionSigner signer = new HttpsUrlConnectionSigner (charset, consumerKey, signingKey); // uses RSA_SHA256 as the default signature method
121- signer. sign(con, payload);
122- ```
123-
124- You can also specify the signature method when creating the signer object:
125- ``` java
126- HttpsUrlConnectionSigner signer = new HttpsUrlConnectionSigner (charset, consumerKey, signingKey, SignatureMethod . RSA_PSS_SHA256 );
116+ HttpsUrlConnectionSigner signer = new HttpsUrlConnectionSigner (charset, consumerKey, signingKey);
127117signer. sign(con, payload);
128118```
129119
@@ -135,9 +125,7 @@ HttpClient httpClient = HttpClientBuilder.create().build();
135125HttpPost httpPost = new HttpPost (" https://sandbox.api.mastercard.com/service" );
136126httpPost. setEntity(new StringEntity (payload, ContentType . APPLICATION_JSON ));
137127
138- ApacheHttpClient4Signer signer = new ApacheHttpClient4Signer (consumerKey, signingKey); // uses RSA_SHA256 as the default signature method
139- // You can also specify the signature method:
140- // ApacheHttpClient4Signer signer = new ApacheHttpClient4Signer(consumerKey, signingKey, SignatureMethod.RSA_PSS_SHA256);
128+ ApacheHttpClient4Signer signer = new ApacheHttpClient4Signer (consumerKey, signingKey);
141129signer. sign(httpPost);
142130```
143131
@@ -152,9 +140,7 @@ Request.Builder request = new Request.Builder()
152140 .url(" https://sandbox.api.mastercard.com/service" )
153141 .post(body);
154142
155- OkHttpSigner signer = new OkHttpSigner (consumerKey, signingKey); // uses RSA_SHA256 as the default signature method
156- // You can also specify the signature method:
157- // OkHttpSigner signer = new OkHttpSigner(consumerKey, signingKey, SignatureMethod.RSA_PSS_SHA256);
143+ OkHttpSigner signer = new OkHttpSigner (consumerKey, signingKey);
158144signer. sign(request);
159145```
160146
@@ -166,9 +152,7 @@ ClientRequest request = ClientRequest.create(HttpMethod.POST, URI.create("https:
166152 .body(BodyInserters . fromValue(new BodyInserterWrapper (yourRequestObject)))
167153 .build();
168154
169- SpringWebfluxSigner signer = new SpringWebfluxSigner (consumerKey, signingKey); // uses RSA_SHA256 as the default signature method
170- // You can also specify the signature method:
171- // SpringWebfluxSigner signer = new SpringWebfluxSigner(consumerKey, signingKey, SignatureMethod.RSA_PSS_SHA256);
155+ SpringWebfluxSigner signer = new SpringWebfluxSigner (consumerKey, signingKey);
172156ClientRequest signedRequest = signer. sign(request);
173157client. exchange(signedRequest);
174158```
@@ -209,11 +193,7 @@ See also:
209193ApiClient client = new ApiClient ();
210194client. setBasePath(" https://sandbox.api.mastercard.com" );
211195List<Interceptor > interceptors = client. getHttpClient(). interceptors();
212- interceptors. add(
213- new OkHttp2OAuth1Interceptor (consumerKey, signingKey) // uses RSA_SHA256 as the default signature method
214- // if you want to specify the signature method
215- // new OkHttp2OAuth1Interceptor(consumerKey, signingKey, SignatureMethod.RSA_PSS_SHA256)
216- );
196+ interceptors. add(new OkHttp2OAuth1Interceptor (consumerKey, signingKey));
217197ServiceApi serviceApi = new ServiceApi (client);
218198// ...
219199```
@@ -227,11 +207,7 @@ client.setHttpClient(
227207 client. getHttpClient()
228208 .newBuilder()
229209 .proxy(proxy) // Optional proxy
230- .addInterceptor(
231- new OkHttpOAuth1Interceptor (consumerKey, signingKey) // uses RSA_SHA256 as the default signature method
232- // if you want to specify the signature method
233- // new OkHttpOAuth1Interceptor(consumerKey, signingKey, SignatureMethod.RSA_PSS_SHA256)
234- )
210+ .addInterceptor(new OkHttpOAuth1Interceptor (consumerKey, signingKey))
235211 .build()
236212);
237213ServiceApi serviceApi = new ServiceApi (client);
@@ -255,11 +231,7 @@ ApiClient client = new ApiClient();
255231client. setBasePath(" https://sandbox.api.mastercard.com" );
256232Feign . Builder feignBuilder = client. getFeignBuilder();
257233ArrayList<RequestInterceptor > interceptors = new ArrayList<> ();
258- interceptors. add(
259- new OpenFeignOAuth1Interceptor (consumerKey, signingKey, client. getBasePath()) // uses RSA_SHA256 as the default signature method
260- // if you want to specify the signature method
261- // new OpenFeignOAuth1Interceptor(consumerKey, signingKey, client.getBasePath(), SignatureMethod.RSA_PSS_SHA256)
262- );
234+ interceptors. add(new OpenFeignOAuth1Interceptor (consumerKey, signingKey, client. getBasePath()));
263235feignBuilder. requestInterceptors(interceptors);
264236ServiceApi serviceApi = client. buildClient(ServiceApi . class);
265237// ...
@@ -282,11 +254,7 @@ ApiClient client = new ApiClient();
282254RestAdapter . Builder adapterBuilder = client. getAdapterBuilder();
283255adapterBuilder. setEndpoint(" https://sandbox.api.mastercard.com" );
284256List<Interceptor > interceptors = client. getOkClient(). interceptors();
285- interceptors. add(
286- new OkHttp2OAuth1Interceptor (consumerKey, signingKey) // uses RSA_SHA256 as the default signature method
287- // if you want to specify the signature method
288- // new OkHttp2OAuth1Interceptor(consumerKey, signingKey, SignatureMethod.RSA_PSS_SHA256)
289- );
257+ interceptors. add(new OkHttp2OAuth1Interceptor (consumerKey, signingKey));
290258ServiceApi serviceApi = client. createService(ServiceApi . class);
291259// ...
292260```
@@ -308,11 +276,7 @@ ApiClient client = new ApiClient();
308276Retrofit . Builder adapterBuilder = client. getAdapterBuilder();
309277adapterBuilder. baseUrl(" https://sandbox.api.mastercard.com" );
310278OkHttpClient . Builder okBuilder = client. getOkBuilder();
311- okBuilder. addInterceptor(
312- new OkHttpOAuth1Interceptor (consumerKey, signingKey) // uses RSA_SHA256 as the default signature method
313- // if you want to specify the signature method
314- // new OkHttpOAuth1Interceptor(consumerKey, signingKey, SignatureMethod.RSA_PSS_SHA256)
315- );
279+ okBuilder. addInterceptor(new OkHttpOAuth1Interceptor (consumerKey, signingKey));
316280ServiceApi serviceApi = client. createService(ServiceApi . class);
317281// ...
318282```
@@ -333,11 +297,7 @@ ServiceApi serviceApi = client.createService(ServiceApi.class);
333297HttpRequestInitializer initializer = new HttpRequestInitializer () {
334298 @Override
335299 public void initialize (HttpRequest request ) {
336- request. setInterceptor(
337- new HttpExecuteOAuth1Interceptor (consumerKey, signingKey) // uses RSA_SHA256 as the default signature method
338- // if you want to specify the signature method
339- // new HttpExecuteOAuth1Interceptor(consumerKey, signingKey, SignatureMethod.RSA_PSS_SHA256)
340- );
300+ request. setInterceptor(new HttpExecuteOAuth1Interceptor (consumerKey, signingKey));
341301 }
342302};
343303ApiClient client = new ApiClient (" https://sandbox.api.mastercard.com" , null , initializer, null );
@@ -360,11 +320,7 @@ ServiceApi serviceApi = client.serviceApi();
360320``` java
361321WebClient . Builder webClientBuilder = WebClient . builder()
362322 .baseUrl(" https://api.mastercard.com/service" )
363- .filter(
364- new SpringWebfluxOAuth1Interceptor (consumerKey, signingKey) // uses RSA_SHA256 as the default signature method
365- // if you want to specify the signature method
366- // new SpringWebfluxOAuth1Interceptor(consumerKey, signingKey, SignatureMethod.RSA_PSS_SHA256)
367- );
323+ .filter(new SpringWebfluxOAuth1Interceptor (consumerKey, signingKey));
368324
369325ApiClient apiClient = new ApiClient (webClientBuilder);
370326ServiceApi serviceApi = client. serviceApi();
0 commit comments