From 6b516810b399f5fcbefabb68bcf5f4c582f3edd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Efe=20Kocaba=C5=9F?= Date: Tue, 25 Jul 2017 11:58:29 +0300 Subject: [PATCH 001/481] Added EtsyAPI --- README.md | 1 + .../com/github/scribejava/apis/EtsyApi.java | 52 +++++++++++++++ .../scribejava/apis/examples/EtsyExample.java | 66 +++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java diff --git a/README.md b/README.md index 087c0f430..297e4dae5 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ ScribeJava support out-of-box several HTTP clients: * Box (https://www.box.com/) * Digg (http://digg.com/) * Доктор на работе (https://www.doktornarabote.ru/) +* Etsy (https://www.etsy.com/) * Facebook (https://www.facebook.com/) * Flickr (https://www.flickr.com/) * Foursquare (https://foursquare.com/) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java new file mode 100644 index 000000000..bd8a660ba --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java @@ -0,0 +1,52 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.model.OAuth1RequestToken; + +public class EtsyApi extends DefaultApi10a { + + private static final String AUTHORIZE_URL = "https://www.etsy.com/oauth/signin?oauth_token=%s"; + private static final String ACCESS_TOKEN_URL = "https://openapi.etsy.com/v2/oauth/access_token"; + private static final String REQUEST_TOKEN_URL = "https://openapi.etsy.com/v2/oauth/request_token"; + + private final String scopeAsString; + + private EtsyApi() { + scopeAsString = null; + } + + private EtsyApi(String... scopes) { + final StringBuilder builder = new StringBuilder(); + for (String scope : scopes) { + builder.append("%20").append(scope); + } + scopeAsString = "?scope=" + builder.substring(3); + } + + private static class InstanceHolder { + private static final EtsyApi INSTANCE = new EtsyApi(); + } + + public static EtsyApi instance() { + return InstanceHolder.INSTANCE; + } + + public static EtsyApi instance(String... scopes) { + return scopes == null || scopes.length == 0 ? instance() : new EtsyApi(scopes); + } + + @Override + public String getAccessTokenEndpoint() { + return ACCESS_TOKEN_URL; + } + + @Override + public String getRequestTokenEndpoint() { + return scopeAsString == null ? REQUEST_TOKEN_URL : REQUEST_TOKEN_URL + scopeAsString; + } + + @Override + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java new file mode 100644 index 000000000..115617f71 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java @@ -0,0 +1,66 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.EtsyApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth10aService; + +import java.io.IOException; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public final class EtsyExample { + + private static final String PROTECTED_RESOURCE_URL = "https://openapi.etsy.com/v2/users/__SELF__"; + + private EtsyExample() { + } + + public static void main(String[] args) throws InterruptedException, ExecutionException, IOException { + // Replace with your api and secret key + final OAuth10aService service = new ServiceBuilder("your api key") + .apiSecret("your secret key") + .build(EtsyApi.instance()); + final Scanner in = new Scanner(System.in); + + System.out.println("=== Etsy's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + final OAuth1RequestToken requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + final String oauthVerifier = in.nextLine(); + System.out.println(); + + // Trade the Request Token and Verifier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("That's it man! Go and build something awesome with ScribeJava! :)"); + } +} From 3dd5ef1236d4db7f38c0003208f1c335cc80b52f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 25 Jul 2017 15:49:57 +0300 Subject: [PATCH 002/481] add new API - Etsy (https://www.etsy.com/) (thanks to https://github.com/efekocabas) --- changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog b/changelog index 01f18217c..2ec48024f 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) * add new API - Frappe (https://github.com/frappe/frappe) (thanks to https://github.com/revant) + * add new API - Etsy (https://www.etsy.com/) (thanks to https://github.com/efekocabas) [4.1.2] * LinkedIn use Header to sign OAuth2 requests From 7ede38639987f0b4c727ae2e2be1da73dd4a21b8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 25 Jul 2017 15:54:42 +0300 Subject: [PATCH 003/481] prepare 4.2.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 297e4dae5..439c26ae3 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 4.1.2 + 4.2.0 ``` @@ -110,7 +110,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 4.1.2 + 4.2.0 ``` diff --git a/changelog b/changelog index 2ec48024f..5b9f19d96 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) * add new API - Frappe (https://github.com/frappe/frappe) (thanks to https://github.com/revant) * add new API - Etsy (https://www.etsy.com/) (thanks to https://github.com/efekocabas) From 73c8b425dd52d22f61d28ea80a6ced675f074df5 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 25 Jul 2017 15:55:45 +0300 Subject: [PATCH 004/481] [maven-release-plugin] prepare release scribejava-4.2.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 15ee61cda..ab3f8dda0 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 4.1.3-SNAPSHOT + 4.2.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -33,7 +33,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-4.2.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 6993dd3e5..93cb6bac9 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.3-SNAPSHOT + 4.2.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index c0721530c..82c1e2074 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.3-SNAPSHOT + 4.2.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index a97c6a073..bea98dd2f 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.3-SNAPSHOT + 4.2.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 1bd473637..4bd0e96aa 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.3-SNAPSHOT + 4.2.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 2e122949c..759a1e059 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.1.3-SNAPSHOT + 4.2.0 ../pom.xml From b2cdee90e327992654bab56ce609aba4b60af427 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 25 Jul 2017 15:56:02 +0300 Subject: [PATCH 005/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index ab3f8dda0..139715de1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 4.2.0 + 4.2.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -33,7 +33,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-4.2.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 93cb6bac9..583b8cdac 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.0 + 4.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 82c1e2074..e2355021b 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.0 + 4.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index bea98dd2f..02eb03fe0 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.0 + 4.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 4bd0e96aa..0142e94c0 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.0 + 4.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 759a1e059..12e034874 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.0 + 4.2.1-SNAPSHOT ../pom.xml From 868fb7c6c2ca1da0025160824f135720b4ad85b9 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 25 Jul 2017 16:08:11 +0300 Subject: [PATCH 006/481] clean deprecates --- .../apis/google/GoogleJsonTokenExtractor.java | 33 ------------------- .../scribejava/apis/google/GoogleToken.java | 21 ------------ 2 files changed, 54 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java deleted file mode 100644 index a343e7f63..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleJsonTokenExtractor.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.github.scribejava.apis.google; - -import com.github.scribejava.apis.openid.OpenIdJsonTokenExtractor; -import java.util.regex.Pattern; - -/** - * - * @deprecated use generic {@link OpenIdJsonTokenExtractor} - */ -@Deprecated -public class GoogleJsonTokenExtractor extends OpenIdJsonTokenExtractor { - - private static final Pattern ID_TOKEN_REGEX_PATTERN = Pattern.compile("\"id_token\"\\s*:\\s*\"(\\S*?)\""); - - protected GoogleJsonTokenExtractor() { - } - - private static class InstanceHolder { - - private static final GoogleJsonTokenExtractor INSTANCE = new GoogleJsonTokenExtractor(); - } - - public static GoogleJsonTokenExtractor instance() { - return InstanceHolder.INSTANCE; - } - - @Override - protected GoogleToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, String response) { - return new GoogleToken(accessToken, tokenType, expiresIn, refreshToken, scope, - extractParameter(response, ID_TOKEN_REGEX_PATTERN, false), response); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java deleted file mode 100644 index aa76087b8..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleToken.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.github.scribejava.apis.google; - -import com.github.scribejava.apis.openid.OpenIdOAuth2AccessToken; - -/** - * @deprecated use generic {@link OpenIdOAuth2AccessToken} - */ -@Deprecated -public class GoogleToken extends OpenIdOAuth2AccessToken { - - private static final long serialVersionUID = -5959403983480821444L; - - public GoogleToken(String accessToken, String openIdToken, String rawResponse) { - super(accessToken, null, null, null, null, openIdToken, rawResponse); - } - - public GoogleToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, - String openIdToken, String rawResponse) { - super(accessToken, tokenType, expiresIn, refreshToken, scope, openIdToken, rawResponse); - } -} From 52d4dc06a57a28ceb7accd7ab50bfadb1be8fc41 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 26 Jul 2017 18:53:34 +0300 Subject: [PATCH 007/481] drop Java 7 backward compatibility support, become Java 8 only --- .travis.yml | 4 +-- changelog | 3 ++ checkstyle.xml | 1 - pom.xml | 28 ++-------------- .../apis/service/MailruOAuthServiceImpl.java | 12 +++---- .../service/OdnoklassnikiServiceImpl.java | 11 ++++--- .../apis/examples/RenrenExample.java | 32 +++++++++---------- .../core/extractors/HeaderExtractorImpl.java | 21 +++++------- .../core/httpclient/jdk/JDKHttpClient.java | 14 +++----- .../scribejava/core/model/ParameterList.java | 15 ++++----- .../core/oauth/OAuth10aService.java | 22 +++---------- .../scribejava/core/oauth/OAuth20Service.java | 8 +---- .../scribejava/core/utils/MapUtils.java | 25 --------------- .../core/oauth/OAuth20ServiceUnit.java | 5 +-- .../scribejava/core/utils/MapUtilsTest.java | 31 ------------------ .../ning/OAuthAsyncCompletionHandler.java | 17 +++------- .../httpclient/okhttp/OkHttpHttpClient.java | 15 ++++----- 17 files changed, 70 insertions(+), 194 deletions(-) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java delete mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java diff --git a/.travis.yml b/.travis.yml index a79954ad5..80a91cb59 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ +dist: trusty language: java script: mvn clean package jdk: - oraclejdk8 - - oraclejdk7 - - openjdk7 + - openjdk8 os: - linux diff --git a/changelog b/changelog index 5b9f19d96..84e7a582d 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * drop Java 7 backward compatibility support, become Java 8 only + [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) * add new API - Frappe (https://github.com/frappe/frappe) (thanks to https://github.com/revant) diff --git a/checkstyle.xml b/checkstyle.xml index 9cba55776..2955d30b9 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -76,7 +76,6 @@ - diff --git a/pom.xml b/pom.xml index 139715de1..7b8520909 100644 --- a/pom.xml +++ b/pom.xml @@ -151,8 +151,8 @@ 3.6.1 UTF-8 - 1.7 - 1.7 + 1.8 + 1.8 true @@ -229,30 +229,6 @@ - - jdk-1.7 - - 1.7 - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 2.17 - - - com.puppycrawl.tools - checkstyle - 6.19 - - - - - - - release-sign-artifacts diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java index 3330bb006..86bcb79ab 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java @@ -11,6 +11,7 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; +import java.util.stream.Collectors; public class MailruOAuthServiceImpl extends OAuth20Service { @@ -35,13 +36,10 @@ public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { final String[] parts = param.split("="); map.put(parts[0], (parts.length == 1) ? "" : parts[1]); } - final StringBuilder urlNew = new StringBuilder(); - for (Map.Entry entry : map.entrySet()) { - urlNew.append(entry.getKey()); - urlNew.append('='); - urlNew.append(entry.getValue()); - } - final String sigSource = URLDecoder.decode(urlNew.toString(), CharEncoding.UTF_8) + clientSecret; + final String urlNew = map.entrySet().stream() + .map(entry -> entry.getKey() + '=' + entry.getValue()) + .collect(Collectors.joining()); + final String sigSource = URLDecoder.decode(urlNew, CharEncoding.UTF_8) + clientSecret; request.addQuerystringParameter("sig", md5Hex(sigSource)); } } catch (UnsupportedEncodingException e) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java index fa9ae2e56..7e9017978 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java @@ -14,6 +14,7 @@ import java.net.URLDecoder; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; import static org.apache.commons.codec.digest.DigestUtils.md5Hex; @@ -34,12 +35,12 @@ public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { final List allParams = queryParams.getParams(); Collections.sort(allParams); - final StringBuilder builder = new StringBuilder(); - for (Parameter param : allParams) { - builder.append(param.getKey()).append('=').append(param.getValue()); - } - final String sigSource = URLDecoder.decode(builder.toString(), CharEncoding.UTF_8) + tokenDigest; + final String stringParams = allParams.stream() + .map(param -> param.getKey() + '=' + param.getValue()) + .collect(Collectors.joining()); + + final String sigSource = URLDecoder.decode(stringParams, CharEncoding.UTF_8) + tokenDigest; request.addQuerystringParameter("sig", md5Hex(sigSource).toLowerCase()); super.signRequest(accessToken, request); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 1eea7e581..eaeb35532 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -3,10 +3,7 @@ import java.nio.charset.Charset; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; @@ -19,6 +16,8 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; +import java.util.stream.Stream; public final class RenrenExample { @@ -69,20 +68,19 @@ public static void main(String... args) throws IOException, InterruptedException parameters.put("format", "json"); parameters.put("v", "1.0"); - final List sigString = new ArrayList<>(parameters.size() + 1); - for (Map.Entry entry : parameters.entrySet()) { - request.addQuerystringParameter(entry.getKey(), entry.getValue()); - sigString.add(String.format("%s=%s", entry.getKey(), entry.getValue())); - } - sigString.add(String.format("%s=%s", OAuthConstants.ACCESS_TOKEN, accessToken.getAccessToken())); - Collections.sort(sigString); - final StringBuilder b = new StringBuilder(); - for (String param : sigString) { - b.append(param); - } - b.append(apiSecret); - System.out.println("Sig string: " + b.toString()); - request.addQuerystringParameter("sig", md5(b.toString())); + parameters.forEach((key, value) -> request.addQuerystringParameter(key, value)); + + final String sig = Stream.concat( + Stream.concat( + parameters.entrySet().stream() + .map(entry -> String.format("%s=%s", entry.getKey(), entry.getValue())), + Stream.of(String.format("%s=%s", OAuthConstants.ACCESS_TOKEN, accessToken.getAccessToken()))) + .sorted(), + Stream.of(apiSecret)) + .collect(Collectors.joining()); + + System.out.println("Sig string: " + sig); + request.addQuerystringParameter("sig", md5(sig)); service.signRequest(accessToken, request); final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java index 2a840521c..a29ba9839 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java @@ -6,13 +6,13 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; +import java.util.stream.Collectors; /** * Default implementation of {@link HeaderExtractor}. Conforms to OAuth 1.0a */ public class HeaderExtractorImpl implements HeaderExtractor { - public static final int ESTIMATED_PARAM_LENGTH = 20; private static final String PARAM_SEPARATOR = ", "; private static final String PREAMBLE = "OAuth "; @@ -23,21 +23,16 @@ public class HeaderExtractorImpl implements HeaderExtractor { public String extract(OAuthRequest request) { checkPreconditions(request); final Map parameters = request.getOauthParameters(); - final StringBuilder header = new StringBuilder(parameters.size() * ESTIMATED_PARAM_LENGTH); - header.append(PREAMBLE); - for (Map.Entry entry : parameters.entrySet()) { - if (header.length() > PREAMBLE.length()) { - header.append(PARAM_SEPARATOR); - } - header.append(String.format("%s=\"%s\"", entry.getKey(), OAuthEncoder.encode(entry.getValue()))); - } - if (request.getRealm() != null && !request.getRealm().isEmpty()) { - header.append(PARAM_SEPARATOR); - header.append(String.format("%s=\"%s\"", OAuthConstants.REALM, request.getRealm())); + final String paramsString = parameters.entrySet().stream() + .map(entry -> String.format("%s=\"%s\"", entry.getKey(), OAuthEncoder.encode(entry.getValue()))) + .collect(Collectors.joining(PARAM_SEPARATOR, PREAMBLE, "")); + + if (request.getRealm() == null || request.getRealm().isEmpty()) { + return paramsString; } - return header.toString(); + return paramsString + PARAM_SEPARATOR + String.format("%s=\"%s\"", OAuthConstants.REALM, request.getRealm()); } private void checkPreconditions(OAuthRequest request) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index ca38aec48..8a6f3e516 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -13,7 +13,6 @@ import java.net.URL; import java.net.UnknownHostException; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -131,21 +130,18 @@ abstract void setBody(HttpURLConnection connection, Object bodyContents, boolean private static Map parseHeaders(HttpURLConnection conn) { final Map headers = new HashMap<>(); - for (Map.Entry> entry : conn.getHeaderFields().entrySet()) { - final String key = entry.getKey(); + conn.getHeaderFields().forEach((key, value) -> { if ("Content-Encoding".equalsIgnoreCase(key)) { - headers.put("Content-Encoding", entry.getValue().get(0)); + headers.put("Content-Encoding", value.get(0)); } else { - headers.put(key, entry.getValue().get(0)); + headers.put(key, value.get(0)); } - } + }); return headers; } private static void addHeaders(HttpURLConnection connection, Map headers, String userAgent) { - for (Map.Entry entry : headers.entrySet()) { - connection.setRequestProperty(entry.getKey(), entry.getValue()); - } + headers.forEach((key, value) -> connection.setRequestProperty(key, value)); if (userAgent != null) { connection.setRequestProperty(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java index 39d806652..0282eaca7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java @@ -6,6 +6,7 @@ import java.util.Map; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; +import java.util.stream.Collectors; public class ParameterList { @@ -27,9 +28,9 @@ public ParameterList() { public ParameterList(Map map) { this(); if (map != null && !map.isEmpty()) { - for (Map.Entry entry : map.entrySet()) { - params.add(new Parameter(entry.getKey(), entry.getValue())); - } + map.entrySet().stream() + .map(entry -> new Parameter(entry.getKey(), entry.getValue())) + .forEach(params::add); } } @@ -58,11 +59,9 @@ public String asFormUrlEncodedString() { return EMPTY_STRING; } - final StringBuilder builder = new StringBuilder(); - for (Parameter p : params) { - builder.append(PARAM_SEPARATOR).append(p.asUrlEncodedPair()); - } - return builder.substring(1); + return params.stream() + .map(Parameter::asUrlEncodedPair) + .collect(Collectors.joining(PARAM_SEPARATOR)); } public void addAll(ParameterList other) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index ad9e6eda0..00be552cb 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -1,7 +1,6 @@ package com.github.scribejava.core.oauth; import java.io.IOException; -import java.util.Map; import java.util.concurrent.Future; import com.github.scribejava.core.builder.api.DefaultApi10a; import com.github.scribejava.core.builder.api.OAuth1SignatureType; @@ -13,7 +12,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.services.Base64Encoder; -import com.github.scribejava.core.utils.MapUtils; import java.util.concurrent.ExecutionException; /** @@ -58,12 +56,7 @@ public final Future getRequestTokenAsync( final OAuthConfig config = getConfig(); config.log("async obtaining request token from " + api.getRequestTokenEndpoint()); final OAuthRequest request = prepareRequestTokenRequest(); - return execute(request, callback, new OAuthRequest.ResponseConverter() { - @Override - public OAuth1RequestToken convert(Response response) throws IOException { - return getApi().getRequestTokenExtractor().extract(response); - } - }); + return execute(request, callback, response -> getApi().getRequestTokenExtractor().extract(response)); } protected OAuthRequest prepareRequestTokenRequest() { @@ -89,7 +82,7 @@ protected void addOAuthParams(OAuthRequest request, String tokenSecret) { } request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, tokenSecret)); - config.log("appended additional OAuth parameters: " + MapUtils.toString(request.getOauthParameters())); + config.log("appended additional OAuth parameters: " + request.getOauthParameters()); } public final OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, String oauthVerifier) @@ -118,12 +111,7 @@ public final Future getAccessTokenAsync(OAuth1RequestToken re final OAuthConfig config = getConfig(); config.log("async obtaining access token from " + api.getAccessTokenEndpoint()); final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier); - return execute(request, callback, new OAuthRequest.ResponseConverter() { - @Override - public OAuth1AccessToken convert(Response response) throws IOException { - return getApi().getAccessTokenExtractor().extract(response); - } - }); + return execute(request, callback, response -> getApi().getAccessTokenExtractor().extract(response)); } protected OAuthRequest prepareAccessTokenRequest(OAuth1RequestToken requestToken, String oauthVerifier) { @@ -191,9 +179,7 @@ protected void appendSignature(OAuthRequest request) { case QueryString: config.log("using Querystring signature"); - for (Map.Entry entry : request.getOauthParameters().entrySet()) { - request.addQuerystringParameter(entry.getKey(), entry.getValue()); - } + request.getOauthParameters().forEach((key, value) -> request.addQuerystringParameter(key, value)); break; default: throw new IllegalStateException("Unknown new Signature Type '" + signatureType + "'."); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 4565a4165..803e6fa80 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -11,7 +11,6 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Response; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -46,12 +45,7 @@ protected Future sendAccessTokenRequestAsync(OAuthRequest req protected Future sendAccessTokenRequestAsync(OAuthRequest request, OAuthAsyncRequestCallback callback) { - return execute(request, callback, new OAuthRequest.ResponseConverter() { - @Override - public OAuth2AccessToken convert(Response response) throws IOException { - return getApi().getAccessTokenExtractor().extract(response); - } - }); + return execute(request, callback, response -> getApi().getAccessTokenExtractor().extract(response)); } public final Future getAccessTokenAsync(String code) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java b/scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java deleted file mode 100644 index 9cb217cb9..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/utils/MapUtils.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.github.scribejava.core.utils; - -import java.util.Map; - -public abstract class MapUtils { - - public static String toString(Map map) { - if (map == null) { - return ""; - } - if (map.isEmpty()) { - return "{}"; - } - - final StringBuilder result = new StringBuilder(); - for (Map.Entry entry : map.entrySet()) { - result.append(", ") - .append(entry.getKey().toString()) - .append(" -> ") - .append(entry.getValue().toString()) - .append(' '); - } - return "{" + result.append('}').substring(1); - } -} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index 8a49c0ee1..76bd0e8c6 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Parameter; import com.google.gson.Gson; import java.util.HashMap; @@ -38,9 +37,7 @@ private String prepareRawResponse(OAuthRequest request) { response.putAll(request.getHeaders()); response.putAll(request.getOauthParameters()); - for (Parameter p : request.getBodyParams().getParams()) { - response.put("query-" + p.getKey(), p.getValue()); - } + request.getBodyParams().getParams().forEach(p -> response.put("query-" + p.getKey(), p.getValue())); return json.toJson(response); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java deleted file mode 100644 index 9ce36c76f..000000000 --- a/scribejava-core/src/test/java/com/github/scribejava/core/utils/MapUtilsTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.github.scribejava.core.utils; - -import java.util.LinkedHashMap; -import java.util.HashMap; -import java.util.Map; -import org.junit.Assert; -import org.junit.Test; - -public class MapUtilsTest { - - @Test - public void shouldPrettyPrintMap() { - final Map map = new LinkedHashMap<>(); - map.put(1, "one"); - map.put(2, "two"); - map.put(3, "three"); - map.put(4, "four"); - Assert.assertEquals("{ 1 -> one , 2 -> two , 3 -> three , 4 -> four }", MapUtils.toString(map)); - } - - @Test - public void shouldHandleEmptyMap() { - final Map map = new HashMap<>(); - Assert.assertEquals("{}", MapUtils.toString(map)); - } - - @Test - public void shouldHandleNullInputs() { - Assert.assertEquals("", MapUtils.toString(null)); - } -} diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java index 5ce461b1b..c60388ac0 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java @@ -4,11 +4,9 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.ning.http.client.AsyncCompletionHandler; -import com.ning.http.client.FluentCaseInsensitiveStringsMap; import java.io.IOException; -import java.util.HashMap; -import java.util.List; import java.util.Map; +import java.util.stream.Collectors; public class OAuthAsyncCompletionHandler extends AsyncCompletionHandler { @@ -23,15 +21,10 @@ public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, @Override public T onCompleted(com.ning.http.client.Response ningResponse) throws IOException { - final FluentCaseInsensitiveStringsMap map = ningResponse.getHeaders(); - final Map headersMap = new HashMap<>(); - for (FluentCaseInsensitiveStringsMap.Entry> header : map) { - final StringBuilder value = new StringBuilder(); - for (String str : header.getValue()) { - value.append(str); - } - headersMap.put(header.getKey(), value.toString()); - } + final Map headersMap = ningResponse.getHeaders().entrySet().stream() + .collect(Collectors.toMap(header -> header.getKey(), + header -> header.getValue().stream().collect(Collectors.joining()))); + final Response response = new Response(ningResponse.getStatusCode(), ningResponse.getStatusText(), headersMap, ningResponse.getResponseBodyAsStream()); diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 66d2daee0..8090ef845 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -18,8 +18,9 @@ import com.github.scribejava.core.model.Response; import java.io.File; -import java.util.HashMap; import java.util.concurrent.ExecutionException; +import java.util.function.Function; +import java.util.stream.Collectors; import okhttp3.Cache; import okhttp3.Headers; import okhttp3.ResponseBody; @@ -125,9 +126,8 @@ private Call createCall(String userAgent, Map headers, Verb http requestBuilder.method(method, body); // fill headers - for (Map.Entry header : headers.entrySet()) { - requestBuilder.addHeader(header.getKey(), header.getValue()); - } + headers.forEach((key, value) -> requestBuilder.addHeader(key, value)); + if (userAgent != null) { requestBuilder.header(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); } @@ -161,11 +161,8 @@ RequestBody createBody(MediaType mediaType, Object bodyContents) { static Response convertResponse(okhttp3.Response okHttpResponse) { final Headers headers = okHttpResponse.headers(); - final Map headersMap = new HashMap<>(); - - for (String name : headers.names()) { - headersMap.put(name, headers.get(name)); - } + final Map headersMap = headers.names().stream() + .collect(Collectors.toMap(Function.identity(), headers::get)); final ResponseBody body = okHttpResponse.body(); return new Response(okHttpResponse.code(), okHttpResponse.message(), headersMap, From bb23fed9e6b33a0c83905e0ca8a68ae4c1386b3e Mon Sep 17 00:00:00 2001 From: evstropovv Date: Sat, 26 Aug 2017 12:31:40 +0300 Subject: [PATCH 008/481] add ucoz api --- .../com/github/scribejava/apis/UcozApi.java | 40 +++++++++ .../AbstractOauth1UcozTokenExtractor.java | 41 ++++++++++ .../ucoz/OAuth1AccessUcozTokenExtractor.java | 23 ++++++ .../ucoz/OAuth1RequestUcozTokenExtractor.java | 23 ++++++ .../scribejava/apis/examples/UcozExample.java | 81 +++++++++++++++++++ 5 files changed, 208 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/AbstractOauth1UcozTokenExtractor.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1AccessUcozTokenExtractor.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1RequestUcozTokenExtractor.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java new file mode 100644 index 000000000..d591149e5 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java @@ -0,0 +1,40 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.ucoz.OAuth1AccessUcozTokenExtractor; +import com.github.scribejava.apis.ucoz.OAuth1RequestUcozTokenExtractor; +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; + +public class UcozApi extends DefaultApi10a { + private static final String AUTHORIZE_URL = "http://uapi.ucoz.com/accounts/oauthauthorizetoken?oauth_token=%s"; + protected UcozApi() { + } + private static class InstanceHolder { + private static final UcozApi INSTANCE = new UcozApi(); + } + public static UcozApi instance() { + return InstanceHolder.INSTANCE; } + @Override + public String getAccessTokenEndpoint(){ + return "http://uapi.ucoz.com/accounts/oauthgetaccesstoken"; } + + @Override + public String getRequestTokenEndpoint() { + return "http://uapi.ucoz.com/accounts/oauthgetrequesttoken"; } + + @Override + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return OAuth1AccessUcozTokenExtractor.instance(); + } + + @Override + public TokenExtractor getRequestTokenExtractor() { + return OAuth1RequestUcozTokenExtractor.instance(); + } +} \ No newline at end of file diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/AbstractOauth1UcozTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/AbstractOauth1UcozTokenExtractor.java new file mode 100644 index 000000000..14a76dd75 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/AbstractOauth1UcozTokenExtractor.java @@ -0,0 +1,41 @@ +package com.github.scribejava.apis.ucoz; + +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth1Token; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +import java.io.IOException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + + +public abstract class AbstractOauth1UcozTokenExtractor implements TokenExtractor { + + private Pattern OAUTH_TOKEN_PATTERN = Pattern.compile("\"oauth_token\"\\s*:\\s*\"(\\S*?)\""); + private Pattern OAUTH_TOKEN_SECRET_PATTERN = Pattern.compile("\"oauth_token_secret\"\\s*:\\s*\"(\\S*?)\""); + + @Override + public T extract(Response response) throws IOException { + final String body = response.getBody(); + Preconditions.checkEmptyString(body, + "Response body is incorrect. " + "Can't extract a token from an empty string"); + final String token = extract(body, OAUTH_TOKEN_PATTERN); + final String secret = extract(body, OAUTH_TOKEN_SECRET_PATTERN); + return createToken(token, secret, body); + } + + private String extract(String response, Pattern p) { + final Matcher matcher = p.matcher(response); + if (matcher.find() && matcher.groupCount() >= 1) { + return OAuthEncoder.decode(matcher.group(1)); + } else { + throw new OAuthException("Response body is incorrect. Can't extract token and secret from this: '" + + response + "'", null); + } + } + + protected abstract T createToken(String token, String secret, String response); +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1AccessUcozTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1AccessUcozTokenExtractor.java new file mode 100644 index 000000000..bc155710e --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1AccessUcozTokenExtractor.java @@ -0,0 +1,23 @@ +package com.github.scribejava.apis.ucoz; + +import com.github.scribejava.core.model.OAuth1AccessToken; + +public class OAuth1AccessUcozTokenExtractor extends AbstractOauth1UcozTokenExtractor { + + protected OAuth1AccessUcozTokenExtractor() { + } + + @Override + protected OAuth1AccessToken createToken(String token, String secret, String response) { + return new OAuth1AccessToken(token, secret, response); + } + + private static class InstanceHolder { + + private static final OAuth1AccessUcozTokenExtractor INSTANCE = new OAuth1AccessUcozTokenExtractor(); + } + + public static OAuth1AccessUcozTokenExtractor instance() { + return OAuth1AccessUcozTokenExtractor.InstanceHolder.INSTANCE; + } +} \ No newline at end of file diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1RequestUcozTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1RequestUcozTokenExtractor.java new file mode 100644 index 000000000..c615fb840 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1RequestUcozTokenExtractor.java @@ -0,0 +1,23 @@ +package com.github.scribejava.apis.ucoz; + +import com.github.scribejava.core.model.OAuth1RequestToken; + +public class OAuth1RequestUcozTokenExtractor extends AbstractOauth1UcozTokenExtractor { + + protected OAuth1RequestUcozTokenExtractor() { + } + + @Override + protected OAuth1RequestToken createToken(String token, String secret, String response) { + return new OAuth1RequestToken(token, secret, response); + } + + private static class InstanceHolder { + + private static final OAuth1RequestUcozTokenExtractor INSTANCE = new OAuth1RequestUcozTokenExtractor(); + } + + public static OAuth1RequestUcozTokenExtractor instance() { + return InstanceHolder.INSTANCE; + } +} \ No newline at end of file diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java new file mode 100644 index 000000000..f2156dfc9 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java @@ -0,0 +1,81 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.UcozApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.*; +import com.github.scribejava.core.oauth.OAuth10aService; + +import java.io.IOException; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public class UcozExample { + public static void main(String ...args){ + String PROTECTED_RESOURCE_URL ="http://artmurka.com/uapi/shop/request?page=categories"; + OAuth10aService service = new ServiceBuilder( "your_api_key") + .apiSecret("your_api_secret") + .debug() + .build(UcozApi.instance()); + Scanner in = new Scanner(System.in); + OAuth1RequestToken requestToken = null; + try { + requestToken = service.getRequestToken(); + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); + } + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + final String oauthVerifier = in.nextLine(); + System.out.println(); + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + OAuth1AccessToken accessToken = null; + try { + accessToken = service.getAccessToken(requestToken, oauthVerifier); + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); + } + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + Response response = null; + try { + response = service.execute(request); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + try { + System.out.println(response.getBody()); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} From 9ae56fd62d3230ea26d62615eb8bc85b6f498523 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 28 Aug 2017 12:52:18 +0300 Subject: [PATCH 009/481] format, rename, fix a bit --- README.md | 1 + changelog | 2 + .../com/github/scribejava/apis/UcozApi.java | 88 ++++++----- .../ucoz/OAuth1AccessUcozTokenExtractor.java | 23 --- .../ucoz/OAuth1RequestUcozTokenExtractor.java | 23 --- .../scribejava/apis/examples/UcozExample.java | 141 ++++++++---------- .../VkontakteExternalHttpExample.java | 2 +- .../apis/examples/YahooExample.java | 2 +- .../AbstractOAuth1JSONTokenExtractor.java | 81 +++++----- .../OAuth1AccessTokenJSONExtractor.java | 23 +++ .../OAuth1RequestTokenJSONExtractor.java | 23 +++ 11 files changed, 199 insertions(+), 210 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1AccessUcozTokenExtractor.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1RequestUcozTokenExtractor.java rename scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/AbstractOauth1UcozTokenExtractor.java => scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java (66%) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1AccessTokenJSONExtractor.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1RequestTokenJSONExtractor.java diff --git a/README.md b/README.md index 439c26ae3..567d5075b 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ ScribeJava support out-of-box several HTTP clients: * Tumblr (https://www.tumblr.com/) * TUT.BY (http://www.tut.by/) * Twitter (https://twitter.com/) +* uCoz (https://www.ucoz.com/) * Viadeo (http://viadeo.com/) * VK ВКонтакте (http://vk.com/) * XING (https://www.xing.com/) diff --git a/changelog b/changelog index 84e7a582d..4ef2ad99c 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,7 @@ [SNAPSHOT] * drop Java 7 backward compatibility support, become Java 8 only + * add JSON token extractor for OAuth 1.0a (thanks to https://github.com/evstropovv) + * add new API - uCoz (https://www.ucoz.com/) (thanks to https://github.com/evstropovv) [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java index d591149e5..208eddc38 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java @@ -1,40 +1,48 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.apis.ucoz.OAuth1AccessUcozTokenExtractor; -import com.github.scribejava.apis.ucoz.OAuth1RequestUcozTokenExtractor; -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth1AccessToken; -import com.github.scribejava.core.model.OAuth1RequestToken; - -public class UcozApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "http://uapi.ucoz.com/accounts/oauthauthorizetoken?oauth_token=%s"; - protected UcozApi() { - } - private static class InstanceHolder { - private static final UcozApi INSTANCE = new UcozApi(); - } - public static UcozApi instance() { - return InstanceHolder.INSTANCE; } - @Override - public String getAccessTokenEndpoint(){ - return "http://uapi.ucoz.com/accounts/oauthgetaccesstoken"; } - - @Override - public String getRequestTokenEndpoint() { - return "http://uapi.ucoz.com/accounts/oauthgetrequesttoken"; } - - @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); } - - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth1AccessUcozTokenExtractor.instance(); - } - - @Override - public TokenExtractor getRequestTokenExtractor() { - return OAuth1RequestUcozTokenExtractor.instance(); - } -} \ No newline at end of file +package com.github.scribejava.apis; + +import com.github.scribejava.core.extractors.OAuth1AccessTokenJSONExtractor; +import com.github.scribejava.core.extractors.OAuth1RequestTokenJSONExtractor; +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; + +public class UcozApi extends DefaultApi10a { + private static final String AUTHORIZE_URL = "http://uapi.ucoz.com/accounts/oauthauthorizetoken?oauth_token=%s"; + + protected UcozApi() { + } + + private static class InstanceHolder { + private static final UcozApi INSTANCE = new UcozApi(); + } + + public static UcozApi instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint(){ + return "http://uapi.ucoz.com/accounts/oauthgetaccesstoken"; + } + + @Override + public String getRequestTokenEndpoint() { + return "http://uapi.ucoz.com/accounts/oauthgetrequesttoken"; + } + + @Override + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { + return String.format(AUTHORIZE_URL, requestToken.getToken()); + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return OAuth1AccessTokenJSONExtractor.instance(); + } + + @Override + public TokenExtractor getRequestTokenExtractor() { + return OAuth1RequestTokenJSONExtractor.instance(); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1AccessUcozTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1AccessUcozTokenExtractor.java deleted file mode 100644 index bc155710e..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1AccessUcozTokenExtractor.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.scribejava.apis.ucoz; - -import com.github.scribejava.core.model.OAuth1AccessToken; - -public class OAuth1AccessUcozTokenExtractor extends AbstractOauth1UcozTokenExtractor { - - protected OAuth1AccessUcozTokenExtractor() { - } - - @Override - protected OAuth1AccessToken createToken(String token, String secret, String response) { - return new OAuth1AccessToken(token, secret, response); - } - - private static class InstanceHolder { - - private static final OAuth1AccessUcozTokenExtractor INSTANCE = new OAuth1AccessUcozTokenExtractor(); - } - - public static OAuth1AccessUcozTokenExtractor instance() { - return OAuth1AccessUcozTokenExtractor.InstanceHolder.INSTANCE; - } -} \ No newline at end of file diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1RequestUcozTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1RequestUcozTokenExtractor.java deleted file mode 100644 index c615fb840..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/OAuth1RequestUcozTokenExtractor.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.scribejava.apis.ucoz; - -import com.github.scribejava.core.model.OAuth1RequestToken; - -public class OAuth1RequestUcozTokenExtractor extends AbstractOauth1UcozTokenExtractor { - - protected OAuth1RequestUcozTokenExtractor() { - } - - @Override - protected OAuth1RequestToken createToken(String token, String secret, String response) { - return new OAuth1RequestToken(token, secret, response); - } - - private static class InstanceHolder { - - private static final OAuth1RequestUcozTokenExtractor INSTANCE = new OAuth1RequestUcozTokenExtractor(); - } - - public static OAuth1RequestUcozTokenExtractor instance() { - return InstanceHolder.INSTANCE; - } -} \ No newline at end of file diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java index f2156dfc9..04dfaacf4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java @@ -1,81 +1,60 @@ -package com.github.scribejava.apis.examples; - -import com.github.scribejava.apis.UcozApi; -import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.core.model.*; -import com.github.scribejava.core.oauth.OAuth10aService; - -import java.io.IOException; -import java.util.Scanner; -import java.util.concurrent.ExecutionException; - -public class UcozExample { - public static void main(String ...args){ - String PROTECTED_RESOURCE_URL ="http://artmurka.com/uapi/shop/request?page=categories"; - OAuth10aService service = new ServiceBuilder( "your_api_key") - .apiSecret("your_api_secret") - .debug() - .build(UcozApi.instance()); - Scanner in = new Scanner(System.in); - OAuth1RequestToken requestToken = null; - try { - requestToken = service.getRequestToken(); - } catch (IOException e) { - e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (ExecutionException e) { - e.printStackTrace(); - } - System.out.println("Got the Request Token!"); - System.out.println(); - - System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(service.getAuthorizationUrl(requestToken)); - System.out.println("And paste the verifier here"); - System.out.print(">>"); - final String oauthVerifier = in.nextLine(); - System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - OAuth1AccessToken accessToken = null; - try { - accessToken = service.getAccessToken(requestToken, oauthVerifier); - } catch (IOException e) { - e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (ExecutionException e) { - e.printStackTrace(); - } - System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - Response response = null; - try { - response = service.execute(request); - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (ExecutionException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - try { - System.out.println(response.getBody()); - } catch (IOException e) { - e.printStackTrace(); - } - System.out.println(); - System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); - } -} +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.UcozApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth10aService; + +import java.io.IOException; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public class UcozExample { + + private static final String PROTECTED_RESOURCE_URL = "http://artmurka.com/uapi/shop/request?page=categories"; + + private UcozExample() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + final OAuth10aService service = new ServiceBuilder("your_api_key") + .apiSecret("your_api_secret") + .debug() + .build(UcozApi.instance()); + final Scanner in = new Scanner(System.in); + final OAuth1RequestToken requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + final String oauthVerifier = in.nextLine(); + System.out.println(); + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java index d16b714d8..598d25c64 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java @@ -14,7 +14,7 @@ import org.asynchttpclient.DefaultAsyncHttpClient; import org.asynchttpclient.DefaultAsyncHttpClientConfig; -public final class VkontakteExternalHttpExample { +public class VkontakteExternalHttpExample { private static final String NETWORK_NAME = "Vkontakte.ru"; private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/users.get"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index 581600a3b..3e8802fa8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class YahooExample { +public class YahooExample { private static final String PROTECTED_RESOURCE_URL = "http://social.yahooapis.com/v1/user/A6ROU63MXWDCW3Y5MGCYWVHDJI/profile/status?format=json"; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/AbstractOauth1UcozTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java similarity index 66% rename from scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/AbstractOauth1UcozTokenExtractor.java rename to scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java index 14a76dd75..16f684855 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ucoz/AbstractOauth1UcozTokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java @@ -1,41 +1,40 @@ -package com.github.scribejava.apis.ucoz; - -import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth1Token; -import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.utils.OAuthEncoder; -import com.github.scribejava.core.utils.Preconditions; - -import java.io.IOException; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - - -public abstract class AbstractOauth1UcozTokenExtractor implements TokenExtractor { - - private Pattern OAUTH_TOKEN_PATTERN = Pattern.compile("\"oauth_token\"\\s*:\\s*\"(\\S*?)\""); - private Pattern OAUTH_TOKEN_SECRET_PATTERN = Pattern.compile("\"oauth_token_secret\"\\s*:\\s*\"(\\S*?)\""); - - @Override - public T extract(Response response) throws IOException { - final String body = response.getBody(); - Preconditions.checkEmptyString(body, - "Response body is incorrect. " + "Can't extract a token from an empty string"); - final String token = extract(body, OAUTH_TOKEN_PATTERN); - final String secret = extract(body, OAUTH_TOKEN_SECRET_PATTERN); - return createToken(token, secret, body); - } - - private String extract(String response, Pattern p) { - final Matcher matcher = p.matcher(response); - if (matcher.find() && matcher.groupCount() >= 1) { - return OAuthEncoder.decode(matcher.group(1)); - } else { - throw new OAuthException("Response body is incorrect. Can't extract token and secret from this: '" - + response + "'", null); - } - } - - protected abstract T createToken(String token, String secret, String response); -} +package com.github.scribejava.core.extractors; + +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.model.OAuth1Token; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.utils.OAuthEncoder; +import com.github.scribejava.core.utils.Preconditions; + +import java.io.IOException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + + +public abstract class AbstractOAuth1JSONTokenExtractor implements TokenExtractor { + + private static final Pattern OAUTH_TOKEN_PATTERN = Pattern.compile("\"oauth_token\"\\s*:\\s*\"(\\S*?)\""); + private static final Pattern OAUTH_TOKEN_SECRET_PATTERN + = Pattern.compile("\"oauth_token_secret\"\\s*:\\s*\"(\\S*?)\""); + + @Override + public T extract(Response response) throws IOException { + final String body = response.getBody(); + Preconditions.checkEmptyString(body, "Response body is incorrect. Can't extract a token from an empty string"); + final String token = extract(body, OAUTH_TOKEN_PATTERN); + final String secret = extract(body, OAUTH_TOKEN_SECRET_PATTERN); + return createToken(token, secret, body); + } + + private String extract(String response, Pattern p) { + final Matcher matcher = p.matcher(response); + if (matcher.find() && matcher.groupCount() >= 1) { + return OAuthEncoder.decode(matcher.group(1)); + } else { + throw new OAuthException("Response body is incorrect. Can't extract token and secret from this: '" + + response + '\'', null); + } + } + + protected abstract T createToken(String token, String secret, String response); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1AccessTokenJSONExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1AccessTokenJSONExtractor.java new file mode 100644 index 000000000..9267f80b4 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1AccessTokenJSONExtractor.java @@ -0,0 +1,23 @@ +package com.github.scribejava.core.extractors; + +import com.github.scribejava.core.model.OAuth1AccessToken; + +public class OAuth1AccessTokenJSONExtractor extends AbstractOAuth1JSONTokenExtractor { + + protected OAuth1AccessTokenJSONExtractor() { + } + + @Override + protected OAuth1AccessToken createToken(String token, String secret, String response) { + return new OAuth1AccessToken(token, secret, response); + } + + private static class InstanceHolder { + + private static final OAuth1AccessTokenJSONExtractor INSTANCE = new OAuth1AccessTokenJSONExtractor(); + } + + public static OAuth1AccessTokenJSONExtractor instance() { + return InstanceHolder.INSTANCE; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1RequestTokenJSONExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1RequestTokenJSONExtractor.java new file mode 100644 index 000000000..875337a82 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth1RequestTokenJSONExtractor.java @@ -0,0 +1,23 @@ +package com.github.scribejava.core.extractors; + +import com.github.scribejava.core.model.OAuth1RequestToken; + +public class OAuth1RequestTokenJSONExtractor extends AbstractOAuth1JSONTokenExtractor { + + protected OAuth1RequestTokenJSONExtractor() { + } + + @Override + protected OAuth1RequestToken createToken(String token, String secret, String response) { + return new OAuth1RequestToken(token, secret, response); + } + + private static class InstanceHolder { + + private static final OAuth1RequestTokenJSONExtractor INSTANCE = new OAuth1RequestTokenJSONExtractor(); + } + + public static OAuth1RequestTokenJSONExtractor instance() { + return InstanceHolder.INSTANCE; + } +} From 523769736fb350efd9c3db9a3a48cfe1785dd5ce Mon Sep 17 00:00:00 2001 From: Vivin Paliath Date: Thu, 31 Aug 2017 15:44:04 -0700 Subject: [PATCH 010/481] issue #793 Adds support for retrieving an access token using client-credentials grant. --- .../scribejava/core/model/OAuthConstants.java | 1 + .../scribejava/core/oauth/OAuth20Service.java | 67 +++++++++++++++---- 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java index 2cf8d236a..4f79cd355 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java @@ -32,6 +32,7 @@ public interface OAuthConstants { String REFRESH_TOKEN = "refresh_token"; String GRANT_TYPE = "grant_type"; String AUTHORIZATION_CODE = "authorization_code"; + String CLIENT_CREDENTIALS = "client_credentials"; String STATE = "state"; String USERNAME = "username"; String PASSWORD = "password"; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 803e6fa80..b6fd25882 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -92,37 +92,44 @@ protected OAuthRequest createAccessTokenRequest(String code) { return request; } - public final Future refreshAccessTokenAsync(String refreshToken) { - return refreshAccessToken(refreshToken, null); + public final Future getAccessTokenClientCredentialsGrantAsync() { + return getAccessTokenClientCredentialsGrant(null); } - public final OAuth2AccessToken refreshAccessToken(String refreshToken) + public final OAuth2AccessToken getAccessTokenClientCredentialsGrant() throws IOException, InterruptedException, ExecutionException { - final OAuthRequest request = createRefreshTokenRequest(refreshToken); + final OAuthRequest request = createAccessTokenClientCredentialsGrantRequest(); return sendAccessTokenRequestSync(request); } - public final Future refreshAccessToken(String refreshToken, + /** + * Start the request to retrieve the access token using client-credentials grant. The optionally provided callback + * will be called with the Token when it is available. + * + * @param callback optional callback + * @return Future + */ + public final Future getAccessTokenClientCredentialsGrant( OAuthAsyncRequestCallback callback) { - final OAuthRequest request = createRefreshTokenRequest(refreshToken); + final OAuthRequest request = createAccessTokenClientCredentialsGrantRequest(); return sendAccessTokenRequestAsync(request, callback); } - protected OAuthRequest createRefreshTokenRequest(String refreshToken) { - if (refreshToken == null || refreshToken.isEmpty()) { - throw new IllegalArgumentException("The refreshToken cannot be null or empty"); - } - final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint()); + protected OAuthRequest createAccessTokenClientCredentialsGrantRequest() { + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); final OAuthConfig config = getConfig(); request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); final String apiSecret = config.getApiSecret(); if (apiSecret != null) { request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); } - request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); - request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); + final String scope = config.getScope(); + if (scope != null) { + request.addParameter(OAuthConstants.SCOPE, scope); + } + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.CLIENT_CREDENTIALS); return request; } @@ -177,6 +184,40 @@ protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, St return request; } + public final Future refreshAccessTokenAsync(String refreshToken) { + return refreshAccessToken(refreshToken, null); + } + + public final OAuth2AccessToken refreshAccessToken(String refreshToken) + throws IOException, InterruptedException, ExecutionException { + final OAuthRequest request = createRefreshTokenRequest(refreshToken); + + return sendAccessTokenRequestSync(request); + } + + public final Future refreshAccessToken(String refreshToken, + OAuthAsyncRequestCallback callback) { + final OAuthRequest request = createRefreshTokenRequest(refreshToken); + + return sendAccessTokenRequestAsync(request, callback); + } + + protected OAuthRequest createRefreshTokenRequest(String refreshToken) { + if (refreshToken == null || refreshToken.isEmpty()) { + throw new IllegalArgumentException("The refreshToken cannot be null or empty"); + } + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint()); + final OAuthConfig config = getConfig(); + request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); + final String apiSecret = config.getApiSecret(); + if (apiSecret != null) { + request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); + } + request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); + return request; + } + /** * {@inheritDoc} */ From f296c750a0f11b4ec9c7dc1d355c5fc025ac325a Mon Sep 17 00:00:00 2001 From: Stephan Date: Sat, 30 Sep 2017 10:15:23 +1000 Subject: [PATCH 011/481] Apache http client integration --- pom.xml | 1 + scribejava-core/pom.xml | 16 ++ .../scribejava/core/AbstractClientTest.java | 178 ++++++++++++++++++ scribejava-httpclient-ahc/pom.xml | 13 ++ .../httpclient/ahc/AhcHttpClientTest.java | 12 ++ scribejava-httpclient-apache/pom.xml | 60 ++++++ .../httpclient/apache/ApacheHttpClient.java | 109 +++++++++++ .../apache/ApacheHttpClientConfig.java | 15 ++ .../httpclient/apache/ApacheHttpFuture.java | 44 +++++ .../httpclient/apache/ApacheProvider.java | 16 ++ .../apache/OAuthAsyncCompletionHandler.java | 95 ++++++++++ .../apache/ApacheHttpClientTest.java | 13 ++ .../OauthAsyncCompletionHandlerTest.java | 128 +++++++++++++ scribejava-httpclient-ning/pom.xml | 13 ++ .../httpclient/ning/NingHttpClientTest.java | 13 ++ scribejava-httpclient-okhttp/pom.xml | 7 + .../okhttp/OkHttpHttpClientTest.java | 109 +---------- 17 files changed, 738 insertions(+), 104 deletions(-) create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java create mode 100644 scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java create mode 100644 scribejava-httpclient-apache/pom.xml create mode 100644 scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java create mode 100644 scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClientConfig.java create mode 100644 scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpFuture.java create mode 100644 scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheProvider.java create mode 100644 scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java create mode 100644 scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/ApacheHttpClientTest.java create mode 100644 scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java create mode 100644 scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/NingHttpClientTest.java diff --git a/pom.xml b/pom.xml index 7b8520909..eaf094176 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,7 @@ scribejava-httpclient-ahc scribejava-httpclient-ning scribejava-httpclient-okhttp + scribejava-httpclient-apache diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index e2355021b..460316e5d 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -14,6 +14,15 @@ ScribeJava Core jar + + + com.squareup.okhttp3 + mockwebserver + 3.8.1 + test + + + @@ -23,6 +32,13 @@ org.apache.maven.plugins maven-jar-plugin + + + + test-jar + + + diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java new file mode 100644 index 000000000..0df7c6ad8 --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java @@ -0,0 +1,178 @@ +package com.github.scribejava.core; + +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.core.oauth.OAuthService; +import com.github.scribejava.core.utils.StreamUtils; +import okhttp3.HttpUrl; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertEquals; + +public abstract class AbstractClientTest { + + class TestCallback implements OAuthAsyncRequestCallback { + + private Throwable throwable; + private T response; + + @Override + public void onCompleted(T response) { + this.response = response; + } + + @Override + public void onThrowable(Throwable throwable) { + this.throwable = throwable; + } + } + + private OAuthService oAuthService; + private HttpClient client; + + @Before + public void setUp() { + client = createNewClient(); + oAuthService = new OAuth20Service(null, + new OAuthConfig("test", "test", null, null, null, null, null, null, null, client)); + } + + @After + public void shutDown() throws IOException { + client.close(); + } + + protected abstract HttpClient createNewClient(); + + @Test + public void shouldSendGetRequest() throws Exception { + final String expectedResponseBody = "response body"; + + final MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString()); + final Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); + + assertEquals(expectedResponseBody, response.getBody()); + + final RecordedRequest recordedRequest = server.takeRequest(); + assertEquals("GET", recordedRequest.getMethod()); + + server.shutdown(); + } + + @Test + public void shouldSendPostRequest() throws Exception { + final String expectedResponseBody = "response body"; + final String expectedRequestBody = "request body"; + + final MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + // request with body + OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); + request.setPayload(expectedRequestBody); + Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); + + assertEquals(expectedResponseBody, response.getBody()); + + RecordedRequest recordedRequest = server.takeRequest(); + assertEquals("POST", recordedRequest.getMethod()); + assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + + + // request with empty body + request = new OAuthRequest(Verb.POST, baseUrl.toString()); + response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); + + assertEquals(expectedResponseBody, response.getBody()); + + recordedRequest = server.takeRequest(); + assertEquals("POST", recordedRequest.getMethod()); + assertEquals("", recordedRequest.getBody().readUtf8()); + + server.shutdown(); + } + + @Test + public void shouldReadResponseStream() throws Exception { + final String expectedResponseBody = "response body"; + + final MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString()); + final Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); + + assertEquals(expectedResponseBody, StreamUtils.getStreamContents(response.getStream())); + + final RecordedRequest recordedRequest = server.takeRequest(); + assertEquals("GET", recordedRequest.getMethod()); + + server.shutdown(); + } + + @Test + public void shouldCallCallback() throws Exception { + final String expectedResponseBody = "response body"; + + final MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString()); + + final TestCallback callback = new TestCallback<>(); + oAuthService.execute(request, callback).get(); + + assertEquals(expectedResponseBody, callback.response.getBody()); + + server.shutdown(); + } + + @Test + public void shouldPassErrors() throws Exception { + + final MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setResponseCode(500)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString()); + + final TestCallback callback = new TestCallback<>(); + final Response response = oAuthService.execute(request, callback).get(); + + assertEquals(500, response.getCode()); + assertEquals(500, callback.response.getCode()); + + server.shutdown(); + } +} diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 02eb03fe0..b312e65e2 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -25,6 +25,19 @@ async-http-client 2.0.33 + + com.github.scribejava + scribejava-core + ${project.version} + test-jar + test + + + com.squareup.okhttp3 + mockwebserver + 3.8.1 + test + diff --git a/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java b/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java new file mode 100644 index 000000000..34d940205 --- /dev/null +++ b/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java @@ -0,0 +1,12 @@ +package com.github.scribejava.httpclient.ahc; + +import com.github.scribejava.core.AbstractClientTest; +import com.github.scribejava.core.httpclient.HttpClient; + +public class AhcHttpClientTest extends AbstractClientTest { + + @Override + protected HttpClient createNewClient() { + return new AhcHttpClient(AhcHttpClientConfig.defaultConfig()); + } +} diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml new file mode 100644 index 000000000..6ce5a545a --- /dev/null +++ b/scribejava-httpclient-apache/pom.xml @@ -0,0 +1,60 @@ + + + 4.0.0 + + + com.github.scribejava + scribejava + 4.2.1-SNAPSHOT + ../pom.xml + + + com.github.scribejava + scribejava-httpclient-apache + ScribeJava Apache Http Client support + jar + + + + com.github.scribejava + scribejava-core + ${project.version} + + + org.apache.httpcomponents + httpclient + 4.5.2 + + + org.apache.httpcomponents + httpasyncclient + 4.1.3 + + + com.github.scribejava + scribejava-core + ${project.version} + test-jar + test + + + com.squareup.okhttp3 + mockwebserver + 3.8.1 + test + + + + + + + org.apache.felix + maven-bundle-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + + diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java new file mode 100644 index 000000000..db6c8e48f --- /dev/null +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java @@ -0,0 +1,109 @@ +package com.github.scribejava.httpclient.apache; + +import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Verb; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.RequestBuilder; +import org.apache.http.entity.ByteArrayEntity; +import org.apache.http.entity.FileEntity; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; +import org.apache.http.impl.nio.client.HttpAsyncClients; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Map; +import java.util.concurrent.Future; + +public class ApacheHttpClient extends AbstractAsyncOnlyHttpClient { + + private final CloseableHttpAsyncClient client; + + public ApacheHttpClient() { + this(HttpAsyncClients.createDefault()); + } + + public ApacheHttpClient(CloseableHttpAsyncClient client) { + this.client = client; + this.client.start(); + } + + @Override + public void close() throws IOException { + client.close(); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + final HttpEntity entity = bodyContents == null ? null : new ByteArrayEntity(bodyContents); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, entity, callback, converter); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + final HttpEntity entity = bodyContents == null ? null : new StringEntity(bodyContents, StandardCharsets.UTF_8); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, entity, callback, converter); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + final HttpEntity entity = bodyContents == null ? null : new FileEntity(bodyContents); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, entity, callback, converter); + } + + private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, HttpEntity entity, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + final RequestBuilder builder = getRequestBuilder(httpVerb); + builder.setUri(completeUrl); + + if (httpVerb.isPermitBody()) { + if (!headers.containsKey(CONTENT_TYPE)) { + builder.addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + } + builder.setEntity(entity); + } + + for (Map.Entry header : headers.entrySet()) { + builder.addHeader(header.getKey(), header.getValue()); + } + + if (userAgent != null) { + builder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); + } + final OAuthAsyncCompletionHandler handler = new OAuthAsyncCompletionHandler<>(callback, converter); + final Future future = client.execute(builder.build(), handler); + return new ApacheHttpFuture<>(future, handler); + } + + private RequestBuilder getRequestBuilder(Verb httpVerb) { + switch (httpVerb) { + case GET: + return RequestBuilder.get(); + case PUT: + return RequestBuilder.put(); + case DELETE: + return RequestBuilder.delete(); + case HEAD: + return RequestBuilder.head(); + case POST: + return RequestBuilder.post(); + case PATCH: + return RequestBuilder.patch(); + case TRACE: + return RequestBuilder.trace(); + case OPTIONS: + return RequestBuilder.options(); + default: + throw new IllegalArgumentException("message build error: unknown verb type"); + } + } +} diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClientConfig.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClientConfig.java new file mode 100644 index 000000000..5ff523431 --- /dev/null +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClientConfig.java @@ -0,0 +1,15 @@ +package com.github.scribejava.httpclient.apache; + +import com.github.scribejava.core.httpclient.HttpClientConfig; + +public class ApacheHttpClientConfig implements HttpClientConfig { + + @Override + public HttpClientConfig createDefaultConfig() { + return defaultConfig(); + } + + public static ApacheHttpClientConfig defaultConfig() { + return new ApacheHttpClientConfig(); + } +} diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpFuture.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpFuture.java new file mode 100644 index 000000000..47c098383 --- /dev/null +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpFuture.java @@ -0,0 +1,44 @@ +package com.github.scribejava.httpclient.apache; + +import org.apache.http.HttpResponse; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class ApacheHttpFuture implements Future { + + private final Future future; + private final OAuthAsyncCompletionHandler handler; + + public ApacheHttpFuture(Future future, OAuthAsyncCompletionHandler handler) { + this.future = future; + this.handler = handler; + } + + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + return future.cancel(mayInterruptIfRunning); + } + + @Override + public boolean isCancelled() { + return future.isCancelled(); + } + + @Override + public boolean isDone() { + return future.isDone(); + } + + @Override + public T get() throws InterruptedException, ExecutionException { + return handler.getResult(); + } + + @Override + public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { + return handler.getResult(timeout, unit); + } +} diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheProvider.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheProvider.java new file mode 100644 index 000000000..ed8efcf68 --- /dev/null +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheProvider.java @@ -0,0 +1,16 @@ +package com.github.scribejava.httpclient.apache; + +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.httpclient.HttpClientProvider; + +public class ApacheProvider implements HttpClientProvider { + + @Override + public HttpClient createClient(HttpClientConfig httpClientConfig) { + if (httpClientConfig instanceof ApacheHttpClientConfig) { + return new ApacheHttpClient(); + } + return null; + } +} diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java new file mode 100644 index 000000000..e63f17179 --- /dev/null +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java @@ -0,0 +1,95 @@ +package com.github.scribejava.httpclient.apache; + +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthRequest.ResponseConverter; +import com.github.scribejava.core.model.Response; +import org.apache.http.Header; +import org.apache.http.HttpResponse; +import org.apache.http.concurrent.FutureCallback; + +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.CancellationException; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class OAuthAsyncCompletionHandler implements FutureCallback { + + private final ResponseConverter converter; + private final OAuthAsyncRequestCallback callback; + private final CountDownLatch latch; + private T result; + private Exception exception; + + public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, ResponseConverter converter) { + this.converter = converter; + this.callback = callback; + this.latch = new CountDownLatch(1); + } + + @Override + public void completed(HttpResponse httpResponse) { + try { + final Map headersMap = Stream.of(httpResponse.getAllHeaders()) + .collect(Collectors.toMap(Header::getName, Header::getValue)); + final Response response = new Response(httpResponse.getStatusLine().getStatusCode(), + httpResponse.getStatusLine().getReasonPhrase(), headersMap, httpResponse.getEntity().getContent()); + @SuppressWarnings("unchecked") + final T t = converter == null ? (T) response : converter.convert(response); + result = t; + if (callback != null) { + callback.onCompleted(result); + } + } catch (IOException e) { + exception = e; + if (callback != null) { + callback.onThrowable(e); + } + } finally { + latch.countDown(); + } + } + + @Override + public void failed(Exception e) { + exception = e; + try { + if (callback != null) { + callback.onThrowable(e); + } + } finally { + latch.countDown(); + } + } + + @Override + public void cancelled() { + exception = new CancellationException(); + try { + if (callback != null) { + callback.onThrowable(exception); + } + } finally { + latch.countDown(); + } + } + + public T getResult() throws InterruptedException, ExecutionException { + latch.await(); + if (exception != null) { + throw new ExecutionException(exception); + } + return result; + } + + public T getResult(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException { + latch.await(timeout, unit); + if (exception != null) { + throw new ExecutionException(exception); + } + return result; + } +} diff --git a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/ApacheHttpClientTest.java b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/ApacheHttpClientTest.java new file mode 100644 index 000000000..03924d81e --- /dev/null +++ b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/ApacheHttpClientTest.java @@ -0,0 +1,13 @@ +package com.github.scribejava.httpclient.apache; + +import com.github.scribejava.core.AbstractClientTest; +import com.github.scribejava.core.httpclient.HttpClient; + +public class ApacheHttpClientTest extends AbstractClientTest { + + @Override + protected HttpClient createNewClient() { + return new ApacheHttpClient(); + } + +} diff --git a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java new file mode 100644 index 000000000..f0309a173 --- /dev/null +++ b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java @@ -0,0 +1,128 @@ +package com.github.scribejava.httpclient.apache; + +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import org.apache.http.HttpResponse; +import org.apache.http.ProtocolVersion; +import org.apache.http.entity.BasicHttpEntity; +import org.apache.http.message.BasicHttpResponse; +import org.apache.http.message.BasicStatusLine; +import org.junit.Before; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.concurrent.CancellationException; +import java.util.concurrent.ExecutionException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class OauthAsyncCompletionHandlerTest { + + private OAuthAsyncCompletionHandler handler; + private TestCallback callback; + + class TestCallback implements OAuthAsyncRequestCallback { + + private Throwable throwable; + private String response; + + @Override + public void onCompleted(String response) { + this.response = response; + } + + @Override + public void onThrowable(Throwable throwable) { + this.throwable = throwable; + } + } + + @Before + public void setUp() { + callback = new TestCallback(); + } + + @Test + public void shouldReleaseLatchOnSuccess() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, response -> "All good"); + final HttpResponse response = new BasicHttpResponse(new BasicStatusLine( + new ProtocolVersion("4", 1, 1), 200, "ok")); + final BasicHttpEntity entity = new BasicHttpEntity(); + entity.setContent(new ByteArrayInputStream(new byte[0])); + response.setEntity(entity); + handler.completed(response); + assertNotNull(callback.response); + assertNull(callback.throwable); + // verify latch is released + assertEquals("All good", handler.getResult()); + } + + @Test + public void shouldReleaseLatchOnIOException() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, response -> { + throw new IOException("Failed to convert"); + }); + final HttpResponse response = new BasicHttpResponse(new BasicStatusLine( + new ProtocolVersion("4", 1, 1), 200, "ok")); + final BasicHttpEntity entity = new BasicHttpEntity(); + entity.setContent(new ByteArrayInputStream(new byte[0])); + response.setEntity(entity); + handler.completed(response); + assertNull(callback.response); + assertNotNull(callback.throwable); + assertTrue(callback.throwable instanceof IOException); + // verify latch is released + try { + handler.getResult(); + fail(); + } catch (ExecutionException expected) { + // expected + } + } + + @Test + public void shouldReleaseLatchOnCancel() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, response -> "All good"); + final HttpResponse response = new BasicHttpResponse(new BasicStatusLine( + new ProtocolVersion("4", 1, 1), 200, "ok")); + final BasicHttpEntity entity = new BasicHttpEntity(); + entity.setContent(new ByteArrayInputStream(new byte[0])); + response.setEntity(entity); + handler.cancelled(); + assertNull(callback.response); + assertNotNull(callback.throwable); + assertTrue(callback.throwable instanceof CancellationException); + // verify latch is released + try { + handler.getResult(); + fail(); + } catch (ExecutionException expected) { + // expected + } + } + + @Test + public void shouldReleaseLatchOnFailure() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, response -> "All good"); + final HttpResponse response = new BasicHttpResponse(new BasicStatusLine( + new ProtocolVersion("4", 1, 1), 200, "ok")); + final BasicHttpEntity entity = new BasicHttpEntity(); + entity.setContent(new ByteArrayInputStream(new byte[0])); + response.setEntity(entity); + handler.failed(new RuntimeException()); + assertNull(callback.response); + assertNotNull(callback.throwable); + assertTrue(callback.throwable instanceof RuntimeException); + // verify latch is released + try { + handler.getResult(); + fail(); + } catch (ExecutionException expected) { + // expected + } + } +} diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 0142e94c0..1d1673810 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -25,6 +25,19 @@ async-http-client 1.9.40 + + com.github.scribejava + scribejava-core + ${project.version} + test-jar + test + + + com.squareup.okhttp3 + mockwebserver + 3.8.1 + test + diff --git a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/NingHttpClientTest.java b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/NingHttpClientTest.java new file mode 100644 index 000000000..8155cebf7 --- /dev/null +++ b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/NingHttpClientTest.java @@ -0,0 +1,13 @@ +package com.github.scribejava.httpclient.ning; + +import com.github.scribejava.core.AbstractClientTest; +import com.github.scribejava.core.httpclient.HttpClient; +import com.ning.http.client.AsyncHttpClient; + +public class NingHttpClientTest extends AbstractClientTest { + + @Override + protected HttpClient createNewClient() { + return new NingHttpClient(new AsyncHttpClient()); + } +} diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 12e034874..f581e55de 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -31,6 +31,13 @@ 3.8.1 test + + com.github.scribejava + scribejava-core + ${project.version} + test-jar + test + diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java index 496882cdd..1bc31919b 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java @@ -1,112 +1,13 @@ package com.github.scribejava.httpclient.okhttp; +import com.github.scribejava.core.AbstractClientTest; import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuth20Service; -import com.github.scribejava.core.oauth.OAuthService; -import com.github.scribejava.core.utils.StreamUtils; -import okhttp3.HttpUrl; import okhttp3.OkHttpClient; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import okhttp3.mockwebserver.RecordedRequest; -import org.junit.Before; -import org.junit.Test; -import java.util.concurrent.TimeUnit; +public class OkHttpHttpClientTest extends AbstractClientTest { -import static org.junit.Assert.assertEquals; - -public class OkHttpHttpClientTest { - private OAuthService oAuthService; - - @Before - public void setUp() { - final HttpClient client = new OkHttpHttpClient(new OkHttpClient()); - oAuthService = new OAuth20Service(null, - new OAuthConfig("test", "test", null, null, null, null, null, null, null, client)); - } - - - @Test - public void shouldSendGetRequest() throws Exception { - final String expectedResponseBody = "response body"; - - final MockWebServer server = new MockWebServer(); - server.enqueue(new MockResponse().setBody(expectedResponseBody)); - server.start(); - - final HttpUrl baseUrl = server.url("/testUrl"); - - final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString()); - final Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); - - assertEquals(expectedResponseBody, response.getBody()); - - final RecordedRequest recordedRequest = server.takeRequest(); - assertEquals("GET", recordedRequest.getMethod()); - - server.shutdown(); - } - - @Test - public void shouldSendPostRequest() throws Exception { - final String expectedResponseBody = "response body"; - final String expectedRequestBody = "request body"; - - final MockWebServer server = new MockWebServer(); - server.enqueue(new MockResponse().setBody(expectedResponseBody)); - server.enqueue(new MockResponse().setBody(expectedResponseBody)); - server.start(); - - final HttpUrl baseUrl = server.url("/testUrl"); - - // request with body - OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); - request.setPayload(expectedRequestBody); - Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); - - assertEquals(expectedResponseBody, response.getBody()); - - RecordedRequest recordedRequest = server.takeRequest(); - assertEquals("POST", recordedRequest.getMethod()); - assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); - - - // request with empty body - request = new OAuthRequest(Verb.POST, baseUrl.toString()); - response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); - - assertEquals(expectedResponseBody, response.getBody()); - - recordedRequest = server.takeRequest(); - assertEquals("POST", recordedRequest.getMethod()); - assertEquals("", recordedRequest.getBody().readUtf8()); - - server.shutdown(); - } - - @Test - public void shouldReadResponseStream() throws Exception { - final String expectedResponseBody = "response body"; - - final MockWebServer server = new MockWebServer(); - server.enqueue(new MockResponse().setBody(expectedResponseBody)); - server.start(); - - final HttpUrl baseUrl = server.url("/testUrl"); - - final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString()); - final Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); - - assertEquals(expectedResponseBody, StreamUtils.getStreamContents(response.getStream())); - - final RecordedRequest recordedRequest = server.takeRequest(); - assertEquals("GET", recordedRequest.getMethod()); - - server.shutdown(); + @Override + protected HttpClient createNewClient() { + return new OkHttpHttpClient(new OkHttpClient()); } } From 5ee2173fbe4feeab5d5fd93d3b455e9f66771f21 Mon Sep 17 00:00:00 2001 From: Stephan Date: Sun, 1 Oct 2017 18:06:18 +1100 Subject: [PATCH 012/481] Added tests for JDKHttpClient, fixed bug --- .../core/httpclient/jdk/JDKHttpClient.java | 18 ++++++++++++------ .../core/httpclient/jdk/JDKHttpClientTest.java | 12 ++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 8a6f3e516..d02dc5e8b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -33,9 +33,13 @@ public void close() throws IOException { public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { try { - final T response = converter.convert(execute(userAgent, headers, httpVerb, completeUrl, bodyContents)); - callback.onCompleted(response); - return new JDKHttpFuture<>(response); + final Response response = execute(userAgent, headers, httpVerb, completeUrl, bodyContents); + @SuppressWarnings("unchecked") + final T t = converter == null ? (T) response : converter.convert(response); + if (callback != null) { + callback.onCompleted(t); + } + return new JDKHttpFuture<>(t); } catch (InterruptedException | ExecutionException | IOException e) { callback.onThrowable(e); return new JDKHttpFuture<>(e); @@ -46,11 +50,13 @@ public Future executeAsync(String userAgent, Map headers, public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { try { - final T response = converter.convert(execute(userAgent, headers, httpVerb, completeUrl, bodyContents)); + final Response response = execute(userAgent, headers, httpVerb, completeUrl, bodyContents); + @SuppressWarnings("unchecked") + final T t = converter == null ? (T) response : converter.convert(response); if (callback != null) { - callback.onCompleted(response); + callback.onCompleted(t); } - return new JDKHttpFuture<>(response); + return new JDKHttpFuture<>(t); } catch (InterruptedException | ExecutionException | IOException e) { if (callback != null) { callback.onThrowable(e); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java new file mode 100644 index 000000000..09d34f0c3 --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java @@ -0,0 +1,12 @@ +package com.github.scribejava.core.httpclient.jdk; + +import com.github.scribejava.core.AbstractClientTest; +import com.github.scribejava.core.httpclient.HttpClient; + +public class JDKHttpClientTest extends AbstractClientTest { + + @Override + protected HttpClient createNewClient() { + return new JDKHttpClient(JDKHttpClientConfig.defaultConfig()); + } +} From 8d62f0cace86975a95c382fbf3176cbbf3881748 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 3 Nov 2017 16:30:02 +0300 Subject: [PATCH 013/481] add PKCE (RFC 7636) support (Proof Key for Code Exchange by OAuth Public Clients) (thanks for suggesting to https://github.com/dieseldjango) --- changelog | 1 + .../examples/Google20WithPKCEExample.java | 115 ++++++++++++++++++ .../core/oauth/OAuth10aService.java | 2 - .../scribejava/core/oauth/OAuth20Service.java | 77 ++++++++++-- .../core/pkce/AuthorizationUrlWithPKCE.java | 21 ++++ .../com/github/scribejava/core/pkce/PKCE.java | 49 ++++++++ .../core/pkce/PKCECodeChallengeMethod.java | 27 ++++ .../scribejava/core/pkce/PKCEService.java | 54 ++++++++ .../core/services/Base64Encoder.java | 15 +-- .../core/services/CommonsEncoder.java | 4 + .../services/DatatypeConverterEncoder.java | 4 + .../services/HMACSha1SignatureService.java | 6 +- .../services/RSASha1SignatureService.java | 6 +- .../core/services/SignatureService.java | 3 + .../pkce/PKCECodeChallengeMethodTest.java | 26 ++++ 15 files changed, 379 insertions(+), 31 deletions(-) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCE.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethodTest.java diff --git a/changelog b/changelog index 4ef2ad99c..076c80762 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * drop Java 7 backward compatibility support, become Java 8 only * add JSON token extractor for OAuth 1.0a (thanks to https://github.com/evstropovv) * add new API - uCoz (https://www.ucoz.com/) (thanks to https://github.com/evstropovv) + * add PKCE (RFC 7636) support (Proof Key for Code Exchange by OAuth Public Clients) (thanks for suggesting to https://github.com/dieseldjango) [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java new file mode 100644 index 000000000..91a108cb1 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java @@ -0,0 +1,115 @@ +package com.github.scribejava.apis.examples; + +import java.util.Random; +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.GoogleApi20; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.core.pkce.AuthorizationUrlWithPKCE; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +public final class Google20WithPKCEExample { + + private static final String NETWORK_NAME = "G+"; + private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; + + private Google20WithPKCEExample() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .scope("profile") // replace with desired scope + .state(secretState) + .callback("http://example.com/callback") + .build(GoogleApi20.instance()); + + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + //pass access_type=offline to get refresh token + //https://developers.google.com/identity/protocols/OAuth2WebServer#preparing-to-start-the-oauth-20-flow + final Map additionalParams = new HashMap<>(); + additionalParams.put("access_type", "offline"); + //force to reget refresh token (if usera are asked not the first time) + additionalParams.put("prompt", "consent"); + + final AuthorizationUrlWithPKCE authUrlWithPKCE = service.getAuthorizationUrlWithPKCE(additionalParams); + + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authUrlWithPKCE.getAuthorizationUrl()); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + OAuth2AccessToken accessToken = service.getAccessToken(code, authUrlWithPKCE.getPkce().getCodeVerifier()); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + + System.out.println("Refreshing the Access Token..."); + accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); + System.out.println("Refreshed the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + while (true) { + System.out.println("Paste fieldnames to fetch (leave empty to get profile, 'exit' to stop example)"); + System.out.print(">>"); + final String query = in.nextLine(); + System.out.println(); + + final String requestUrl; + if ("exit".equals(query)) { + break; + } else if (query == null || query.isEmpty()) { + requestUrl = PROTECTED_RESOURCE_URL; + } else { + requestUrl = PROTECTED_RESOURCE_URL + "?fields=" + query; + } + + final OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + } + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index 00be552cb..1023def56 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -11,7 +11,6 @@ import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.services.Base64Encoder; import java.util.concurrent.ExecutionException; /** @@ -157,7 +156,6 @@ public String getAuthorizationUrl(OAuth1RequestToken requestToken) { private String getSignature(OAuthRequest request, String tokenSecret) { final OAuthConfig config = getConfig(); config.log("generating signature..."); - config.log("using base64 encoder: " + Base64Encoder.type()); final String baseString = api.getBaseStringExtractor().extract(request); final String signature = api.getSignatureService().getSignature(baseString, config.getApiSecret(), tokenSecret); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 803e6fa80..5caefdca9 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -1,6 +1,5 @@ package com.github.scribejava.core.oauth; -import com.github.scribejava.core.services.Base64Encoder; import java.io.IOException; import java.nio.charset.Charset; import java.util.concurrent.Future; @@ -11,12 +10,19 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.pkce.AuthorizationUrlWithPKCE; +import com.github.scribejava.core.pkce.PKCE; +import com.github.scribejava.core.pkce.PKCEService; +import java.util.Base64; +import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutionException; public class OAuth20Service extends OAuthService { private static final String VERSION = "2.0"; + private static final Base64.Encoder BASE_64_ENCODER = Base64.getEncoder(); + private static final PKCEService PKCE_SERVICE = new PKCEService(); private final DefaultApi20 api; /** @@ -49,12 +55,21 @@ protected Future sendAccessTokenRequestAsync(OAuthRequest req } public final Future getAccessTokenAsync(String code) { - return getAccessToken(code, null); + return getAccessToken(code, null, null); + } + + public final Future getAccessTokenAsync(String code, String pkceCodeVerifier) { + return getAccessToken(code, null, pkceCodeVerifier); } public final OAuth2AccessToken getAccessToken(String code) throws IOException, InterruptedException, ExecutionException { - final OAuthRequest request = createAccessTokenRequest(code); + return getAccessToken(code, (String) null); + } + + public final OAuth2AccessToken getAccessToken(String code, String pkceCodeVerifier) + throws IOException, InterruptedException, ExecutionException { + final OAuthRequest request = createAccessTokenRequest(code, pkceCodeVerifier); return sendAccessTokenRequestSync(request); } @@ -65,15 +80,22 @@ public final OAuth2AccessToken getAccessToken(String code) * * @param code code * @param callback optional callback + * @param pkceCodeVerifier pkce Code Verifier * @return Future */ public final Future getAccessToken(String code, - OAuthAsyncRequestCallback callback) { - final OAuthRequest request = createAccessTokenRequest(code); + OAuthAsyncRequestCallback callback, String pkceCodeVerifier) { + final OAuthRequest request = createAccessTokenRequest(code, pkceCodeVerifier); return sendAccessTokenRequestAsync(request, callback); } + public final Future getAccessToken(String code, + OAuthAsyncRequestCallback callback) { + + return getAccessToken(code, callback, null); + } + protected OAuthRequest createAccessTokenRequest(String code) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); final OAuthConfig config = getConfig(); @@ -92,6 +114,14 @@ protected OAuthRequest createAccessTokenRequest(String code) { return request; } + protected OAuthRequest createAccessTokenRequest(String code, String pkceCodeVerifier) { + final OAuthRequest request = createAccessTokenRequest(code); + if (pkceCodeVerifier != null) { + request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); + } + return request; + } + public final Future refreshAccessTokenAsync(String refreshToken) { return refreshAccessToken(refreshToken, null); } @@ -168,10 +198,9 @@ protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, St final String apiKey = config.getApiKey(); final String apiSecret = config.getApiSecret(); if (apiKey != null && apiSecret != null) { - request.addHeader(OAuthConstants.HEADER, - OAuthConstants.BASIC + ' ' - + Base64Encoder.getInstance() - .encode(String.format("%s:%s", apiKey, apiSecret).getBytes(Charset.forName("UTF-8")))); + request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + ' ' + + BASE_64_ENCODER.encodeToString( + String.format("%s:%s", apiKey, apiSecret).getBytes(Charset.forName("UTF-8")))); } return request; @@ -190,13 +219,22 @@ public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { api.getSignatureType().signRequest(accessToken, request); } + public final AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE() { + return getAuthorizationUrlWithPKCE(null); + } + + public final AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(Map additionalParams) { + final PKCE pkce = PKCE_SERVICE.generatePKCE(); + return new AuthorizationUrlWithPKCE(pkce, getAuthorizationUrl(additionalParams, pkce)); + } + /** * Returns the URL where you should redirect your users to authenticate your application. * * @return the URL where you should redirect your users */ public final String getAuthorizationUrl() { - return getAuthorizationUrl(null); + return getAuthorizationUrl(null, null); } /** @@ -205,8 +243,23 @@ public final String getAuthorizationUrl() { * @param additionalParams any additional GET params to add to the URL * @return the URL where you should redirect your users */ - public String getAuthorizationUrl(Map additionalParams) { - return api.getAuthorizationUrl(getConfig(), additionalParams); + public final String getAuthorizationUrl(Map additionalParams) { + return getAuthorizationUrl(additionalParams, null); + } + + public final String getAuthorizationUrl(PKCE pkce) { + return getAuthorizationUrl(null, pkce); + } + + public String getAuthorizationUrl(Map additionalParams, PKCE pkce) { + final Map params; + if (pkce == null) { + params = additionalParams; + } else { + params = additionalParams == null ? new HashMap<>() : new HashMap<>(additionalParams); + params.putAll(pkce.getAuthorizationUrlParams()); + } + return api.getAuthorizationUrl(getConfig(), params); } public DefaultApi20 getApi() { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java new file mode 100644 index 000000000..101f82f10 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java @@ -0,0 +1,21 @@ +package com.github.scribejava.core.pkce; + +public class AuthorizationUrlWithPKCE { + + private final PKCE pkce; + private final String authorizationUrl; + + public AuthorizationUrlWithPKCE(PKCE pkce, String authorizationUrl) { + this.pkce = pkce; + this.authorizationUrl = authorizationUrl; + } + + public PKCE getPkce() { + return pkce; + } + + public String getAuthorizationUrl() { + return authorizationUrl; + } + +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCE.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCE.java new file mode 100644 index 000000000..c8d43d26e --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCE.java @@ -0,0 +1,49 @@ +package com.github.scribejava.core.pkce; + +import java.util.HashMap; +import java.util.Map; + +/** + * Used to hold code_challenge, code_challenge_method and code_verifier for https://tools.ietf.org/html/rfc7636 + */ +public class PKCE { + + public static final String PKCE_CODE_CHALLENGE_METHOD_PARAM = "code_challenge_method"; + public static final String PKCE_CODE_CHALLENGE_PARAM = "code_challenge"; + public static final String PKCE_CODE_VERIFIER_PARAM = "code_verifier"; + + private String codeChallenge; + private PKCECodeChallengeMethod codeChallengeMethod = PKCECodeChallengeMethod.S256; + private String codeVerifier; + + public String getCodeChallenge() { + return codeChallenge; + } + + public void setCodeChallenge(String codeChallenge) { + this.codeChallenge = codeChallenge; + } + + public PKCECodeChallengeMethod getCodeChallengeMethod() { + return codeChallengeMethod; + } + + public void setCodeChallengeMethod(PKCECodeChallengeMethod codeChallengeMethod) { + this.codeChallengeMethod = codeChallengeMethod; + } + + public String getCodeVerifier() { + return codeVerifier; + } + + public void setCodeVerifier(String codeVerifier) { + this.codeVerifier = codeVerifier; + } + + public Map getAuthorizationUrlParams() { + final Map params = new HashMap<>(); + params.put(PKCE_CODE_CHALLENGE_PARAM, codeChallenge); + params.put(PKCE_CODE_CHALLENGE_METHOD_PARAM, codeChallengeMethod.name()); + return params; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java new file mode 100644 index 000000000..e8e6cb6e2 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java @@ -0,0 +1,27 @@ +package com.github.scribejava.core.pkce; + +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Base64; + +public enum PKCECodeChallengeMethod { + S256 { + private final Base64.Encoder base64Encoder = Base64.getUrlEncoder().withoutPadding(); + + @Override + public String transform2CodeChallenge(String codeVerifier) throws NoSuchAlgorithmException { + return base64Encoder.encodeToString( + MessageDigest.getInstance("SHA-256").digest( + codeVerifier.getBytes(StandardCharsets.US_ASCII))); + } + }, + plain { + @Override + public String transform2CodeChallenge(String codeVerifier) { + return codeVerifier; + } + }; + + public abstract String transform2CodeChallenge(String codeVerifier) throws NoSuchAlgorithmException; +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java new file mode 100644 index 000000000..86cbb22af --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java @@ -0,0 +1,54 @@ +package com.github.scribejava.core.pkce; + +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.util.Base64; + +/** + * Used to implement Proof Key for Code Exchange by OAuth Public Clients https://tools.ietf.org/html/rfc7636 + * + */ +public class PKCEService { + + private static final SecureRandom RANDOM = new SecureRandom(); + private static final Base64.Encoder BASE_64_ENCODER = Base64.getUrlEncoder().withoutPadding(); + /** + * number of octets to randomly generate. + */ + private final int numberOFOctets; + + public PKCEService(int numberOFOctets) { + this.numberOFOctets = numberOFOctets; + } + + /** + * will create random generator with recommended params (32 octets) https://tools.ietf.org/html/rfc7636#section-4.1 + */ + public PKCEService() { + this(32); + } + + public PKCE generatePKCE() { + final byte[] bytes = new byte[numberOFOctets]; + RANDOM.nextBytes(bytes); + return generatePKCE(bytes); + } + + public PKCE generatePKCE(byte[] randomBytes) { + final String codeVerifier = BASE_64_ENCODER.encodeToString(randomBytes); + + final PKCE pkce = new PKCE(); + pkce.setCodeVerifier(codeVerifier); + try { + pkce.setCodeChallenge(pkce.getCodeChallengeMethod().transform2CodeChallenge(codeVerifier)); + } catch (NoSuchAlgorithmException nsaE) { + pkce.setCodeChallengeMethod(PKCECodeChallengeMethod.plain); + try { + pkce.setCodeChallenge(PKCECodeChallengeMethod.plain.transform2CodeChallenge(codeVerifier)); + } catch (NoSuchAlgorithmException unrealE) { + throw new IllegalStateException("It's just cannot be", unrealE); + } + } + return pkce; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java index ab564941c..26285cda4 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java @@ -1,16 +1,17 @@ package com.github.scribejava.core.services; +/** + * @deprecated use standard java8 java.util.Base64 + */ +@Deprecated public abstract class Base64Encoder { - private static Base64Encoder instance; + private static class InstanceHolder { + private static final Base64Encoder INSTANCE = createEncoderInstance(); + } public static Base64Encoder getInstance() { - synchronized (Base64Encoder.class) { - if (instance == null) { - instance = createEncoderInstance(); - } - } - return instance; + return InstanceHolder.INSTANCE; } private static Base64Encoder createEncoderInstance() { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/CommonsEncoder.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/CommonsEncoder.java index 6e2afa24d..c982abfcd 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/CommonsEncoder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/CommonsEncoder.java @@ -4,6 +4,10 @@ import org.apache.commons.codec.binary.Base64; import com.github.scribejava.core.exceptions.OAuthSignatureException; +/** + * @deprecated use standard java8 java.util.Base64 + */ +@Deprecated public class CommonsEncoder extends Base64Encoder { @Override diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/DatatypeConverterEncoder.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/DatatypeConverterEncoder.java index eee87714f..cfc8c2ef2 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/DatatypeConverterEncoder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/DatatypeConverterEncoder.java @@ -2,6 +2,10 @@ import javax.xml.bind.DatatypeConverter; +/** + * @deprecated use standard java8 java.util.Base64 + */ +@Deprecated public class DatatypeConverterEncoder extends Base64Encoder { @Override diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java index 824f488d7..3d942fbd0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java @@ -40,11 +40,7 @@ private String doSign(String toSign, String keyString) throws UnsupportedEncodin final Mac mac = Mac.getInstance(HMAC_SHA1); mac.init(key); final byte[] bytes = mac.doFinal(toSign.getBytes(UTF8)); - return bytesToBase64String(bytes).replace(CARRIAGE_RETURN, EMPTY_STRING); - } - - private String bytesToBase64String(byte[] bytes) { - return Base64Encoder.getInstance().encode(bytes); + return BASE_64_ENCODER.encodeToString(bytes).replace(CARRIAGE_RETURN, EMPTY_STRING); } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/RSASha1SignatureService.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/RSASha1SignatureService.java index 78ecfa2a1..9cb460e7b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/RSASha1SignatureService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/RSASha1SignatureService.java @@ -32,17 +32,13 @@ public String getSignature(String baseString, String apiSecret, String tokenSecr final Signature signature = Signature.getInstance(RSA_SHA1); signature.initSign(privateKey); signature.update(baseString.getBytes(UTF8)); - return bytesToBase64String(signature); + return BASE_64_ENCODER.encodeToString(signature.sign()); } catch (NoSuchAlgorithmException | InvalidKeyException | SignatureException | UnsupportedEncodingException | RuntimeException e) { throw new OAuthSignatureException(baseString, e); } } - private String bytesToBase64String(Signature signature) throws SignatureException { - return Base64Encoder.getInstance().encode(signature.sign()); - } - /** * {@inheritDoc} */ diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java index cf821d089..0b180d49f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java @@ -1,9 +1,12 @@ package com.github.scribejava.core.services; +import java.util.Base64; + /** * Signs a base string, returning the OAuth signature */ public interface SignatureService { + Base64.Encoder BASE_64_ENCODER = Base64.getEncoder(); /** * Returns the signature diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethodTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethodTest.java new file mode 100644 index 000000000..1f580480a --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethodTest.java @@ -0,0 +1,26 @@ +package com.github.scribejava.core.pkce; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; + +/** + * test PKCE according to
+ * Appendix B. Example for the S256 code_challenge_method
+ * https://tools.ietf.org/html/rfc7636#appendix-B + */ +public class PKCECodeChallengeMethodTest { + + private static final byte[] RANDOM_BYTES = new byte[]{116, 24, (byte) 223, (byte) 180, (byte) 151, (byte) 153, + (byte) 224, 37, 79, (byte) 250, 96, 125, (byte) 216, (byte) 173, (byte) 187, (byte) 186, 22, (byte) 212, 37, 77, + 105, (byte) 214, (byte) 191, (byte) 240, 91, 88, 5, 88, 83, (byte) 132, (byte) 141, 121}; + + @Test + public void testGeneratingPKCE() { + final PKCE pkce = new PKCEService().generatePKCE(RANDOM_BYTES); + + assertEquals(PKCECodeChallengeMethod.S256, pkce.getCodeChallengeMethod()); + assertEquals("dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk", pkce.getCodeVerifier()); + assertEquals("E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM", pkce.getCodeChallenge()); + } + +} From a1368bbfc154eb32352367d4cdc155f10e6a6f77 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 3 Nov 2017 16:33:57 +0300 Subject: [PATCH 014/481] update deps --- pom.xml | 8 ++++---- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 7b8520909..864cc710d 100644 --- a/pom.xml +++ b/pom.xml @@ -86,13 +86,13 @@ com.google.code.gson gson - 2.8.1 + 2.8.2 test commons-codec commons-codec - 1.10 + 1.11 compile true @@ -132,7 +132,7 @@ com.puppycrawl.tools checkstyle - 8.0 + 8.3 @@ -148,7 +148,7 @@ maven-compiler-plugin - 3.6.1 + 3.7.0 UTF-8 1.8 diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 02eb03fe0..2bd07e247 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.0.33 + 2.0.37 diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 12e034874..dffe95c4d 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,12 +23,12 @@ com.squareup.okhttp3 okhttp - 3.8.1 + 3.9.0 com.squareup.okhttp3 mockwebserver - 3.8.1 + 3.9.0 test From 82f38333b9fd53291f32f29638ee473c578f9900 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 3 Nov 2017 18:50:59 +0300 Subject: [PATCH 015/481] switch to use HTTP Basic Authorization by default in requests with need of (2.3. Client Authentication) https://tools.ietf.org/html/rfc6749#section-2.3 Can be overrided in API class --- changelog | 2 + .../github/scribejava/apis/FacebookApi.java | 6 +++ .../com/github/scribejava/apis/HHApi.java | 6 +++ .../scribejava/apis/OdnoklassnikiApi.java | 6 +++ .../github/scribejava/apis/VkontakteApi.java | 6 +++ .../builder/api/ClientAuthenticationType.java | 43 +++++++++++++++++++ .../core/builder/api/DefaultApi20.java | 4 ++ .../scribejava/core/oauth/OAuth20Service.java | 28 +++--------- 8 files changed, 80 insertions(+), 21 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java diff --git a/changelog b/changelog index 076c80762..403427346 100644 --- a/changelog +++ b/changelog @@ -3,6 +3,8 @@ * add JSON token extractor for OAuth 1.0a (thanks to https://github.com/evstropovv) * add new API - uCoz (https://www.ucoz.com/) (thanks to https://github.com/evstropovv) * add PKCE (RFC 7636) support (Proof Key for Code Exchange by OAuth Public Clients) (thanks for suggesting to https://github.com/dieseldjango) + * switch to use HTTP Basic Authorization by default in requests with need of + (2.3. Client Authentication) https://tools.ietf.org/html/rfc6749#section-2.3 Can be overrided in API class [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index f761aab03..41333f4f0 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.facebook.FacebookAccessTokenJsonExtractor; +import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; @@ -47,4 +48,9 @@ protected String getAuthorizationBaseUrl() { public TokenExtractor getAccessTokenExtractor() { return FacebookAccessTokenJsonExtractor.instance(); } + + @Override + public ClientAuthenticationType getClientAuthenticationType() { + return ClientAuthenticationType.REQUEST_BODY; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java index 2a8a8aa12..f1f307155 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java @@ -1,5 +1,6 @@ package com.github.scribejava.apis; +import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; public class HHApi extends DefaultApi20 { @@ -24,4 +25,9 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://hh.ru/oauth/authorize"; } + + @Override + public ClientAuthenticationType getClientAuthenticationType() { + return ClientAuthenticationType.REQUEST_BODY; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index f8e1a40ef..df4e2e755 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.service.OdnoklassnikiServiceImpl; +import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.OAuthConfig; @@ -38,4 +39,9 @@ public OAuth20Service createService(OAuthConfig config) { public OAuth2SignatureType getSignatureType() { return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; } + + @Override + public ClientAuthenticationType getClientAuthenticationType() { + return ClientAuthenticationType.REQUEST_BODY; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index 285cb2cde..7472dba2e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -1,5 +1,6 @@ package com.github.scribejava.apis; +import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.Verb; @@ -36,4 +37,9 @@ protected String getAuthorizationBaseUrl() { public OAuth2SignatureType getSignatureType() { return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; } + + @Override + public ClientAuthenticationType getClientAuthenticationType() { + return ClientAuthenticationType.REQUEST_BODY; + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java new file mode 100644 index 000000000..7e2526b0e --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java @@ -0,0 +1,43 @@ +package com.github.scribejava.core.builder.api; + +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import java.nio.charset.Charset; +import java.util.Base64; + +/** + * Represents
+ * 2.3. Client Authentication
+ * https://tools.ietf.org/html/rfc6749#section-2.3
+ * in it's part 2.3.1. Client Password
+ * https://tools.ietf.org/html/rfc6749#section-2.3.1 + */ +public enum ClientAuthenticationType { + HTTP_BASIC_AUTHENTICATION_SCHEME { + private final Base64.Encoder base64Encoder = Base64.getEncoder(); + + @Override + public void addClientAuthentication(OAuthRequest request, OAuthConfig config) { + final String apiKey = config.getApiKey(); + final String apiSecret = config.getApiSecret(); + if (apiKey != null && apiSecret != null) { + request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + ' ' + + base64Encoder.encodeToString( + String.format("%s:%s", apiKey, apiSecret).getBytes(Charset.forName("UTF-8")))); + } + } + }, + REQUEST_BODY { + @Override + public void addClientAuthentication(OAuthRequest request, OAuthConfig config) { + request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); + final String apiSecret = config.getApiSecret(); + if (apiSecret != null) { + request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); + } + } + }; + + public abstract void addClientAuthentication(OAuthRequest request, OAuthConfig config); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 5a9e7ce44..90c65a162 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -94,4 +94,8 @@ public OAuth20Service createService(OAuthConfig config) { public OAuth2SignatureType getSignatureType() { return OAuth2SignatureType.BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD; } + + public ClientAuthenticationType getClientAuthenticationType() { + return ClientAuthenticationType.HTTP_BASIC_AUTHENTICATION_SCHEME; + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 5caefdca9..be4804d54 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -1,7 +1,6 @@ package com.github.scribejava.core.oauth; import java.io.IOException; -import java.nio.charset.Charset; import java.util.concurrent.Future; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuth2AccessToken; @@ -13,7 +12,6 @@ import com.github.scribejava.core.pkce.AuthorizationUrlWithPKCE; import com.github.scribejava.core.pkce.PKCE; import com.github.scribejava.core.pkce.PKCEService; -import java.util.Base64; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -21,7 +19,6 @@ public class OAuth20Service extends OAuthService { private static final String VERSION = "2.0"; - private static final Base64.Encoder BASE_64_ENCODER = Base64.getEncoder(); private static final PKCEService PKCE_SERVICE = new PKCEService(); private final DefaultApi20 api; @@ -99,11 +96,9 @@ public final Future getAccessToken(String code, protected OAuthRequest createAccessTokenRequest(String code) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); final OAuthConfig config = getConfig(); - request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - final String apiSecret = config.getApiSecret(); - if (apiSecret != null) { - request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); - } + + api.getClientAuthenticationType().addClientAuthentication(request, config); + request.addParameter(OAuthConstants.CODE, code); request.addParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); final String scope = config.getScope(); @@ -145,12 +140,9 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken) { throw new IllegalArgumentException("The refreshToken cannot be null or empty"); } final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint()); - final OAuthConfig config = getConfig(); - request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - final String apiSecret = config.getApiSecret(); - if (apiSecret != null) { - request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); - } + + api.getClientAuthenticationType().addClientAuthentication(request, getConfig()); + request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); return request; @@ -195,13 +187,7 @@ protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, St request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.PASSWORD); - final String apiKey = config.getApiKey(); - final String apiSecret = config.getApiSecret(); - if (apiKey != null && apiSecret != null) { - request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + ' ' - + BASE_64_ENCODER.encodeToString( - String.format("%s:%s", apiKey, apiSecret).getBytes(Charset.forName("UTF-8")))); - } + api.getClientAuthenticationType().addClientAuthentication(request, config); return request; } From 68919e6331490da8a2fc6be1485d4c53ff4db894 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 3 Nov 2017 19:16:44 +0300 Subject: [PATCH 016/481] add support for client_credentials grant type (thanks to https://github.com/vivin) --- changelog | 1 + ...kontakteClientCredentialsGrantExample.java | 37 +++++++++++++++++++ .../scribejava/core/oauth/OAuth20Service.java | 8 ++-- 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java diff --git a/changelog b/changelog index 403427346..7e381fea6 100644 --- a/changelog +++ b/changelog @@ -5,6 +5,7 @@ * add PKCE (RFC 7636) support (Proof Key for Code Exchange by OAuth Public Clients) (thanks for suggesting to https://github.com/dieseldjango) * switch to use HTTP Basic Authorization by default in requests with need of (2.3. Client Authentication) https://tools.ietf.org/html/rfc6749#section-2.3 Can be overrided in API class + * add support for client_credentials grant type (thanks to https://github.com/vivin) [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java new file mode 100644 index 000000000..b91b115f3 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java @@ -0,0 +1,37 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.VkontakteApi; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +public final class VkontakteClientCredentialsGrantExample { + + private static final String NETWORK_NAME = "Vkontakte.ru"; + + private VkontakteClientCredentialsGrantExample() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .scope("wall,offline") // replace with desired scope + .callback("http://your.site.com/callback") + .build(VkontakteApi.instance()); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + final OAuth2AccessToken accessToken = service.getAccessTokenClientCredentialsGrant(); + + System.out.println("Got the Access Token!"); + System.out.println(accessToken); + System.out.println(); + + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index de76f3af5..a04eb8061 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -220,11 +220,9 @@ public final Future getAccessTokenClientCredentialsGrant( protected OAuthRequest createAccessTokenClientCredentialsGrantRequest() { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); final OAuthConfig config = getConfig(); - request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - final String apiSecret = config.getApiSecret(); - if (apiSecret != null) { - request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); - } + + api.getClientAuthenticationType().addClientAuthentication(request, config); + final String scope = config.getScope(); if (scope != null) { request.addParameter(OAuthConstants.SCOPE, scope); From f3cd5193346b60503c2103bf776d384be2dcfa43 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 14 Nov 2017 19:23:23 +0300 Subject: [PATCH 017/481] add support for RFC 7009 OAuth 2.0 Token Revocation (thanks to https://github.com/vivin) --- changelog | 1 + .../github/scribejava/apis/FacebookApi.java | 2 +- .../github/scribejava/apis/GoogleApi20.java | 5 + .../FacebookAccessTokenJsonExtractor.java | 2 +- .../apis/examples/Google20Example.java | 2 +- .../apis/examples/Google20RevokeExample.java | 104 ++++++++++++++++++ .../core/builder/api/DefaultApi20.java | 12 ++ .../OAuth2AccessTokenJsonExtractor.java | 7 +- .../model/OAuth2AccessTokenErrorResponse.java | 6 +- .../scribejava/core/oauth/OAuth20Service.java | 55 +++++++++ .../OAuth2RevokeTokenResponseConverter.java | 15 +++ .../src/main/java/revoke/TokenTypeHint.java | 12 ++ 12 files changed, 215 insertions(+), 8 deletions(-) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java create mode 100644 scribejava-core/src/main/java/revoke/OAuth2RevokeTokenResponseConverter.java create mode 100644 scribejava-core/src/main/java/revoke/TokenTypeHint.java diff --git a/changelog b/changelog index 7e381fea6..c728e42dc 100644 --- a/changelog +++ b/changelog @@ -6,6 +6,7 @@ * switch to use HTTP Basic Authorization by default in requests with need of (2.3. Client Authentication) https://tools.ietf.org/html/rfc6749#section-2.3 Can be overrided in API class * add support for client_credentials grant type (thanks to https://github.com/vivin) + * add support for RFC 7009 OAuth 2.0 Token Revocation (thanks to https://github.com/vivin) [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index 41333f4f0..635a20e48 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -36,7 +36,7 @@ public String getAccessTokenEndpoint() { @Override public String getRefreshTokenEndpoint() { - throw new UnsupportedOperationException("Facebook doesn't support refershing tokens"); + throw new UnsupportedOperationException("Facebook doesn't support refreshing tokens"); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java index 1e4bd8c6f..b4ab24d39 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java @@ -32,4 +32,9 @@ protected String getAuthorizationBaseUrl() { public TokenExtractor getAccessTokenExtractor() { return OpenIdJsonTokenExtractor.instance(); } + + @Override + public String getRevokeTokenEndpoint() { + return "https://accounts.google.com/o/oauth2/revoke"; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java index 5f6d71d44..62326e099 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java @@ -35,7 +35,7 @@ public static FacebookAccessTokenJsonExtractor instance() { * ID.","type":"OAuthException","code":101,"fbtrace_id":"CvDR+X4WWIx"}}' */ @Override - protected void generateError(String response) { + public void generateError(String response) { extractParameter(response, MESSAGE_REGEX_PATTERN, false); throw new FacebookAccessTokenErrorResponse(extractParameter(response, MESSAGE_REGEX_PATTERN, false), diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index e9e2adf27..63507de18 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -14,7 +14,7 @@ import java.util.Map; import java.util.concurrent.ExecutionException; -public final class Google20Example { +public class Google20Example { private static final String NETWORK_NAME = "G+"; private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java new file mode 100644 index 000000000..da2d7ea17 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java @@ -0,0 +1,104 @@ +package com.github.scribejava.apis.examples; + +import java.util.Random; +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.GoogleApi20; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +public class Google20RevokeExample { + + private static final String NETWORK_NAME = "G+"; + private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; + + private Google20RevokeExample() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .scope("profile") // replace with desired scope + .state(secretState) + .callback("http://example.com/callback") + .build(GoogleApi20.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + //pass access_type=offline to get refresh token + //https://developers.google.com/identity/protocols/OAuth2WebServer#preparing-to-start-the-oauth-20-flow + final Map additionalParams = new HashMap<>(); + additionalParams.put("access_type", "offline"); + //force to reget refresh token (if usera are asked not the first time) + additionalParams.put("prompt", "consent"); + final String authorizationUrl = service.getAuthorizationUrl(additionalParams); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + Response response = service.execute(request); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + System.out.println(); + + System.out.println("Revoking token..."); + service.revokeToken(accessToken.getAccessToken()); + System.out.println("done."); + System.out.println("After revoke we should fail requesting any data..."); + //Google Note: Following a successful revocation response, + //it might take some time before the revocation has full effect. + while (response.getCode() == 200) { + Thread.sleep(1000); + request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + response = service.execute(request); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + System.out.println(); + } + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 90c65a162..e0caa4637 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -54,6 +54,18 @@ public String getRefreshTokenEndpoint() { return getAccessTokenEndpoint(); } + /** + * As stated in RFC 7009 OAuth 2.0 Token Revocation + * + * @return endpoint, which allows clients to notify the authorization server that a previously obtained refresh or + * access token is no longer needed. + * @see RFC 7009 + */ + public String getRevokeTokenEndpoint() { + throw new UnsupportedOperationException( + "This API doesn't support revoking tokens or we have no info about this"); + } + protected abstract String getAuthorizationBaseUrl(); /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index 0c24755b3..49c6ec7d8 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -40,11 +40,10 @@ public static OAuth2AccessTokenJsonExtractor instance() { @Override public OAuth2AccessToken extract(Response response) throws IOException { final String body = response.getBody(); - Preconditions.checkEmptyString(body, - "Response body is incorrect. Can't extract a token from an empty string"); + Preconditions.checkEmptyString(body, "Response body is incorrect. Can't extract a token from an empty string"); if (response.getCode() != 200) { - generateError(response.getBody()); + generateError(body); } return createToken(body); } @@ -54,7 +53,7 @@ public OAuth2AccessToken extract(Response response) throws IOException { * * @param response response */ - protected void generateError(String response) { + public void generateError(String response) { final String errorInString = extractParameter(response, ERROR_REGEX_PATTERN, true); final String errorDescription = extractParameter(response, ERROR_DESCRIPTION_REGEX_PATTERN, false); final String errorUriInString = extractParameter(response, ERROR_URI_REGEX_PATTERN, false); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java index eba31404e..6476799e0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java @@ -12,7 +12,11 @@ public class OAuth2AccessTokenErrorResponse extends OAuthException { private static final long serialVersionUID = 2309424849700276816L; public enum ErrorCode { - invalid_request, invalid_client, invalid_grant, unauthorized_client, unsupported_grant_type, invalid_scope + invalid_request, invalid_client, invalid_grant, unauthorized_client, unsupported_grant_type, invalid_scope, + /** + * @see RFC 7009, 2.2.1. Error Response + */ + unsupported_token_type } private final ErrorCode errorCode; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index a04eb8061..2c80b4bc5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -3,18 +3,22 @@ import java.io.IOException; import java.util.concurrent.Future; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2Authorization; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.pkce.AuthorizationUrlWithPKCE; import com.github.scribejava.core.pkce.PKCE; import com.github.scribejava.core.pkce.PKCEService; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutionException; +import revoke.TokenTypeHint; public class OAuth20Service extends OAuthService { @@ -291,6 +295,57 @@ public DefaultApi20 getApi() { return api; } + protected OAuthRequest createRevokeTokenRequest(String tokenToRevoke, TokenTypeHint tokenTypeHint) { + final OAuthRequest request = new OAuthRequest(Verb.POST, api.getRevokeTokenEndpoint()); + + api.getClientAuthenticationType().addClientAuthentication(request, getConfig()); + + request.addParameter("token", tokenToRevoke); + if (tokenTypeHint != null) { + request.addParameter("token_type_hint", tokenTypeHint.toString()); + } + return request; + } + + public final Future revokeTokenAsync(String tokenToRevoke) { + return revokeTokenAsync(tokenToRevoke, null); + } + + public final Future revokeTokenAsync(String tokenToRevoke, TokenTypeHint tokenTypeHint) { + return revokeToken(tokenToRevoke, null, tokenTypeHint); + } + + public final void revokeToken(String tokenToRevoke) throws IOException, InterruptedException, ExecutionException { + revokeToken(tokenToRevoke, (TokenTypeHint) null); + } + + public final void revokeToken(String tokenToRevoke, TokenTypeHint tokenTypeHint) + throws IOException, InterruptedException, ExecutionException { + final OAuthRequest request = createRevokeTokenRequest(tokenToRevoke, tokenTypeHint); + + checkForErrorRevokeToken(execute(request)); + } + + public final Future revokeToken(String tokenToRevoke, OAuthAsyncRequestCallback callback) { + return revokeToken(tokenToRevoke, callback, null); + } + + public final Future revokeToken(String tokenToRevoke, OAuthAsyncRequestCallback callback, + TokenTypeHint tokenTypeHint) { + final OAuthRequest request = createRevokeTokenRequest(tokenToRevoke, tokenTypeHint); + + return execute(request, callback, response -> { + checkForErrorRevokeToken(response); + return null; + }); + } + + private void checkForErrorRevokeToken(Response response) throws IOException { + if (response.getCode() != 200) { + OAuth2AccessTokenJsonExtractor.instance().generateError(response.getBody()); + } + } + public OAuth2Authorization extractAuthorization(String redirectLocation) { final OAuth2Authorization authorization = new OAuth2Authorization(); int end = redirectLocation.indexOf('#'); diff --git a/scribejava-core/src/main/java/revoke/OAuth2RevokeTokenResponseConverter.java b/scribejava-core/src/main/java/revoke/OAuth2RevokeTokenResponseConverter.java new file mode 100644 index 000000000..a6c69609e --- /dev/null +++ b/scribejava-core/src/main/java/revoke/OAuth2RevokeTokenResponseConverter.java @@ -0,0 +1,15 @@ +package revoke; + +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.model.Response; +import java.io.IOException; + +public class OAuth2RevokeTokenResponseConverter { + + public Void convert(Response response) throws IOException { + if (response.getCode() != 200) { + OAuth2AccessTokenJsonExtractor.instance().generateError(response.getBody()); + } + return null; + } +} diff --git a/scribejava-core/src/main/java/revoke/TokenTypeHint.java b/scribejava-core/src/main/java/revoke/TokenTypeHint.java new file mode 100644 index 000000000..6855ee8b0 --- /dev/null +++ b/scribejava-core/src/main/java/revoke/TokenTypeHint.java @@ -0,0 +1,12 @@ +package revoke; + +/** + * + * as stated in RFC 7009
+ * 2.1. Revocation Request + * + * @see RFC 7009, 2.1. Revocation Request + */ +public enum TokenTypeHint { + access_token, refresh_token +} From 8d18844ca6a5720dcf435ff2bad032f12a400eff Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 14 Nov 2017 19:49:10 +0300 Subject: [PATCH 018/481] add OAuth2Service signRequest method accepting just String, not OAuth2 Access Token Object. Remove signRequest from abstract OAuthService. 2.0 and 1.0a will be a bit more different now. --- changelog | 2 ++ .../apis/service/ImgurOAuthServiceImpl.java | 6 ++---- .../apis/service/MailruOAuthServiceImpl.java | 5 ++--- .../service/OdnoklassnikiServiceImpl.java | 5 ++--- .../apis/service/TutByOAuthServiceImpl.java | 5 ++--- .../core/builder/ServiceBuilder.java | 2 +- .../scribejava/core/builder/api/BaseApi.java | 2 +- .../core/builder/api/OAuth2SignatureType.java | 21 ++++++++++++++----- .../core/oauth/OAuth10aService.java | 3 +-- .../scribejava/core/oauth/OAuth20Service.java | 9 +++++--- .../scribejava/core/oauth/OAuthService.java | 11 +--------- .../okhttp/OkHttpHttpClientTest.java | 2 +- 12 files changed, 37 insertions(+), 36 deletions(-) diff --git a/changelog b/changelog index c728e42dc..3b0e94297 100644 --- a/changelog +++ b/changelog @@ -7,6 +7,8 @@ (2.3. Client Authentication) https://tools.ietf.org/html/rfc6749#section-2.3 Can be overrided in API class * add support for client_credentials grant type (thanks to https://github.com/vivin) * add support for RFC 7009 OAuth 2.0 Token Revocation (thanks to https://github.com/vivin) + * add OAuth2Service signRequest method accepting just String, not OAuth2 Access Token Object. + Remove signRequest from abstract OAuthService. 2.0 and 1.0a will be a bit more different now. [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java index c0f74aab6..c77de1b70 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java @@ -2,7 +2,6 @@ import com.github.scribejava.apis.ImgurApi; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; @@ -33,9 +32,8 @@ protected OAuthRequest createAccessTokenRequest(String oauthVerifier) { } @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { + public void signRequest(String accessToken, OAuthRequest request) { request.addHeader("Authorization", - accessToken == null - ? "Client-ID " + getConfig().getApiKey() : "Bearer " + accessToken.getAccessToken()); + accessToken == null ? "Client-ID " + getConfig().getApiKey() : "Bearer " + accessToken); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java index 86bcb79ab..2b6e3cc3e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java @@ -7,7 +7,6 @@ import org.apache.commons.codec.CharEncoding; import static org.apache.commons.codec.digest.DigestUtils.md5Hex; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; @@ -20,9 +19,9 @@ public MailruOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { + public void signRequest(String accessToken, OAuthRequest request) { // sig = md5(params + secret_key) - request.addQuerystringParameter("session_key", accessToken.getAccessToken()); + request.addQuerystringParameter("session_key", accessToken); request.addQuerystringParameter("app_id", getConfig().getApiKey()); final String completeUrl = request.getCompleteUrl(); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java index 7e9017978..6d3850cc2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java @@ -1,7 +1,6 @@ package com.github.scribejava.apis.service; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Parameter; @@ -25,10 +24,10 @@ public OdnoklassnikiServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { + public void signRequest(String accessToken, OAuthRequest request) { //sig = lower(md5( sorted_request_params_composed_string + md5(access_token + application_secret_key))) try { - final String tokenDigest = md5Hex(accessToken.getAccessToken() + getConfig().getApiSecret()); + final String tokenDigest = md5Hex(accessToken + getConfig().getApiSecret()); final ParameterList queryParams = request.getQueryStringParams(); queryParams.addAll(request.getBodyParams()); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java index f1f14485f..b199ac66a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java @@ -1,7 +1,6 @@ package com.github.scribejava.apis.service; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; @@ -14,7 +13,7 @@ public TutByOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { } @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { - request.addQuerystringParameter(OAuthConstants.TOKEN, accessToken.getAccessToken()); + public void signRequest(String accessToken, OAuthRequest request) { + request.addQuerystringParameter(OAuthConstants.TOKEN, accessToken); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index a3ff17365..c003e7d18 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -137,7 +137,7 @@ public ServiceBuilder debug() { * @param api will build Service for this API * @return fully configured {@link S} */ - public > S build(BaseApi api) { + public S build(BaseApi api) { return api.createService(new OAuthConfig(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, httpClient)); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java index 7f6fbdd4f..a42fe35fa 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java @@ -3,7 +3,7 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.oauth.OAuthService; -public interface BaseApi> { +public interface BaseApi { T createService(OAuthConfig config); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java index a6825a757..b2334be32 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java @@ -10,8 +10,8 @@ public enum OAuth2SignatureType { */ BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD { @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { - request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); + public void signRequest(String accessToken, OAuthRequest request) { + request.addHeader("Authorization", "Bearer " + accessToken); } }, @@ -20,11 +20,22 @@ public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { */ BEARER_URI_QUERY_PARAMETER { @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { - request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getAccessToken()); + public void signRequest(String accessToken, OAuthRequest request) { + request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken); } }; - public abstract void signRequest(OAuth2AccessToken accessToken, OAuthRequest request); + /** + * + * @param accessToken accessToken + * @param request request + * @deprecated use {@link #signRequest(java.lang.String, com.github.scribejava.core.model.OAuthRequest)} + */ + @Deprecated + public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { + signRequest(accessToken == null ? null : accessToken.getAccessToken(), request); + } + + public abstract void signRequest(String accessToken, OAuthRequest request); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index 1023def56..a006c70b2 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -16,7 +16,7 @@ /** * OAuth 1.0a implementation of {@link OAuthService} */ -public class OAuth10aService extends OAuthService { +public class OAuth10aService extends OAuthService { private static final String VERSION = "1.0"; private final DefaultApi10a api; @@ -124,7 +124,6 @@ protected OAuthRequest prepareAccessTokenRequest(OAuth1RequestToken requestToken return request; } - @Override public void signRequest(OAuth1AccessToken token, OAuthRequest request) { final OAuthConfig config = getConfig(); config.log("signing request: " + request.getCompleteUrl()); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 2c80b4bc5..b20f421b7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -20,7 +20,7 @@ import java.util.concurrent.ExecutionException; import revoke.TokenTypeHint; -public class OAuth20Service extends OAuthService { +public class OAuth20Service extends OAuthService { private static final String VERSION = "2.0"; private static final PKCEService PKCE_SERVICE = new PKCEService(); @@ -243,11 +243,14 @@ public String getVersion() { return VERSION; } - @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { + public void signRequest(String accessToken, OAuthRequest request) { api.getSignatureType().signRequest(accessToken, request); } + public final void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { + signRequest(accessToken == null ? null : accessToken.getAccessToken(), request); + } + public final AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE() { return getAuthorizationUrlWithPKCE(null); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index df58ce3ea..cf2ca6252 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -9,7 +9,6 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Token; import java.io.File; import java.io.IOException; @@ -17,13 +16,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -/** - * The main ScribeJava object. - * - * A facade responsible for the retrieval of request and access tokens and for the signing of HTTP requests. - * @param type of token used to sign the request - */ -public abstract class OAuthService implements AutoCloseable { +public abstract class OAuthService implements AutoCloseable { private final OAuthConfig config; private final HttpClient httpClient; @@ -66,8 +59,6 @@ public OAuthConfig getConfig() { */ public abstract String getVersion(); - public abstract void signRequest(T token, OAuthRequest request); - public Future executeAsync(OAuthRequest request) { return execute(request, null); } diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java index 496882cdd..469b6882a 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java @@ -21,7 +21,7 @@ import static org.junit.Assert.assertEquals; public class OkHttpHttpClientTest { - private OAuthService oAuthService; + private OAuthService oAuthService; @Before public void setUp() { From 76f626edd74f74c9ab4c5c32c2c504d963006cd7 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 15 Nov 2017 10:39:28 +0300 Subject: [PATCH 019/481] fix typo in package name --- .../java/com/github/scribejava/core/oauth/OAuth20Service.java | 2 +- .../core}/revoke/OAuth2RevokeTokenResponseConverter.java | 2 +- .../{ => com/github/scribejava/core}/revoke/TokenTypeHint.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename scribejava-core/src/main/java/{ => com/github/scribejava/core}/revoke/OAuth2RevokeTokenResponseConverter.java (91%) rename scribejava-core/src/main/java/{ => com/github/scribejava/core}/revoke/TokenTypeHint.java (84%) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index b20f421b7..9b9b22e41 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -18,7 +18,7 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutionException; -import revoke.TokenTypeHint; +import com.github.scribejava.core.revoke.TokenTypeHint; public class OAuth20Service extends OAuthService { diff --git a/scribejava-core/src/main/java/revoke/OAuth2RevokeTokenResponseConverter.java b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/OAuth2RevokeTokenResponseConverter.java similarity index 91% rename from scribejava-core/src/main/java/revoke/OAuth2RevokeTokenResponseConverter.java rename to scribejava-core/src/main/java/com/github/scribejava/core/revoke/OAuth2RevokeTokenResponseConverter.java index a6c69609e..b287d7868 100644 --- a/scribejava-core/src/main/java/revoke/OAuth2RevokeTokenResponseConverter.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/OAuth2RevokeTokenResponseConverter.java @@ -1,4 +1,4 @@ -package revoke; +package com.github.scribejava.core.revoke; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.model.Response; diff --git a/scribejava-core/src/main/java/revoke/TokenTypeHint.java b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java similarity index 84% rename from scribejava-core/src/main/java/revoke/TokenTypeHint.java rename to scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java index 6855ee8b0..55a95057e 100644 --- a/scribejava-core/src/main/java/revoke/TokenTypeHint.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java @@ -1,4 +1,4 @@ -package revoke; +package com.github.scribejava.core.revoke; /** * From 73c29f539804fbed6e7e2587a87f97898439eeca Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 15 Nov 2017 10:55:51 +0300 Subject: [PATCH 020/481] drop toString method from *Tokens to prevent leak of sensible data (token ans secrets) (thanks to https://github.com/rcaa) --- changelog | 1 + .../apis/openid/OpenIdOAuth2AccessToken.java | 11 ----------- .../scribejava/apis/salesforce/SalesforceToken.java | 11 ----------- .../scribejava/apis/examples/AWeberExample.java | 3 +-- .../github/scribejava/apis/examples/Box20Example.java | 3 +-- .../github/scribejava/apis/examples/DiggExample.java | 3 +-- .../github/scribejava/apis/examples/EtsyExample.java | 3 +-- .../apis/examples/FacebookAsyncNingExample.java | 4 ++-- .../scribejava/apis/examples/FacebookExample.java | 3 +-- .../scribejava/apis/examples/FlickrExample.java | 3 +-- .../scribejava/apis/examples/Foursquare2Example.java | 3 +-- .../scribejava/apis/examples/FoursquareExample.java | 3 +-- .../scribejava/apis/examples/FrappeExample.java | 4 +--- .../scribejava/apis/examples/FreelancerExample.java | 5 ++--- .../apis/examples/GitHubAsyncOkHttpExample.java | 4 ++-- .../scribejava/apis/examples/GitHubExample.java | 3 +-- .../apis/examples/Google20AsyncAHCExample.java | 8 ++++---- .../scribejava/apis/examples/Google20Example.java | 6 ++---- .../apis/examples/Google20RevokeExample.java | 3 +-- .../apis/examples/Google20WithPKCEExample.java | 6 ++---- .../github/scribejava/apis/examples/HHExample.java | 3 +-- .../github/scribejava/apis/examples/ImgurExample.java | 3 +-- .../scribejava/apis/examples/Kaixin20Example.java | 3 +-- .../scribejava/apis/examples/LinkedIn20Example.java | 3 +-- .../scribejava/apis/examples/LinkedInExample.java | 3 +-- .../apis/examples/LinkedInExampleWithScopes.java | 3 +-- .../github/scribejava/apis/examples/LiveExample.java | 3 +-- .../scribejava/apis/examples/MailruAsyncExample.java | 4 ++-- .../scribejava/apis/examples/MailruExample.java | 3 +-- .../scribejava/apis/examples/MeetupExample.java | 3 +-- .../scribejava/apis/examples/MisfitExample.java | 3 +-- .../github/scribejava/apis/examples/NaverExample.java | 3 +-- .../scribejava/apis/examples/NeteaseWeiboExample.java | 3 +-- .../apis/examples/OdnoklassnikiExample.java | 6 ++---- .../scribejava/apis/examples/PinterestExample.java | 3 +-- .../github/scribejava/apis/examples/Px500Example.java | 3 +-- .../scribejava/apis/examples/RenrenExample.java | 3 +-- .../scribejava/apis/examples/SalesforceExample.java | 3 +-- .../apis/examples/SalesforceNingAsyncExample.java | 4 ++-- .../scribejava/apis/examples/SinaWeibo2Example.java | 3 +-- .../scribejava/apis/examples/SinaWeiboExample.java | 3 +-- .../scribejava/apis/examples/SkyrockExample.java | 3 +-- .../scribejava/apis/examples/SohuWeiboExample.java | 3 +-- .../apis/examples/StackExchangeExample.java | 3 +-- .../examples/TheThingsNetworkV1StagingExample.java | 3 +-- .../examples/TheThingsNetworkV2PreviewExample.java | 3 +-- .../scribejava/apis/examples/TrelloExample.java | 3 +-- .../scribejava/apis/examples/TumblrExample.java | 3 +-- .../github/scribejava/apis/examples/TutByExample.java | 3 +-- .../scribejava/apis/examples/TwitterExample.java | 3 +-- .../github/scribejava/apis/examples/UcozExample.java | 3 +-- .../scribejava/apis/examples/ViadeoExample.java | 3 +-- .../scribejava/apis/examples/VkontakteExample.java | 3 +-- .../apis/examples/VkontakteExternalHttpExample.java | 4 ++-- .../github/scribejava/apis/examples/XingExample.java | 3 +-- .../github/scribejava/apis/examples/YahooExample.java | 3 +-- .../scribejava/core/model/OAuth1AccessToken.java | 7 ------- .../scribejava/core/model/OAuth1RequestToken.java | 8 -------- .../scribejava/core/model/OAuth2AccessToken.java | 10 ---------- 59 files changed, 66 insertions(+), 163 deletions(-) diff --git a/changelog b/changelog index 3b0e94297..fda68b66e 100644 --- a/changelog +++ b/changelog @@ -9,6 +9,7 @@ * add support for RFC 7009 OAuth 2.0 Token Revocation (thanks to https://github.com/vivin) * add OAuth2Service signRequest method accepting just String, not OAuth2 Access Token Object. Remove signRequest from abstract OAuthService. 2.0 and 1.0a will be a bit more different now. + * drop toString method from *Tokens to prevent leak of sensible data (token ans secrets) (thanks to https://github.com/rcaa) [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdOAuth2AccessToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdOAuth2AccessToken.java index 94550ef79..7e6588444 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdOAuth2AccessToken.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdOAuth2AccessToken.java @@ -56,15 +56,4 @@ public boolean equals(Object obj) { return Objects.equals(openIdToken, ((OpenIdOAuth2AccessToken) obj).getOpenIdToken()); } - - @Override - public String toString() { - return "OpenIdOAuth2AccessToken{" - + "access_token=" + getAccessToken() - + ", token_type=" + getTokenType() - + ", expires_in=" + getExpiresIn() - + ", refresh_token=" + getRefreshToken() - + ", scope=" + getScope() - + ", open_id_token=" + openIdToken + '}'; - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java index 14a0911cd..242cb7e31 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceToken.java @@ -51,15 +51,4 @@ public boolean equals(Object obj) { } return Objects.equals(instanceUrl, ((SalesforceToken) obj).getInstanceUrl()); } - - @Override - public String toString() { - return "SalesforceToken{" - + "access_token=" + getAccessToken() - + ", token_type=" + getTokenType() - + ", expires_in=" + getExpiresIn() - + ", refresh_token=" + getRefreshToken() - + ", scope=" + getScope() - + ", instance_url=" + instanceUrl + '}'; - } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index d304dc6d4..f79dfa4ef 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -50,8 +50,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index de8a1c1ed..eaf26af17 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -69,8 +69,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(If you're curious, it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index aafbea10c..3985a7b83 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -53,8 +53,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java index 115617f71..a3bc12d40 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java @@ -47,8 +47,7 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index ae8879790..73062a43c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -74,8 +74,8 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code).get(); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index 521020e29..c4c54897d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -63,8 +63,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index e5809874f..81d47b10c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -51,8 +51,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index 33e6206ef..0dd9d1a31 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -47,8 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index afaaca188..9a30e6c10 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -45,8 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java index fe704ed7a..16fe60528 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java @@ -49,9 +49,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(If you're curious, it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); - + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index a17f896de..696860bce 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -37,7 +37,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Fetching the Request Token..."); final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); - System.out.println("(if your curious it looks like this: " + requestToken + " )"); + System.out.println("(if your curious the raw answer looks like this: " + requestToken.getRawResponse() + "')"); System.out.println(); System.out.println("Now go and authorize ScribeJava here:"); @@ -51,8 +51,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java index 596a14a45..06e81e5dd 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java @@ -66,8 +66,8 @@ public static void main(String... args) throws IOException, ExecutionException, System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index 8c3444d92..392a0c494 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -62,8 +62,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index 7ac82e7e9..c5e9dc5d0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -83,14 +83,14 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println("Trading the Request Token for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + + "')"); System.out.println("Refreshing the Access Token..."); accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); System.out.println("Refreshed the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 63507de18..02c8ff680 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -71,14 +71,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println("Refreshing the Access Token..."); accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); System.out.println("Refreshed the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java index da2d7ea17..7e677731c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java @@ -71,8 +71,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java index 91a108cb1..5a5668147 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java @@ -75,14 +75,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code, authUrlWithPKCE.getPkce().getCodeVerifier()); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println("Refreshing the Access Token..."); accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); System.out.println("Refreshed the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index e892eace3..d273974d6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -49,8 +49,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); System.out.println("Now we're going to access a protected resource..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index 35f6d9a31..104b4cb61 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -47,8 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java index 6d61a613b..43d5fe583 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -47,8 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java index 8553c3498..69a65ebc7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java @@ -49,8 +49,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index 02ae520c1..4d1c998fe 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -46,8 +46,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index a8247f65c..f09d322d5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -50,8 +50,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index 09fabe03a..b6231a744 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -47,8 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index 2c566e99b..181ab1b82 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -60,8 +60,8 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + + "')"); System.out.println(); System.out.println("Now we're going to access a protected resource..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index f6c620d0f..8a02df6fd 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -49,8 +49,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); System.out.println("Now we're going to access a protected resource..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index c8d6ea911..50d3a894b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -45,8 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java index ed6c1dd7f..4c8cbddf1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java @@ -50,8 +50,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java index 5d2d5548e..21ff0fa92 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java @@ -64,8 +64,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java index 866c2167b..63a7891c9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java @@ -53,8 +53,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index 8ea048fe8..4ecd3779c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -52,15 +52,13 @@ public static void main(String... args) throws IOException, InterruptedException OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); System.out.println("Refreshing the Access Token..."); accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); System.out.println("Refreshed the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index 1fec439b4..def416167 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -48,8 +48,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index 820a0e821..fbbad7874 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -45,8 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index eaeb35532..621566f6e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -56,8 +56,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java index 30f4aab85..d9c9ff819 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -76,8 +76,7 @@ public static void main(String... args) throws IOException, NoSuchAlgorithmExcep } System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + salesforceAccessToken + ", 'rawResponse'='" - + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); System.out.println("instance_url is: " + salesforceAccessToken.getInstanceUrl()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java index d057df0d9..9a55bd575 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java @@ -77,8 +77,8 @@ public static void main(String... args) throws InterruptedException, ExecutionEx } System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + salesforceAccessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + + "')"); System.out.println(); System.out.println("Instance is: " + salesforceAccessToken.getInstanceUrl()); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java index a2bacaff4..e314a82d7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -47,8 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index 289f4eb50..324e02201 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -53,8 +53,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index fcb2f592a..578ef88a3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -45,8 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java index 0cb93b91a..53d20aa9f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java @@ -53,8 +53,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index 04858eab6..e9af948d9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -67,8 +67,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java index 057f9b27c..7264194a3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java @@ -69,8 +69,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java index acb791c1c..943a2529a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java @@ -66,8 +66,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index dea9fc659..309d4a9b3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -47,8 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index ec21d3bfb..1e6bdac15 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -47,8 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index daa5f0122..ef3f1c924 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -48,8 +48,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index 620eb7820..235c0c2e6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -45,8 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java index 04dfaacf4..34a7a4b98 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java @@ -40,8 +40,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index 09dcde65a..9605b1c49 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -47,8 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java index 240f78e7c..9954116cc 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java @@ -48,8 +48,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java index 598d25c64..4a89fd4d4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java @@ -65,8 +65,8 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index 9929c6152..fce6c9aea 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -45,8 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index 3e8802fa8..af3fa635a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -46,8 +46,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1AccessToken.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1AccessToken.java index e57a7db39..dd145e5c7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1AccessToken.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1AccessToken.java @@ -62,11 +62,4 @@ public boolean equals(Object obj) { } return Objects.equals(getTokenSecret(), other.getTokenSecret()); } - - @Override - public String toString() { - return "OAuth1AccessToken{" - + "oauth_token=" + getToken() - + ", oauth_token_secret=" + getTokenSecret() + '}'; - } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1RequestToken.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1RequestToken.java index 1c53d4932..b8b3d2be4 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1RequestToken.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth1RequestToken.java @@ -83,12 +83,4 @@ public boolean equals(Object obj) { } return Objects.equals(getTokenSecret(), other.getTokenSecret()); } - - @Override - public String toString() { - return "OAuth1RequestToken{" - + "oauth_token=" + getToken() - + ", oauth_token_secret=" + getTokenSecret() - + ", oauth_callback_confirmed=" + oauthCallbackConfirmed + '}'; - } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java index b97e4e0a0..2b30f2031 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java @@ -131,14 +131,4 @@ public boolean equals(Object obj) { } return Objects.equals(expiresIn, other.getExpiresIn()); } - - @Override - public String toString() { - return "OAuth2AccessToken{" - + "access_token=" + accessToken - + ", token_type=" + tokenType - + ", expires_in=" + expiresIn - + ", refresh_token=" + refreshToken - + ", scope=" + scope + '}'; - } } From 4003852cdd58260346dd749ee1417e656e182a5a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 21 Nov 2017 13:26:01 +0300 Subject: [PATCH 021/481] add Apache HttpComponents HttpClient support in separate module (thanks to https://github.com/sschwieb) --- changelog | 1 + pom.xml | 6 ++ scribejava-apis/pom.xml | 6 ++ .../examples/FacebookAsyncApacheExample.java | 87 +++++++++++++++++++ scribejava-core/pom.xml | 9 -- .../core/httpclient/HttpClient.java | 5 +- .../core/httpclient/jdk/JDKHttpClient.java | 6 +- .../scribejava/core/oauth/OAuthService.java | 3 +- .../scribejava/core/AbstractClientTest.java | 42 +++++---- .../httpclient/jdk/JDKHttpClientTest.java | 2 +- scribejava-httpclient-ahc/pom.xml | 6 -- .../httpclient/ahc/AhcHttpClient.java | 53 ++++------- .../ahc/OAuthAsyncCompletionHandler.java | 7 +- .../httpclient/ahc/AhcHttpClientTest.java | 2 +- scribejava-httpclient-apache/pom.xml | 10 +-- .../httpclient/apache/ApacheHttpClient.java | 18 ++-- .../apache/ApacheHttpClientConfig.java | 13 ++- .../httpclient/apache/ApacheProvider.java | 2 +- .../apache/OAuthAsyncCompletionHandler.java | 25 ++++-- ...ibejava.core.httpclient.HttpClientProvider | 1 + .../OauthAsyncCompletionHandlerTest.java | 33 ++++--- scribejava-httpclient-ning/pom.xml | 6 -- .../httpclient/ning/NingHttpClient.java | 59 ++++--------- .../httpclient/ning/NingHttpClientTest.java | 3 +- scribejava-httpclient-okhttp/pom.xml | 6 -- .../httpclient/okhttp/OkHttpHttpClient.java | 4 + .../okhttp/OkHttpHttpClientTest.java | 3 +- 27 files changed, 240 insertions(+), 178 deletions(-) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java create mode 100644 scribejava-httpclient-apache/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider diff --git a/changelog b/changelog index fda68b66e..2c70fb103 100644 --- a/changelog +++ b/changelog @@ -10,6 +10,7 @@ * add OAuth2Service signRequest method accepting just String, not OAuth2 Access Token Object. Remove signRequest from abstract OAuthService. 2.0 and 1.0a will be a bit more different now. * drop toString method from *Tokens to prevent leak of sensible data (token ans secrets) (thanks to https://github.com/rcaa) + * add Apache HttpComponents HttpClient support in separate module (thanks to https://github.com/sschwieb) [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/pom.xml b/pom.xml index 054ecafb4..3af42a45a 100644 --- a/pom.xml +++ b/pom.xml @@ -97,6 +97,12 @@ compile true + + com.squareup.okhttp3 + mockwebserver + 3.9.0 + test + diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 583b8cdac..2042df1c2 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -38,6 +38,12 @@ ${project.version} test + + com.github.scribejava + scribejava-httpclient-apache + ${project.version} + test + diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java new file mode 100644 index 000000000..c15406779 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java @@ -0,0 +1,87 @@ +package com.github.scribejava.apis.examples; + +import java.util.Random; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; +import com.github.scribejava.apis.FacebookApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.httpclient.apache.ApacheHttpClientConfig; +import java.io.IOException; + +public final class FacebookAsyncApacheExample { + + private static final String NETWORK_NAME = "Facebook"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.8/me"; + + private FacebookAsyncApacheExample() { + } + + public static void main(String... args) throws InterruptedException, ExecutionException, IOException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + + try (OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .state(secretState) + .callback("http://www.example.com/oauth_callback/") + .httpClientConfig(ApacheHttpClientConfig.defaultConfig()) + .build(FacebookApi.instance())) { + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s Async OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code).get(); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } + } +} diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 460316e5d..bfb71c2bf 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -14,15 +14,6 @@ ScribeJava Core jar - - - com.squareup.okhttp3 - mockwebserver - 3.8.1 - test - - - diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java index 5793faf5c..a3bc0b5c5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java @@ -4,19 +4,18 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; +import java.io.Closeable; import java.io.File; import java.io.IOException; import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -public interface HttpClient { +public interface HttpClient extends Closeable { String DEFAULT_CONTENT_TYPE = "application/x-www-form-urlencoded"; String CONTENT_TYPE = "Content-Type"; String CONTENT_LENGTH = "Content-Length"; - void close() throws IOException; - Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index d02dc5e8b..5e173eb7e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -21,12 +21,16 @@ public class JDKHttpClient implements HttpClient { private final JDKHttpClientConfig config; + public JDKHttpClient() { + this(JDKHttpClientConfig.defaultConfig()); + } + public JDKHttpClient(JDKHttpClientConfig clientConfig) { config = clientConfig; } @Override - public void close() throws IOException { + public void close() { } @Override diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index cf2ca6252..710f1bb68 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -9,6 +9,7 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; +import java.io.Closeable; import java.io.File; import java.io.IOException; @@ -16,7 +17,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -public abstract class OAuthService implements AutoCloseable { +public abstract class OAuthService implements Closeable { private final OAuthConfig config; private final HttpClient httpClient; diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java index 0df7c6ad8..56780f80c 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java @@ -17,49 +17,48 @@ import org.junit.Before; import org.junit.Test; -import java.io.IOException; import java.util.concurrent.TimeUnit; import static org.junit.Assert.assertEquals; public abstract class AbstractClientTest { - class TestCallback implements OAuthAsyncRequestCallback { + private OAuthService oAuthService; - private Throwable throwable; - private T response; + private static class TestCallback implements OAuthAsyncRequestCallback { + + private Response response; @Override - public void onCompleted(T response) { + public void onCompleted(Response response) { this.response = response; } @Override public void onThrowable(Throwable throwable) { - this.throwable = throwable; } - } - private OAuthService oAuthService; - private HttpClient client; + public Response getResponse() { + return response; + } + } @Before public void setUp() { - client = createNewClient(); oAuthService = new OAuth20Service(null, - new OAuthConfig("test", "test", null, null, null, null, null, null, null, client)); + new OAuthConfig("test", "test", null, null, null, null, null, null, null, createNewClient())); } @After - public void shutDown() throws IOException { - client.close(); + public void shutDown() throws Exception { + oAuthService.close(); } protected abstract HttpClient createNewClient(); @Test public void shouldSendGetRequest() throws Exception { - final String expectedResponseBody = "response body"; + final String expectedResponseBody = "response body for test shouldSendGetRequest"; final MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setBody(expectedResponseBody)); @@ -80,7 +79,7 @@ public void shouldSendGetRequest() throws Exception { @Test public void shouldSendPostRequest() throws Exception { - final String expectedResponseBody = "response body"; + final String expectedResponseBody = "response body for test shouldSendPostRequest"; final String expectedRequestBody = "request body"; final MockWebServer server = new MockWebServer(); @@ -101,7 +100,6 @@ public void shouldSendPostRequest() throws Exception { assertEquals("POST", recordedRequest.getMethod()); assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); - // request with empty body request = new OAuthRequest(Verb.POST, baseUrl.toString()); response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); @@ -117,7 +115,7 @@ public void shouldSendPostRequest() throws Exception { @Test public void shouldReadResponseStream() throws Exception { - final String expectedResponseBody = "response body"; + final String expectedResponseBody = "response body for test shouldReadResponseStream"; final MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setBody(expectedResponseBody)); @@ -138,7 +136,7 @@ public void shouldReadResponseStream() throws Exception { @Test public void shouldCallCallback() throws Exception { - final String expectedResponseBody = "response body"; + final String expectedResponseBody = "response body for test shouldCallCallback"; final MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setBody(expectedResponseBody)); @@ -148,10 +146,10 @@ public void shouldCallCallback() throws Exception { final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString()); - final TestCallback callback = new TestCallback<>(); + final TestCallback callback = new TestCallback(); oAuthService.execute(request, callback).get(); - assertEquals(expectedResponseBody, callback.response.getBody()); + assertEquals(expectedResponseBody, callback.getResponse().getBody()); server.shutdown(); } @@ -167,11 +165,11 @@ public void shouldPassErrors() throws Exception { final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString()); - final TestCallback callback = new TestCallback<>(); + final TestCallback callback = new TestCallback(); final Response response = oAuthService.execute(request, callback).get(); assertEquals(500, response.getCode()); - assertEquals(500, callback.response.getCode()); + assertEquals(500, callback.getResponse().getCode()); server.shutdown(); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java index 09d34f0c3..6ac1070fa 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java @@ -7,6 +7,6 @@ public class JDKHttpClientTest extends AbstractClientTest { @Override protected HttpClient createNewClient() { - return new JDKHttpClient(JDKHttpClientConfig.defaultConfig()); + return new JDKHttpClient(); } } diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 652f24bc2..7cff01618 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -32,12 +32,6 @@ test-jar test - - com.squareup.okhttp3 - mockwebserver - 3.8.1 - test - diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java index cdc894bb8..ce705c372 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java @@ -13,6 +13,7 @@ import java.util.concurrent.Future; import java.io.File; +import java.util.function.Consumer; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.BoundRequestBuilder; @@ -20,6 +21,10 @@ public class AhcHttpClient extends AbstractAsyncOnlyHttpClient { private final AsyncHttpClient client; + public AhcHttpClient() { + this(AhcHttpClientConfig.defaultConfig()); + } + public AhcHttpClient(AhcHttpClientConfig ahcConfig) { final AsyncHttpClientConfig clientConfig = ahcConfig.getClientConfig(); client = clientConfig == null ? new DefaultAsyncHttpClient() : new DefaultAsyncHttpClient(clientConfig); @@ -37,28 +42,28 @@ public void close() throws IOException { @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.BYTE_ARRAY, bodyContents, callback, - converter); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + requestBuilder -> requestBuilder.setBody(bodyContents), callback, converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.STRING, bodyContents, callback, - converter); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + requestBuilder -> requestBuilder.setBody(bodyContents), callback, converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.FILE, bodyContents, callback, - converter); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + requestBuilder -> requestBuilder.setBody(bodyContents), callback, converter); } private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, BodySetter bodySetter, Object bodyContents, OAuthAsyncRequestCallback callback, + String completeUrl, Consumer bodySetter, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - BoundRequestBuilder boundRequestBuilder; + final BoundRequestBuilder boundRequestBuilder; switch (httpVerb) { case GET: boundRequestBuilder = client.prepareGet(completeUrl); @@ -78,41 +83,17 @@ private Future doExecuteAsync(String userAgent, Map heade if (httpVerb.isPermitBody()) { if (!headers.containsKey(CONTENT_TYPE)) { - boundRequestBuilder = boundRequestBuilder.addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + boundRequestBuilder.addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } - boundRequestBuilder = bodySetter.setBody(boundRequestBuilder, bodyContents); + bodySetter.accept(boundRequestBuilder); } - for (Map.Entry header : headers.entrySet()) { - boundRequestBuilder.addHeader(header.getKey(), header.getValue()); - } + headers.forEach((headerKey, headerValue) -> boundRequestBuilder.addHeader(headerKey, headerValue)); + if (userAgent != null) { boundRequestBuilder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); } return boundRequestBuilder.execute(new OAuthAsyncCompletionHandler<>(callback, converter)); } - - private enum BodySetter { - BYTE_ARRAY { - @Override - BoundRequestBuilder setBody(BoundRequestBuilder requestBuilder, Object bodyContents) { - return requestBuilder.setBody((byte[]) bodyContents); - } - }, - STRING { - @Override - BoundRequestBuilder setBody(BoundRequestBuilder requestBuilder, Object bodyContents) { - return requestBuilder.setBody((String) bodyContents); - } - }, - FILE { - @Override - BoundRequestBuilder setBody(BoundRequestBuilder requestBuilder, Object bodyContents) { - return requestBuilder.setBody((File) bodyContents); - } - }; - - abstract BoundRequestBuilder setBody(BoundRequestBuilder requestBuilder, Object bodyContents); - } } diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java index 856cbcf68..444f52226 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java @@ -3,7 +3,6 @@ import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -import io.netty.handler.codec.http.HttpHeaders; import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -22,11 +21,9 @@ public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, @Override public T onCompleted(org.asynchttpclient.Response ahcResponse) throws IOException { - final HttpHeaders map = ahcResponse.getHeaders(); final Map headersMap = new HashMap<>(); - for (Map.Entry header : map) { - headersMap.put(header.getKey(), header.getValue()); - } + ahcResponse.getHeaders().forEach(header -> headersMap.put(header.getKey(), header.getValue())); + final Response response = new Response(ahcResponse.getStatusCode(), ahcResponse.getStatusText(), headersMap, ahcResponse.getResponseBodyAsStream()); diff --git a/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java b/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java index 34d940205..5de2d153e 100644 --- a/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java +++ b/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java @@ -7,6 +7,6 @@ public class AhcHttpClientTest extends AbstractClientTest { @Override protected HttpClient createNewClient() { - return new AhcHttpClient(AhcHttpClientConfig.defaultConfig()); + return new AhcHttpClient(); } } diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 6ce5a545a..c004c990d 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -11,7 +11,7 @@ com.github.scribejava scribejava-httpclient-apache - ScribeJava Apache Http Client support + ScribeJava Apache HttpComponents HttpClient support jar @@ -23,7 +23,7 @@ org.apache.httpcomponents httpclient - 4.5.2 + 4.5.3 org.apache.httpcomponents @@ -37,12 +37,6 @@ test-jar test - - com.squareup.okhttp3 - mockwebserver - 3.8.1 - test - diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java index db6c8e48f..e11eb3393 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java @@ -12,20 +12,28 @@ import org.apache.http.entity.FileEntity; import org.apache.http.entity.StringEntity; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; -import org.apache.http.impl.nio.client.HttpAsyncClients; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.concurrent.Future; +import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; public class ApacheHttpClient extends AbstractAsyncOnlyHttpClient { private final CloseableHttpAsyncClient client; public ApacheHttpClient() { - this(HttpAsyncClients.createDefault()); + this(ApacheHttpClientConfig.defaultConfig()); + } + + public ApacheHttpClient(ApacheHttpClientConfig config) { + this(config.getHttpAsyncClientBuilder()); + } + + public ApacheHttpClient(HttpAsyncClientBuilder builder) { + this(builder.build()); } public ApacheHttpClient(CloseableHttpAsyncClient client) { @@ -72,9 +80,7 @@ private Future doExecuteAsync(String userAgent, Map heade builder.setEntity(entity); } - for (Map.Entry header : headers.entrySet()) { - builder.addHeader(header.getKey(), header.getValue()); - } + headers.forEach((headerKey, headerValue) -> builder.addHeader(headerKey, headerValue)); if (userAgent != null) { builder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); @@ -84,7 +90,7 @@ private Future doExecuteAsync(String userAgent, Map heade return new ApacheHttpFuture<>(future, handler); } - private RequestBuilder getRequestBuilder(Verb httpVerb) { + private static RequestBuilder getRequestBuilder(Verb httpVerb) { switch (httpVerb) { case GET: return RequestBuilder.get(); diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClientConfig.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClientConfig.java index 5ff523431..2a4f3a5b0 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClientConfig.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClientConfig.java @@ -1,15 +1,26 @@ package com.github.scribejava.httpclient.apache; import com.github.scribejava.core.httpclient.HttpClientConfig; +import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; public class ApacheHttpClientConfig implements HttpClientConfig { + private final HttpAsyncClientBuilder httpAsyncClientBuilder; + + public ApacheHttpClientConfig(HttpAsyncClientBuilder httpAsyncClientBuilder) { + this.httpAsyncClientBuilder = httpAsyncClientBuilder; + } + + public HttpAsyncClientBuilder getHttpAsyncClientBuilder() { + return httpAsyncClientBuilder; + } + @Override public HttpClientConfig createDefaultConfig() { return defaultConfig(); } public static ApacheHttpClientConfig defaultConfig() { - return new ApacheHttpClientConfig(); + return new ApacheHttpClientConfig(HttpAsyncClientBuilder.create()); } } diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheProvider.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheProvider.java index ed8efcf68..553972d1d 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheProvider.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheProvider.java @@ -9,7 +9,7 @@ public class ApacheProvider implements HttpClientProvider { @Override public HttpClient createClient(HttpClientConfig httpClientConfig) { if (httpClientConfig instanceof ApacheHttpClientConfig) { - return new ApacheHttpClient(); + return new ApacheHttpClient((ApacheHttpClientConfig) httpClientConfig); } return null; } diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java index e63f17179..eeef72e75 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java @@ -8,35 +8,41 @@ import org.apache.http.concurrent.FutureCallback; import java.io.IOException; +import java.util.Arrays; import java.util.Map; import java.util.concurrent.CancellationException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; -import java.util.stream.Stream; +import org.apache.http.StatusLine; public class OAuthAsyncCompletionHandler implements FutureCallback { - private final ResponseConverter converter; private final OAuthAsyncRequestCallback callback; + private final ResponseConverter converter; private final CountDownLatch latch; private T result; private Exception exception; public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, ResponseConverter converter) { - this.converter = converter; this.callback = callback; + this.converter = converter; this.latch = new CountDownLatch(1); } @Override public void completed(HttpResponse httpResponse) { try { - final Map headersMap = Stream.of(httpResponse.getAllHeaders()) + final Map headersMap = Arrays.stream(httpResponse.getAllHeaders()) .collect(Collectors.toMap(Header::getName, Header::getValue)); - final Response response = new Response(httpResponse.getStatusLine().getStatusCode(), - httpResponse.getStatusLine().getReasonPhrase(), headersMap, httpResponse.getEntity().getContent()); + + final StatusLine statusLine = httpResponse.getStatusLine(); + + final Response response = new Response(statusLine.getStatusCode(), statusLine.getReasonPhrase(), + headersMap, httpResponse.getEntity().getContent()); + @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); result = t; @@ -85,8 +91,11 @@ public T getResult() throws InterruptedException, ExecutionException { return result; } - public T getResult(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException { - latch.await(timeout, unit); + public T getResult(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { + + if (!latch.await(timeout, unit)) { + throw new TimeoutException(); + } if (exception != null) { throw new ExecutionException(exception); } diff --git a/scribejava-httpclient-apache/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider b/scribejava-httpclient-apache/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider new file mode 100644 index 000000000..651910028 --- /dev/null +++ b/scribejava-httpclient-apache/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider @@ -0,0 +1 @@ +com.github.scribejava.httpclient.apache.ApacheProvider diff --git a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java index f0309a173..89f3de1bc 100644 --- a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java @@ -25,7 +25,7 @@ public class OauthAsyncCompletionHandlerTest { private OAuthAsyncCompletionHandler handler; private TestCallback callback; - class TestCallback implements OAuthAsyncRequestCallback { + private static class TestCallback implements OAuthAsyncRequestCallback { private Throwable throwable; private String response; @@ -39,6 +39,15 @@ public void onCompleted(String response) { public void onThrowable(Throwable throwable) { this.throwable = throwable; } + + public Throwable getThrowable() { + return throwable; + } + + public String getResponse() { + return response; + } + } @Before @@ -55,8 +64,8 @@ public void shouldReleaseLatchOnSuccess() throws Exception { entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); handler.completed(response); - assertNotNull(callback.response); - assertNull(callback.throwable); + assertNotNull(callback.getResponse()); + assertNull(callback.getThrowable()); // verify latch is released assertEquals("All good", handler.getResult()); } @@ -72,9 +81,9 @@ public void shouldReleaseLatchOnIOException() throws Exception { entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); handler.completed(response); - assertNull(callback.response); - assertNotNull(callback.throwable); - assertTrue(callback.throwable instanceof IOException); + assertNull(callback.getResponse()); + assertNotNull(callback.getThrowable()); + assertTrue(callback.getThrowable() instanceof IOException); // verify latch is released try { handler.getResult(); @@ -93,9 +102,9 @@ public void shouldReleaseLatchOnCancel() throws Exception { entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); handler.cancelled(); - assertNull(callback.response); - assertNotNull(callback.throwable); - assertTrue(callback.throwable instanceof CancellationException); + assertNull(callback.getResponse()); + assertNotNull(callback.getThrowable()); + assertTrue(callback.getThrowable() instanceof CancellationException); // verify latch is released try { handler.getResult(); @@ -114,9 +123,9 @@ public void shouldReleaseLatchOnFailure() throws Exception { entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); handler.failed(new RuntimeException()); - assertNull(callback.response); - assertNotNull(callback.throwable); - assertTrue(callback.throwable instanceof RuntimeException); + assertNull(callback.getResponse()); + assertNotNull(callback.getThrowable()); + assertTrue(callback.getThrowable() instanceof RuntimeException); // verify latch is released try { handler.getResult(); diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 1d1673810..04551b961 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -32,12 +32,6 @@ test-jar test - - com.squareup.okhttp3 - mockwebserver - 3.8.1 - test - diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java index bcc843e00..32398b5aa 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java @@ -12,11 +12,16 @@ import com.ning.http.client.AsyncHttpClientConfig; import java.io.File; +import java.util.function.Consumer; public class NingHttpClient extends AbstractAsyncOnlyHttpClient { private final AsyncHttpClient client; + public NingHttpClient() { + this(NingHttpClientConfig.defaultConfig()); + } + public NingHttpClient(NingHttpClientConfig ningConfig) { final String ningAsyncHttpProviderClassName = ningConfig.getNingAsyncHttpProviderClassName(); AsyncHttpClientConfig config = ningConfig.getConfig(); @@ -43,30 +48,30 @@ public void close() { public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.BYTE_ARRAY, bodyContents, callback, - converter); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + requestBuilder -> requestBuilder.setBody(bodyContents), callback, converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.STRING, bodyContents, callback, - converter); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + requestBuilder -> requestBuilder.setBody(bodyContents), callback, converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.FILE, bodyContents, callback, - converter); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + requestBuilder -> requestBuilder.setBody(bodyContents), callback, converter); } private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, BodySetter bodySetter, Object bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; + String completeUrl, Consumer bodySetter, + OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + final AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; switch (httpVerb) { case GET: boundRequestBuilder = client.prepareGet(completeUrl); @@ -86,45 +91,17 @@ private Future doExecuteAsync(String userAgent, Map heade if (httpVerb.isPermitBody()) { if (!headers.containsKey(CONTENT_TYPE)) { - boundRequestBuilder = boundRequestBuilder.addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + boundRequestBuilder.addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } - boundRequestBuilder = bodySetter.setBody(boundRequestBuilder, bodyContents); + bodySetter.accept(boundRequestBuilder); } - for (Map.Entry header : headers.entrySet()) { - boundRequestBuilder.addHeader(header.getKey(), header.getValue()); - } + headers.forEach((headerKey, headerValue) -> boundRequestBuilder.addHeader(headerKey, headerValue)); + if (userAgent != null) { boundRequestBuilder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); } return boundRequestBuilder.execute(new OAuthAsyncCompletionHandler<>(callback, converter)); } - - private enum BodySetter { - BYTE_ARRAY { - @Override - AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder, - Object bodyContents) { - return requestBuilder.setBody((byte[]) bodyContents); - } - }, - STRING { - @Override - AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder, - Object bodyContents) { - return requestBuilder.setBody((String) bodyContents); - } - }, - FILE { - @Override - AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder, - Object bodyContents) { - return requestBuilder.setBody((File) bodyContents); - } - }; - - abstract AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder, - Object bodyContents); - } } diff --git a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/NingHttpClientTest.java b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/NingHttpClientTest.java index 8155cebf7..6ebf6456f 100644 --- a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/NingHttpClientTest.java +++ b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/NingHttpClientTest.java @@ -2,12 +2,11 @@ import com.github.scribejava.core.AbstractClientTest; import com.github.scribejava.core.httpclient.HttpClient; -import com.ning.http.client.AsyncHttpClient; public class NingHttpClientTest extends AbstractClientTest { @Override protected HttpClient createNewClient() { - return new NingHttpClient(new AsyncHttpClient()); + return new NingHttpClient(); } } diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 1d013f042..e63a88568 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -25,12 +25,6 @@ okhttp 3.9.0 - - com.squareup.okhttp3 - mockwebserver - 3.9.0 - test - com.github.scribejava scribejava-core diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 8090ef845..f4638d3ab 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -31,6 +31,10 @@ public class OkHttpHttpClient implements HttpClient { private final OkHttpClient client; + public OkHttpHttpClient() { + this(OkHttpHttpClientConfig.defaultConfig()); + } + public OkHttpHttpClient(OkHttpHttpClientConfig config) { final OkHttpClient.Builder clientBuilder = config.getClientBuilder(); client = clientBuilder == null ? new OkHttpClient() : clientBuilder.build(); diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java index 1bc31919b..80fdf2834 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClientTest.java @@ -2,12 +2,11 @@ import com.github.scribejava.core.AbstractClientTest; import com.github.scribejava.core.httpclient.HttpClient; -import okhttp3.OkHttpClient; public class OkHttpHttpClientTest extends AbstractClientTest { @Override protected HttpClient createNewClient() { - return new OkHttpHttpClient(new OkHttpClient()); + return new OkHttpHttpClient(); } } From fd4f99ef56bbefcc75f0a028d14522a4711ebb11 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 22 Nov 2017 16:37:23 +0300 Subject: [PATCH 022/481] add support for appsecret_proof in Facebook --- changelog | 1 + .../github/scribejava/apis/FacebookApi.java | 7 +++ .../com/github/scribejava/apis/ImgurApi.java | 7 ++- .../com/github/scribejava/apis/MailruApi.java | 7 ++- .../scribejava/apis/OdnoklassnikiApi.java | 7 ++- .../com/github/scribejava/apis/TutByApi.java | 7 ++- .../apis/service/FacebookService.java | 40 +++++++++++++++ .../apis/service/ImgurOAuthService.java | 39 +++++++++++++++ .../apis/service/ImgurOAuthServiceImpl.java | 35 +++---------- .../apis/service/MailruOAuthService.java | 48 ++++++++++++++++++ .../apis/service/MailruOAuthServiceImpl.java | 44 +++------------- .../service/OdnoklassnikiOAuthService.java | 50 +++++++++++++++++++ .../service/OdnoklassnikiServiceImpl.java | 46 +++-------------- .../apis/service/TutByOAuthService.java | 19 +++++++ .../apis/service/TutByOAuthServiceImpl.java | 15 +++--- 15 files changed, 240 insertions(+), 132 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java diff --git a/changelog b/changelog index 2c70fb103..c41771e81 100644 --- a/changelog +++ b/changelog @@ -11,6 +11,7 @@ Remove signRequest from abstract OAuthService. 2.0 and 1.0a will be a bit more different now. * drop toString method from *Tokens to prevent leak of sensible data (token ans secrets) (thanks to https://github.com/rcaa) * add Apache HttpComponents HttpClient support in separate module (thanks to https://github.com/sschwieb) + * add support for appsecret_proof in Facebook [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index 635a20e48..54f51cc25 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -1,10 +1,12 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.facebook.FacebookAccessTokenJsonExtractor; +import com.github.scribejava.apis.service.FacebookService; import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; /** @@ -53,4 +55,9 @@ public TokenExtractor getAccessTokenExtractor() { public ClientAuthenticationType getClientAuthenticationType() { return ClientAuthenticationType.REQUEST_BODY; } + + @Override + public FacebookService createService(OAuthConfig config) { + return new FacebookService(this, config); + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index 3b14473d1..477fb5e0f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.service.ImgurOAuthServiceImpl; +import com.github.scribejava.apis.service.ImgurOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.ParameterList; -import com.github.scribejava.core.oauth.OAuth20Service; import java.util.Map; public class ImgurApi extends DefaultApi20 { @@ -56,8 +55,8 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth20Service createService(OAuthConfig config) { - return new ImgurOAuthServiceImpl(this, config); + public ImgurOAuthService createService(OAuthConfig config) { + return new ImgurOAuthService(this, config); } public static boolean isOob(OAuthConfig config) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index a67e434c5..cf9ae9903 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -2,8 +2,7 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.apis.service.MailruOAuthServiceImpl; -import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.apis.service.MailruOAuthService; public class MailruApi extends DefaultApi20 { @@ -29,7 +28,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth20Service createService(OAuthConfig config) { - return new MailruOAuthServiceImpl(this, config); + public MailruOAuthService createService(OAuthConfig config) { + return new MailruOAuthService(this, config); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index df4e2e755..4582d1ac9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.service.OdnoklassnikiServiceImpl; +import com.github.scribejava.apis.service.OdnoklassnikiOAuthService; import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.oauth.OAuth20Service; public class OdnoklassnikiApi extends DefaultApi20 { @@ -31,8 +30,8 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth20Service createService(OAuthConfig config) { - return new OdnoklassnikiServiceImpl(this, config); + public OdnoklassnikiOAuthService createService(OAuthConfig config) { + return new OdnoklassnikiOAuthService(this, config); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java index 6928ba70a..0e7359f08 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java @@ -1,9 +1,8 @@ package com.github.scribejava.apis; +import com.github.scribejava.apis.service.TutByOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.apis.service.TutByOAuthServiceImpl; -import com.github.scribejava.core.oauth.OAuth20Service; public class TutByApi extends DefaultApi20 { @@ -29,7 +28,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth20Service createService(OAuthConfig config) { - return new TutByOAuthServiceImpl(this, config); + public TutByOAuthService createService(OAuthConfig config) { + return new TutByOAuthService(this, config); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java new file mode 100644 index 000000000..c506ce852 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java @@ -0,0 +1,40 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.util.Formatter; +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; + +public class FacebookService extends OAuth20Service { + + public FacebookService(DefaultApi20 api, OAuthConfig config) { + super(api, config); + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + super.signRequest(accessToken, request); + + final Mac mac; + try { + mac = Mac.getInstance("HmacSHA256"); + final SecretKeySpec secretKey = new SecretKeySpec(getConfig().getApiSecret().getBytes(), "HmacSHA256"); + mac.init(secretKey); + + final Formatter appsecretProof = new Formatter(); + + for (byte b : mac.doFinal(accessToken.getBytes())) { + appsecretProof.format("%02x", b); + } + + request.addParameter("appsecret_proof", appsecretProof.toString()); + } catch (NoSuchAlgorithmException | InvalidKeyException e) { + throw new IllegalStateException("There is a problem while generating Facebook appsecret_proof.", e); + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java new file mode 100644 index 000000000..89edf0198 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java @@ -0,0 +1,39 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.apis.ImgurApi; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; + +public class ImgurOAuthService extends OAuth20Service { + + public ImgurOAuthService(DefaultApi20 api, OAuthConfig config) { + super(api, config); + } + + @Override + protected OAuthRequest createAccessTokenRequest(String oauthVerifier) { + final DefaultApi20 api = getApi(); + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); + final OAuthConfig config = getConfig(); + request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); + request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); + + if (ImgurApi.isOob(config)) { + request.addBodyParameter(OAuthConstants.GRANT_TYPE, "pin"); + request.addBodyParameter("pin", oauthVerifier); + } else { + request.addBodyParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); + request.addBodyParameter(OAuthConstants.CODE, oauthVerifier); + } + return request; + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + request.addHeader("Authorization", + accessToken == null ? "Client-ID " + getConfig().getApiKey() : "Bearer " + accessToken); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java index c77de1b70..b7ee9b1ad 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java @@ -1,39 +1,16 @@ package com.github.scribejava.apis.service; -import com.github.scribejava.apis.ImgurApi; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; -public class ImgurOAuthServiceImpl extends OAuth20Service { +/** + * + * @deprecated renamed to {@link ImgurOAuthService} + */ +@Deprecated +public class ImgurOAuthServiceImpl extends ImgurOAuthService { public ImgurOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { super(api, config); } - - @Override - protected OAuthRequest createAccessTokenRequest(String oauthVerifier) { - final DefaultApi20 api = getApi(); - final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - final OAuthConfig config = getConfig(); - request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); - - if (ImgurApi.isOob(config)) { - request.addBodyParameter(OAuthConstants.GRANT_TYPE, "pin"); - request.addBodyParameter("pin", oauthVerifier); - } else { - request.addBodyParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); - request.addBodyParameter(OAuthConstants.CODE, oauthVerifier); - } - return request; - } - - @Override - public void signRequest(String accessToken, OAuthRequest request) { - request.addHeader("Authorization", - accessToken == null ? "Client-ID " + getConfig().getApiKey() : "Bearer " + accessToken); - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java new file mode 100644 index 000000000..0e426f337 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java @@ -0,0 +1,48 @@ +package com.github.scribejava.apis.service; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.Map; +import java.util.TreeMap; +import org.apache.commons.codec.CharEncoding; +import static org.apache.commons.codec.digest.DigestUtils.md5Hex; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.util.stream.Collectors; + +public class MailruOAuthService extends OAuth20Service { + + public MailruOAuthService(DefaultApi20 api, OAuthConfig config) { + super(api, config); + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + // sig = md5(params + secret_key) + request.addQuerystringParameter("session_key", accessToken); + request.addQuerystringParameter("app_id", getConfig().getApiKey()); + final String completeUrl = request.getCompleteUrl(); + + try { + final String clientSecret = getConfig().getApiSecret(); + final int queryIndex = completeUrl.indexOf('?'); + if (queryIndex != -1) { + final String urlPart = completeUrl.substring(queryIndex + 1); + final Map map = new TreeMap<>(); + for (String param : urlPart.split("&")) { + final String[] parts = param.split("="); + map.put(parts[0], (parts.length == 1) ? "" : parts[1]); + } + final String urlNew = map.entrySet().stream() + .map(entry -> entry.getKey() + '=' + entry.getValue()) + .collect(Collectors.joining()); + final String sigSource = URLDecoder.decode(urlNew, CharEncoding.UTF_8) + clientSecret; + request.addQuerystringParameter("sig", md5Hex(sigSource)); + } + } catch (UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java index 2b6e3cc3e..4301fd8fb 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java @@ -1,48 +1,16 @@ package com.github.scribejava.apis.service; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.Map; -import java.util.TreeMap; -import org.apache.commons.codec.CharEncoding; -import static org.apache.commons.codec.digest.DigestUtils.md5Hex; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; -import java.util.stream.Collectors; -public class MailruOAuthServiceImpl extends OAuth20Service { +/** + * + * @deprecated renamed to {@link MailruOAuthService} + */ +@Deprecated +public class MailruOAuthServiceImpl extends MailruOAuthService { public MailruOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { super(api, config); } - - @Override - public void signRequest(String accessToken, OAuthRequest request) { - // sig = md5(params + secret_key) - request.addQuerystringParameter("session_key", accessToken); - request.addQuerystringParameter("app_id", getConfig().getApiKey()); - final String completeUrl = request.getCompleteUrl(); - - try { - final String clientSecret = getConfig().getApiSecret(); - final int queryIndex = completeUrl.indexOf('?'); - if (queryIndex != -1) { - final String urlPart = completeUrl.substring(queryIndex + 1); - final Map map = new TreeMap<>(); - for (String param : urlPart.split("&")) { - final String[] parts = param.split("="); - map.put(parts[0], (parts.length == 1) ? "" : parts[1]); - } - final String urlNew = map.entrySet().stream() - .map(entry -> entry.getKey() + '=' + entry.getValue()) - .collect(Collectors.joining()); - final String sigSource = URLDecoder.decode(urlNew, CharEncoding.UTF_8) + clientSecret; - request.addQuerystringParameter("sig", md5Hex(sigSource)); - } - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException(e); - } - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java new file mode 100644 index 000000000..0bf117edd --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java @@ -0,0 +1,50 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Parameter; +import com.github.scribejava.core.model.ParameterList; +import com.github.scribejava.core.oauth.OAuth20Service; + +import org.apache.commons.codec.CharEncoding; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import static org.apache.commons.codec.digest.DigestUtils.md5Hex; + +public class OdnoklassnikiOAuthService extends OAuth20Service { + + public OdnoklassnikiOAuthService(DefaultApi20 api, OAuthConfig config) { + super(api, config); + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + //sig = lower(md5( sorted_request_params_composed_string + md5(access_token + application_secret_key))) + try { + final String tokenDigest = md5Hex(accessToken + getConfig().getApiSecret()); + + final ParameterList queryParams = request.getQueryStringParams(); + queryParams.addAll(request.getBodyParams()); + final List allParams = queryParams.getParams(); + + Collections.sort(allParams); + + final String stringParams = allParams.stream() + .map(param -> param.getKey() + '=' + param.getValue()) + .collect(Collectors.joining()); + + final String sigSource = URLDecoder.decode(stringParams, CharEncoding.UTF_8) + tokenDigest; + request.addQuerystringParameter("sig", md5Hex(sigSource).toLowerCase()); + + super.signRequest(accessToken, request); + } catch (UnsupportedEncodingException unex) { + throw new IllegalStateException(unex); + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java index 6d3850cc2..6e001447e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java @@ -2,49 +2,15 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Parameter; -import com.github.scribejava.core.model.ParameterList; -import com.github.scribejava.core.oauth.OAuth20Service; -import org.apache.commons.codec.CharEncoding; - -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import static org.apache.commons.codec.digest.DigestUtils.md5Hex; - -public class OdnoklassnikiServiceImpl extends OAuth20Service { +/** + * + * @deprecated renamed to {@link OdnoklassnikiOAuthService} + */ +@Deprecated +public class OdnoklassnikiServiceImpl extends OdnoklassnikiOAuthService { public OdnoklassnikiServiceImpl(DefaultApi20 api, OAuthConfig config) { super(api, config); } - - @Override - public void signRequest(String accessToken, OAuthRequest request) { - //sig = lower(md5( sorted_request_params_composed_string + md5(access_token + application_secret_key))) - try { - final String tokenDigest = md5Hex(accessToken + getConfig().getApiSecret()); - - final ParameterList queryParams = request.getQueryStringParams(); - queryParams.addAll(request.getBodyParams()); - final List allParams = queryParams.getParams(); - - Collections.sort(allParams); - - final String stringParams = allParams.stream() - .map(param -> param.getKey() + '=' + param.getValue()) - .collect(Collectors.joining()); - - final String sigSource = URLDecoder.decode(stringParams, CharEncoding.UTF_8) + tokenDigest; - request.addQuerystringParameter("sig", md5Hex(sigSource).toLowerCase()); - - super.signRequest(accessToken, request); - } catch (UnsupportedEncodingException unex) { - throw new IllegalStateException(unex); - } - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java new file mode 100644 index 000000000..ea9f8aa7b --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java @@ -0,0 +1,19 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; + +public class TutByOAuthService extends OAuth20Service { + + public TutByOAuthService(DefaultApi20 api, OAuthConfig config) { + super(api, config); + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + request.addQuerystringParameter(OAuthConstants.TOKEN, accessToken); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java index b199ac66a..64af14d84 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java @@ -2,18 +2,15 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; -public class TutByOAuthServiceImpl extends OAuth20Service { +/** + * + * @deprecated renamed to {@link TutByOAuthService} + */ +@Deprecated +public class TutByOAuthServiceImpl extends TutByOAuthService { public TutByOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { super(api, config); } - - @Override - public void signRequest(String accessToken, OAuthRequest request) { - request.addQuerystringParameter(OAuthConstants.TOKEN, accessToken); - } } From a4ce21509e9d61053849913f66a55a46b88ffbaa Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 22 Nov 2017 16:42:55 +0300 Subject: [PATCH 023/481] update Facebook v2.8 -> v2.11 --- changelog | 1 + .../main/java/com/github/scribejava/apis/FacebookApi.java | 6 +++--- .../apis/examples/FacebookAsyncApacheExample.java | 2 +- .../scribejava/apis/examples/FacebookAsyncNingExample.java | 2 +- .../github/scribejava/apis/examples/FacebookExample.java | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/changelog b/changelog index c41771e81..9ccba0fbc 100644 --- a/changelog +++ b/changelog @@ -12,6 +12,7 @@ * drop toString method from *Tokens to prevent leak of sensible data (token ans secrets) (thanks to https://github.com/rcaa) * add Apache HttpComponents HttpClient support in separate module (thanks to https://github.com/sschwieb) * add support for appsecret_proof in Facebook + * update Facebook v2.8 -> v2.11 [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index 54f51cc25..f67c36136 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -10,7 +10,7 @@ import com.github.scribejava.core.model.Verb; /** - * Facebook v2.8 API + * Facebook v2.11 API */ public class FacebookApi extends DefaultApi20 { @@ -33,7 +33,7 @@ public Verb getAccessTokenVerb() { @Override public String getAccessTokenEndpoint() { - return "https://graph.facebook.com/v2.8/oauth/access_token"; + return "https://graph.facebook.com/v2.11/oauth/access_token"; } @Override @@ -43,7 +43,7 @@ public String getRefreshTokenEndpoint() { @Override protected String getAuthorizationBaseUrl() { - return "https://www.facebook.com/v2.8/dialog/oauth"; + return "https://www.facebook.com/v2.11/dialog/oauth"; } @Override diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java index c15406779..461576775 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java @@ -16,7 +16,7 @@ public final class FacebookAsyncApacheExample { private static final String NETWORK_NAME = "Facebook"; - private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.8/me"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.11/me"; private FacebookAsyncApacheExample() { } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index 73062a43c..292d1b9f2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -17,7 +17,7 @@ public final class FacebookAsyncNingExample { private static final String NETWORK_NAME = "Facebook"; - private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.8/me"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.11/me"; private FacebookAsyncNingExample() { } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index c4c54897d..c0721835d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -15,7 +15,7 @@ public final class FacebookExample { private static final String NETWORK_NAME = "Facebook"; - private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.8/me"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.11/me"; private FacebookExample() { } From dace89cb48934d553bce5087a55b56ccfb467003 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 22 Nov 2017 16:46:09 +0300 Subject: [PATCH 024/481] update some deps --- pom.xml | 4 ++-- scribejava-httpclient-okhttp/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 3af42a45a..1b9cfb537 100644 --- a/pom.xml +++ b/pom.xml @@ -100,7 +100,7 @@ com.squareup.okhttp3 mockwebserver - 3.9.0 + 3.9.1 test @@ -139,7 +139,7 @@ com.puppycrawl.tools checkstyle - 8.3 + 8.4 diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index e63a88568..7c78aa158 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 3.9.0 + 3.9.1 com.github.scribejava From f7f19b137a6d2c30e95351df323f697a0875368e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 22 Nov 2017 17:00:15 +0300 Subject: [PATCH 025/481] version of Facebook API can be configured while constructing OAuthService - use FacebookApi.customVersion("2.11") --- changelog | 2 +- .../com/github/scribejava/apis/FacebookApi.java | 17 ++++++++++++++--- .../apis/examples/Google20RevokeExample.java | 3 ++- .../VkontakteClientCredentialsGrantExample.java | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/changelog b/changelog index 9ccba0fbc..12ca3a11d 100644 --- a/changelog +++ b/changelog @@ -12,7 +12,7 @@ * drop toString method from *Tokens to prevent leak of sensible data (token ans secrets) (thanks to https://github.com/rcaa) * add Apache HttpComponents HttpClient support in separate module (thanks to https://github.com/sschwieb) * add support for appsecret_proof in Facebook - * update Facebook v2.8 -> v2.11 + * update Facebook v2.8 -> v2.11 (version can be configured while constructing OAuthService - use FacebookApi.customVersion("2.11")) [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index f67c36136..949304dfb 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -10,11 +10,18 @@ import com.github.scribejava.core.model.Verb; /** - * Facebook v2.11 API + * Facebook API */ public class FacebookApi extends DefaultApi20 { + private final String version; + protected FacebookApi() { + this("2.11"); + } + + protected FacebookApi(String version) { + this.version = version; } private static class InstanceHolder { @@ -26,6 +33,10 @@ public static FacebookApi instance() { return InstanceHolder.INSTANCE; } + public static FacebookApi customVersion(String version) { + return new FacebookApi(version); + } + @Override public Verb getAccessTokenVerb() { return Verb.GET; @@ -33,7 +44,7 @@ public Verb getAccessTokenVerb() { @Override public String getAccessTokenEndpoint() { - return "https://graph.facebook.com/v2.11/oauth/access_token"; + return "https://graph.facebook.com/v" + version + "/oauth/access_token"; } @Override @@ -43,7 +54,7 @@ public String getRefreshTokenEndpoint() { @Override protected String getAuthorizationBaseUrl() { - return "https://www.facebook.com/v2.11/dialog/oauth"; + return "https://www.facebook.com/v" + version + "/dialog/oauth"; } @Override diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java index 7e677731c..89d36be2c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java @@ -86,7 +86,8 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Revoking token..."); service.revokeToken(accessToken.getAccessToken()); System.out.println("done."); - System.out.println("After revoke we should fail requesting any data..."); + System.out.println("After revoke we should fail requesting any data... Press enter to try"); + in.nextLine(); //Google Note: Following a successful revocation response, //it might take some time before the revocation has full effect. while (response.getCode() == 200) { diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java index b91b115f3..0ffc2fc13 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java @@ -29,7 +29,7 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth2AccessToken accessToken = service.getAccessTokenClientCredentialsGrant(); System.out.println("Got the Access Token!"); - System.out.println(accessToken); + System.out.println(accessToken.getRawResponse()); System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); From 6024845ce66bf60d37e917a863a4ae137aef4cfb Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 22 Nov 2017 17:06:59 +0300 Subject: [PATCH 026/481] prepare 5.0.0 --- README.md | 9 +++++---- changelog | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 567d5075b..a8ed20a7f 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,10 @@ Hit ScribeJava as hard and with many threads as you like. ScribeJava support out-of-box several HTTP clients: * ning async http client 1.9.x (maven module scribejava-httpclient-ning) - * asynchttpclient 2.x (maven module scribejava-httpclient-ahc) + * Async Http Client asynchttpclient 2.x (maven module scribejava-httpclient-ahc) * OkHttp (maven module scribejava-httpclient-okhttp) - + * Apache HttpComponents HttpClient (maven module scribejava-httpclient-apache) + just add corresponding maven modules to your pom ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box @@ -102,7 +103,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 4.2.0 + 5.0.0 ``` @@ -111,7 +112,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 4.2.0 + 5.0.0 ``` diff --git a/changelog b/changelog index 12ca3a11d..c1a691a34 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[5.0.0] * drop Java 7 backward compatibility support, become Java 8 only * add JSON token extractor for OAuth 1.0a (thanks to https://github.com/evstropovv) * add new API - uCoz (https://www.ucoz.com/) (thanks to https://github.com/evstropovv) From 69613265c6cf121b5c9687cd2966eb116674dd21 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 22 Nov 2017 17:08:11 +0300 Subject: [PATCH 027/481] [maven-release-plugin] prepare release scribejava-5.0.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 1b9cfb537..41b4cbce7 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 4.2.1-SNAPSHOT + 5.0.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-5.0.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 2042df1c2..e4a8d7bdd 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.1-SNAPSHOT + 5.0.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index bfb71c2bf..082932072 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.1-SNAPSHOT + 5.0.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 7cff01618..a1b042a86 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.1-SNAPSHOT + 5.0.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index c004c990d..b9708b4d5 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.1-SNAPSHOT + 5.0.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 04551b961..ca7a29ba9 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.1-SNAPSHOT + 5.0.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 7c78aa158..25d9149ed 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 4.2.1-SNAPSHOT + 5.0.0 ../pom.xml From 4f2743793f408e285bcc42b1a5e03f789f0a7483 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 22 Nov 2017 17:08:18 +0300 Subject: [PATCH 028/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 41b4cbce7..eb85fa190 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.0.0 + 5.0.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-5.0.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index e4a8d7bdd..9a7b21a63 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.0 + 5.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 082932072..3af1df7aa 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.0 + 5.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index a1b042a86..5a35925a3 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.0 + 5.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index b9708b4d5..95b48da1b 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.0 + 5.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index ca7a29ba9..bb88941ae 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.0 + 5.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 25d9149ed..c032e7667 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.0 + 5.0.1-SNAPSHOT ../pom.xml From 8d1527b5f2e6ad797ce9505cee04e2013b5bf67c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 22 Nov 2017 17:42:46 +0300 Subject: [PATCH 029/481] drop optional dependency on Apache commons-codec --- changelog | 3 ++ pom.xml | 7 ---- .../apis/service/ImgurOAuthServiceImpl.java | 16 --------- .../apis/service/MailruOAuthService.java | 26 +++++++++++--- .../apis/service/MailruOAuthServiceImpl.java | 16 --------- .../service/OdnoklassnikiOAuthService.java | 30 +++++++++++----- .../service/OdnoklassnikiServiceImpl.java | 16 --------- .../apis/service/TutByOAuthServiceImpl.java | 16 --------- .../apis/examples/RenrenExample.java | 13 ++++--- .../core/builder/api/OAuth2SignatureType.java | 12 ------- .../core/pkce/PKCECodeChallengeMethod.java | 3 +- .../core/services/Base64Encoder.java | 32 ----------------- .../core/services/CommonsEncoder.java | 35 ------------------- .../services/DatatypeConverterEncoder.java | 20 ----------- .../core/oauth/OAuth20ServiceTest.java | 12 ++++--- 15 files changed, 60 insertions(+), 197 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/services/CommonsEncoder.java delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/services/DatatypeConverterEncoder.java diff --git a/changelog b/changelog index c1a691a34..a05a60c6e 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * drop optional dependency on Apache commons-codec + [5.0.0] * drop Java 7 backward compatibility support, become Java 8 only * add JSON token extractor for OAuth 1.0a (thanks to https://github.com/evstropovv) diff --git a/pom.xml b/pom.xml index eb85fa190..5fda43fc8 100644 --- a/pom.xml +++ b/pom.xml @@ -90,13 +90,6 @@ 2.8.2 test - - commons-codec - commons-codec - 1.11 - compile - true - com.squareup.okhttp3 mockwebserver diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java deleted file mode 100644 index b7ee9b1ad..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthServiceImpl.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; - -/** - * - * @deprecated renamed to {@link ImgurOAuthService} - */ -@Deprecated -public class ImgurOAuthServiceImpl extends ImgurOAuthService { - - public ImgurOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { - super(api, config); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java index 0e426f337..625140ed9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java @@ -1,15 +1,17 @@ package com.github.scribejava.apis.service; -import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.Map; import java.util.TreeMap; -import org.apache.commons.codec.CharEncoding; -import static org.apache.commons.codec.digest.DigestUtils.md5Hex; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Formatter; import java.util.stream.Collectors; public class MailruOAuthService extends OAuth20Service { @@ -38,11 +40,25 @@ public void signRequest(String accessToken, OAuthRequest request) { final String urlNew = map.entrySet().stream() .map(entry -> entry.getKey() + '=' + entry.getValue()) .collect(Collectors.joining()); - final String sigSource = URLDecoder.decode(urlNew, CharEncoding.UTF_8) + clientSecret; - request.addQuerystringParameter("sig", md5Hex(sigSource)); + final String sigSource = URLDecoder.decode(urlNew, "UTF-8") + clientSecret; + request.addQuerystringParameter("sig", md5(sigSource)); } } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } } + + public static String md5(String orgString) { + try { + final MessageDigest md = MessageDigest.getInstance("MD5"); + final byte[] array = md.digest(orgString.getBytes(Charset.forName("UTF-8"))); + final Formatter builder = new Formatter(); + for (byte b : array) { + builder.format("%02x", b); + } + return builder.toString(); + } catch (NoSuchAlgorithmException e) { + throw new IllegalStateException("MD5 is unsupported?", e); + } + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java deleted file mode 100644 index 4301fd8fb..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthServiceImpl.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; - -/** - * - * @deprecated renamed to {@link MailruOAuthService} - */ -@Deprecated -public class MailruOAuthServiceImpl extends MailruOAuthService { - - public MailruOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { - super(api, config); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java index 0bf117edd..4b0ea020b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java @@ -6,17 +6,17 @@ import com.github.scribejava.core.model.Parameter; import com.github.scribejava.core.model.ParameterList; import com.github.scribejava.core.oauth.OAuth20Service; - -import org.apache.commons.codec.CharEncoding; - import java.io.UnsupportedEncodingException; + import java.net.URLDecoder; +import java.nio.charset.Charset; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.Collections; +import java.util.Formatter; import java.util.List; import java.util.stream.Collectors; -import static org.apache.commons.codec.digest.DigestUtils.md5Hex; - public class OdnoklassnikiOAuthService extends OAuth20Service { public OdnoklassnikiOAuthService(DefaultApi20 api, OAuthConfig config) { @@ -27,7 +27,7 @@ public OdnoklassnikiOAuthService(DefaultApi20 api, OAuthConfig config) { public void signRequest(String accessToken, OAuthRequest request) { //sig = lower(md5( sorted_request_params_composed_string + md5(access_token + application_secret_key))) try { - final String tokenDigest = md5Hex(accessToken + getConfig().getApiSecret()); + final String tokenDigest = md5(accessToken + getConfig().getApiSecret()); final ParameterList queryParams = request.getQueryStringParams(); queryParams.addAll(request.getBodyParams()); @@ -39,12 +39,26 @@ public void signRequest(String accessToken, OAuthRequest request) { .map(param -> param.getKey() + '=' + param.getValue()) .collect(Collectors.joining()); - final String sigSource = URLDecoder.decode(stringParams, CharEncoding.UTF_8) + tokenDigest; - request.addQuerystringParameter("sig", md5Hex(sigSource).toLowerCase()); + final String sigSource = URLDecoder.decode(stringParams, "UTF-8") + tokenDigest; + request.addQuerystringParameter("sig", md5(sigSource).toLowerCase()); super.signRequest(accessToken, request); } catch (UnsupportedEncodingException unex) { throw new IllegalStateException(unex); } } + + public static String md5(String orgString) { + try { + final MessageDigest md = MessageDigest.getInstance("MD5"); + final byte[] array = md.digest(orgString.getBytes(Charset.forName("UTF-8"))); + final Formatter builder = new Formatter(); + for (byte b : array) { + builder.format("%02x", b); + } + return builder.toString(); + } catch (NoSuchAlgorithmException e) { + throw new IllegalStateException("MD5 is unsupported?", e); + } + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java deleted file mode 100644 index 6e001447e..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiServiceImpl.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; - -/** - * - * @deprecated renamed to {@link OdnoklassnikiOAuthService} - */ -@Deprecated -public class OdnoklassnikiServiceImpl extends OdnoklassnikiOAuthService { - - public OdnoklassnikiServiceImpl(DefaultApi20 api, OAuthConfig config) { - super(api, config); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java deleted file mode 100644 index 64af14d84..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthServiceImpl.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; - -/** - * - * @deprecated renamed to {@link TutByOAuthService} - */ -@Deprecated -public class TutByOAuthServiceImpl extends TutByOAuthService { - - public TutByOAuthServiceImpl(DefaultApi20 api, OAuthConfig config) { - super(api, config); - } -} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 621566f6e..31f043d6e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -15,6 +15,7 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.Formatter; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -96,15 +97,13 @@ public static String md5(String orgString) { try { final MessageDigest md = MessageDigest.getInstance("MD5"); final byte[] array = md.digest(orgString.getBytes(Charset.forName("UTF-8"))); - final StringBuffer sb = new StringBuffer(); - for (int i = 0; i < array.length; ++i) { - sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3)); + final Formatter builder = new Formatter(); + for (byte b : array) { + builder.format("%02x", b); } - return sb.toString(); + return builder.toString(); } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); + throw new IllegalStateException("MD5 is unsupported?", e); } - return null; } - } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java index b2334be32..c42b54d98 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java @@ -1,6 +1,5 @@ package com.github.scribejava.core.builder.api; -import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; @@ -26,16 +25,5 @@ public void signRequest(String accessToken, OAuthRequest request) { }; - /** - * - * @param accessToken accessToken - * @param request request - * @deprecated use {@link #signRequest(java.lang.String, com.github.scribejava.core.model.OAuthRequest)} - */ - @Deprecated - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { - signRequest(accessToken == null ? null : accessToken.getAccessToken(), request); - } - public abstract void signRequest(String accessToken, OAuthRequest request); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java index e8e6cb6e2..69dbe17c6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java @@ -12,8 +12,7 @@ public enum PKCECodeChallengeMethod { @Override public String transform2CodeChallenge(String codeVerifier) throws NoSuchAlgorithmException { return base64Encoder.encodeToString( - MessageDigest.getInstance("SHA-256").digest( - codeVerifier.getBytes(StandardCharsets.US_ASCII))); + MessageDigest.getInstance("SHA-256").digest(codeVerifier.getBytes(StandardCharsets.US_ASCII))); } }, plain { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java deleted file mode 100644 index 26285cda4..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.github.scribejava.core.services; - -/** - * @deprecated use standard java8 java.util.Base64 - */ -@Deprecated -public abstract class Base64Encoder { - - private static class InstanceHolder { - private static final Base64Encoder INSTANCE = createEncoderInstance(); - } - - public static Base64Encoder getInstance() { - return InstanceHolder.INSTANCE; - } - - private static Base64Encoder createEncoderInstance() { - if (CommonsEncoder.isPresent()) { - return new CommonsEncoder(); - } else { - return new DatatypeConverterEncoder(); - } - } - - public static String type() { - return getInstance().getType(); - } - - public abstract String encode(byte[] bytes); - - public abstract String getType(); -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/CommonsEncoder.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/CommonsEncoder.java deleted file mode 100644 index c982abfcd..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/CommonsEncoder.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.github.scribejava.core.services; - -import java.io.UnsupportedEncodingException; -import org.apache.commons.codec.binary.Base64; -import com.github.scribejava.core.exceptions.OAuthSignatureException; - -/** - * @deprecated use standard java8 java.util.Base64 - */ -@Deprecated -public class CommonsEncoder extends Base64Encoder { - - @Override - public String encode(byte[] bytes) { - try { - return new String(Base64.encodeBase64(bytes), "UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new OAuthSignatureException("Can't perform base64 encoding", e); - } - } - - @Override - public String getType() { - return "CommonsCodec"; - } - - public static boolean isPresent() { - try { - Class.forName("org.apache.commons.codec.binary.Base64"); - return true; - } catch (ClassNotFoundException e) { - return false; - } - } -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/DatatypeConverterEncoder.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/DatatypeConverterEncoder.java deleted file mode 100644 index cfc8c2ef2..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/DatatypeConverterEncoder.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.scribejava.core.services; - -import javax.xml.bind.DatatypeConverter; - -/** - * @deprecated use standard java8 java.util.Base64 - */ -@Deprecated -public class DatatypeConverterEncoder extends Base64Encoder { - - @Override - public String encode(byte[] bytes) { - return DatatypeConverter.printBase64Binary(bytes); - } - - @Override - public String getType() { - return "DatatypeConverter"; - } -} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java index 581fc5a63..f62c49e86 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java @@ -4,7 +4,6 @@ import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2Authorization; import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.services.Base64Encoder; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import java.io.IOException; @@ -13,11 +12,14 @@ import org.junit.Test; import java.nio.charset.Charset; +import java.util.Base64; import java.util.Map; import java.util.concurrent.ExecutionException; public class OAuth20ServiceTest { + private final Base64.Encoder base64Encoder = Base64.getEncoder(); + @Test public void shouldProduceCorrectRequestSync() throws IOException, InterruptedException, ExecutionException { final OAuth20Service service = new ServiceBuilder("your_api_key") @@ -35,8 +37,8 @@ public void shouldProduceCorrectRequestSync() throws IOException, InterruptedExc assertEquals(OAuth20ServiceUnit.STATE, map.get(OAuthConstants.STATE)); assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); - final String authorize = Base64Encoder.getInstance() - .encode(String.format("%s:%s", service.getConfig().getApiKey(), service.getConfig().getApiSecret()) + final String authorize = base64Encoder.encodeToString( + String.format("%s:%s", service.getConfig().getApiKey(), service.getConfig().getApiSecret()) .getBytes(Charset.forName("UTF-8"))); assertEquals(OAuthConstants.BASIC + " " + authorize, map.get(OAuthConstants.HEADER)); @@ -63,8 +65,8 @@ public void shouldProduceCorrectRequestAsync() throws ExecutionException, Interr assertEquals(OAuth20ServiceUnit.STATE, map.get(OAuthConstants.STATE)); assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); - final String authorize = Base64Encoder.getInstance() - .encode(String.format("%s:%s", service.getConfig().getApiKey(), service.getConfig().getApiSecret()) + final String authorize = base64Encoder.encodeToString( + String.format("%s:%s", service.getConfig().getApiKey(), service.getConfig().getApiSecret()) .getBytes(Charset.forName("UTF-8"))); assertEquals(OAuthConstants.BASIC + " " + authorize, map.get(OAuthConstants.HEADER)); From aa6098bffa9ae3a7876a5419f91c78c79acfcab2 Mon Sep 17 00:00:00 2001 From: Ruben Andreassen Date: Sun, 3 Dec 2017 20:08:32 +0100 Subject: [PATCH 030/481] Added DataportenApi --- .../github/scribejava/apis/DataportenApi.java | 41 ++++++++++ .../apis/examples/DataportenExample.java | 81 +++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/DataportenApi.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DataportenApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DataportenApi.java new file mode 100644 index 000000000..99acbd4df --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DataportenApi.java @@ -0,0 +1,41 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.Verb; + +public class DataportenApi extends DefaultApi20 { + + protected DataportenApi() { + } + + private static class InstanceHolder { + private static final DataportenApi INSTANCE = new DataportenApi(); + } + + public static DataportenApi instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://auth.dataporten.no/oauth/token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://auth.dataporten.no/oauth/authorization"; + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java new file mode 100644 index 000000000..00b75c26d --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java @@ -0,0 +1,81 @@ +package com.github.scribejava.apis.examples; + +import java.util.Random; +import java.util.Scanner; +import com.github.scribejava.apis.DataportenApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +public final class DataportenExample { + + private static final String NETWORK_NAME = "Dataporten"; + private static final String PROTECTED_RESOURCE_URL = "https://auth.dataporten.no/userinfo"; + + private DataportenExample() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .state(secretState) + .callback("http://www.example.com/oauth_callback/") + .build(DataportenApi.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} From dc5f6acfb55455148f5aca6b6ec99164c8413624 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 4 Dec 2017 13:51:14 +0300 Subject: [PATCH 031/481] add API - Dataporten (https://docs.dataporten.no/) (thanks to https://github.com/xibriz) --- README.md | 1 + changelog | 1 + .../com/github/scribejava/apis/DataportenApi.java | 14 -------------- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index a8ed20a7f..9ce7bba1a 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ ScribeJava support out-of-box several HTTP clients: * AWeber (http://www.aweber.com/) * Box (https://www.box.com/) +* Dataporten (https://docs.dataporten.no/) * Digg (http://digg.com/) * Доктор на работе (https://www.doktornarabote.ru/) * Etsy (https://www.etsy.com/) diff --git a/changelog b/changelog index a05a60c6e..f26621947 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * drop optional dependency on Apache commons-codec + * add API - Dataporten (https://docs.dataporten.no/) (thanks to https://github.com/xibriz) [5.0.0] * drop Java 7 backward compatibility support, become Java 8 only diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DataportenApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DataportenApi.java index 99acbd4df..5e7ad9ceb 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DataportenApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DataportenApi.java @@ -1,10 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.Verb; public class DataportenApi extends DefaultApi20 { @@ -19,11 +15,6 @@ public static DataportenApi instance() { return InstanceHolder.INSTANCE; } - @Override - public Verb getAccessTokenVerb() { - return Verb.POST; - } - @Override public String getAccessTokenEndpoint() { return "https://auth.dataporten.no/oauth/token"; @@ -33,9 +24,4 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://auth.dataporten.no/oauth/authorization"; } - - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } } From edc8222b2d2b3ab89b090e6730359a5d9ffeef31 Mon Sep 17 00:00:00 2001 From: Kaushal Mall Date: Mon, 4 Dec 2017 15:08:31 -0700 Subject: [PATCH 032/481] New files for Azure Active Directory OAuth Api + updates to OAuthConstants class. --- .../apis/AzureActiveDirectoryApi.java | 85 +++++++++++++++++++ .../service/AzureActiveDirectoryService.java | 47 ++++++++++ .../apis/examples/MicrosoftAzureExample.java | 67 +++++++++++++++ .../scribejava/core/model/OAuthConstants.java | 7 +- 4 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java new file mode 100644 index 000000000..b14de7380 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java @@ -0,0 +1,85 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.service.AzureActiveDirectoryService; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.utils.OAuthEncoder; + +import java.util.Map; + +/** + * Microsoft Azure Active Directory Api + * + * Some helpful links + * https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-code + * https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-devquickstarts-webapp-java + * https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/signed-in-user-operations + * https://portal.azure.com + */ +public class AzureActiveDirectoryApi extends DefaultApi20 { + + private static final String MSFT_GRAPH_URL = "https://graph.windows.net"; + + private static final String AUTHORIZE_URL = "?client_id=%s&redirect_uri=%s&response_type=code&resource=" + + MSFT_GRAPH_URL; + private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; + + private static final String MSFT_LOGIN_URL = "https://login.microsoftonline.com"; + private static final String SLASH = "/"; + private static final String COMMON = "common"; + private static final String TOKEN_URI = "oauth2/token"; + private static final String AUTH_URI = "oauth2/authorize"; + + private static class InstanceHolder { + + private static final AzureActiveDirectoryApi INSTANCE = new AzureActiveDirectoryApi(); + } + + public static AzureActiveDirectoryApi instance() { + return AzureActiveDirectoryApi.InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + TOKEN_URI; + } + + @Override + protected String getAuthorizationBaseUrl() { + return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI; + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public AzureActiveDirectoryService createService(OAuthConfig config) { + return new AzureActiveDirectoryService(this, config); + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); + } + + @Override + public String getAuthorizationUrl(OAuthConfig config, Map additionalParams) { + + String scope = config.getScope(); + + if ( scope == null ) { + return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI + String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), + OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope())); + } else { + return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI + + String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); + } + } + +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java new file mode 100644 index 000000000..fad1da6d2 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java @@ -0,0 +1,47 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; + +public class AzureActiveDirectoryService extends OAuth20Service { + + private final DefaultApi20 api; + + public AzureActiveDirectoryService(DefaultApi20 api, OAuthConfig config) { + super(api, config); + this.api = api; + } + + @Override + public OAuthRequest createAccessTokenRequest(String code) { + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); + final OAuthConfig config = getConfig(); + + request.addHeader(OAuthConstants.CONTENT_TYPE, OAuthConstants.APPLICATION_X_WWW_FORM_URLENCODED); + + request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); + final String apiSecret = config.getApiSecret(); + if (apiSecret != null) { + request.addBodyParameter(OAuthConstants.CLIENT_SECRET, apiSecret); + } + request.addBodyParameter(OAuthConstants.CODE, code); + request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); + final String scope = config.getScope(); + if (scope != null) { + request.addBodyParameter(OAuthConstants.SCOPE, scope); + } + request.addBodyParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); + + return request; + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + request.addHeader(OAuthConstants.AUTHORIZATION, OAuthConstants.BEARER + accessToken); + request.addHeader(OAuthConstants.ACCEPT, + OAuthConstants.APPLICATION_JSON_ODATA_MINIMALMETADATA_STREAMING_TRUE_CHARSET_UTF_8); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java new file mode 100644 index 000000000..fc5d97eaf --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java @@ -0,0 +1,67 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.AzureActiveDirectoryApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.IOException; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + + + +public class MicrosoftAzureExample { + + private static final String NETWORK_NAME = "Microsoft Azure Active Directory"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.windows.net/me?api-version=1.6"; + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "client id here"; + final String clientSecret = "client secret here"; + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .scope( "openid" ) + .callback("http://www.example.com/oauth_callback/") + .build(AzureActiveDirectoryApi.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java index 4f79cd355..a86f467b5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java @@ -41,5 +41,10 @@ public interface OAuthConstants { //not OAuth specific String USER_AGENT_HEADER_NAME = "User-Agent"; - + String CONTENT_TYPE = "Content-Type"; + String APPLICATION_X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded"; + String AUTHORIZATION = "Authorization"; + String BEARER = "Bearer "; + String ACCEPT = "Accept"; + String APPLICATION_JSON_ODATA_MINIMALMETADATA_STREAMING_TRUE_CHARSET_UTF_8 = "application/json; odata=minimalmetadata; streaming=true; charset=utf-8"; } From 648e95d84bb39ff75907c1b2f2e74005cf275eca Mon Sep 17 00:00:00 2001 From: Kaushal Mall Date: Mon, 4 Dec 2017 16:10:42 -0700 Subject: [PATCH 033/481] updates for checkstyle failure. --- .../scribejava/apis/service/AzureActiveDirectoryService.java | 4 ++-- .../java/com/github/scribejava/core/model/OAuthConstants.java | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java index fad1da6d2..ccda746c7 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java @@ -9,6 +9,7 @@ public class AzureActiveDirectoryService extends OAuth20Service { private final DefaultApi20 api; + String ACCEPTED_FORMAT = "application/json; odata=minimalmetadata; streaming=true; charset=utf-8"; public AzureActiveDirectoryService(DefaultApi20 api, OAuthConfig config) { super(api, config); @@ -41,7 +42,6 @@ public OAuthRequest createAccessTokenRequest(String code) { @Override public void signRequest(String accessToken, OAuthRequest request) { request.addHeader(OAuthConstants.AUTHORIZATION, OAuthConstants.BEARER + accessToken); - request.addHeader(OAuthConstants.ACCEPT, - OAuthConstants.APPLICATION_JSON_ODATA_MINIMALMETADATA_STREAMING_TRUE_CHARSET_UTF_8); + request.addHeader(OAuthConstants.ACCEPT, ACCEPTED_FORMAT); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java index a86f467b5..1d130fdc8 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java @@ -46,5 +46,4 @@ public interface OAuthConstants { String AUTHORIZATION = "Authorization"; String BEARER = "Bearer "; String ACCEPT = "Accept"; - String APPLICATION_JSON_ODATA_MINIMALMETADATA_STREAMING_TRUE_CHARSET_UTF_8 = "application/json; odata=minimalmetadata; streaming=true; charset=utf-8"; } From 017086c642d3ceb9ca16b295fa9304fcf4841323 Mon Sep 17 00:00:00 2001 From: Kaushal Mall Date: Mon, 4 Dec 2017 16:37:44 -0700 Subject: [PATCH 034/481] more checkstyle changes --- .../github/scribejava/apis/AzureActiveDirectoryApi.java | 7 ++++--- .../apis/service/AzureActiveDirectoryService.java | 3 ++- .../scribejava/apis/examples/MicrosoftAzureExample.java | 6 +++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java index b14de7380..41fe05f0d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java @@ -71,10 +71,11 @@ public TokenExtractor getAccessTokenExtractor() { @Override public String getAuthorizationUrl(OAuthConfig config, Map additionalParams) { - String scope = config.getScope(); + final String scope = config.getScope(); - if ( scope == null ) { - return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI + String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), + if (scope == null) { + return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI + + String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope())); } else { return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java index ccda746c7..03e0d2ead 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java @@ -8,8 +8,9 @@ public class AzureActiveDirectoryService extends OAuth20Service { + private static final String ACCEPTED_FORMAT = "application/json; " + + "odata=minimalmetadata; streaming=true; charset=utf-8"; private final DefaultApi20 api; - String ACCEPTED_FORMAT = "application/json; odata=minimalmetadata; streaming=true; charset=utf-8"; public AzureActiveDirectoryService(DefaultApi20 api, OAuthConfig config) { super(api, config); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java index fc5d97eaf..9f82c9b81 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java @@ -19,13 +19,17 @@ public class MicrosoftAzureExample { private static final String NETWORK_NAME = "Microsoft Azure Active Directory"; private static final String PROTECTED_RESOURCE_URL = "https://graph.windows.net/me?api-version=1.6"; + private MicrosoftAzureExample(){ + + } + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "client id here"; final String clientSecret = "client secret here"; final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .scope( "openid" ) + .scope("openid") .callback("http://www.example.com/oauth_callback/") .build(AzureActiveDirectoryApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); From 6d339c85a8df034bb680a90d431eeffcae8afe3c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 6 Dec 2017 13:03:17 +0300 Subject: [PATCH 035/481] add API - Microsoft Azure Active Directory (Azure AD) (thanks to https://github.com/kaushalmall) --- README.md | 1 + changelog | 1 + .../apis/AzureActiveDirectoryApi.java | 86 ------------------- .../MicrosoftAzureActiveDirectoryApi.java | 58 +++++++++++++ .../service/AzureActiveDirectoryService.java | 48 ----------- .../MicrosoftAzureActiveDirectoryService.java | 22 +++++ ...MicrosoftAzureActiveDirectoryExample.java} | 10 +-- .../scribejava/core/model/OAuthConstants.java | 5 -- 8 files changed, 86 insertions(+), 145 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java rename scribejava-apis/src/test/java/com/github/scribejava/apis/examples/{MicrosoftAzureExample.java => MicrosoftAzureActiveDirectoryExample.java} (92%) diff --git a/README.md b/README.md index 9ce7bba1a..2e953db75 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ ScribeJava support out-of-box several HTTP clients: * Imgur (http://imgur.com/) * Kaixin 开心网 (http://www.kaixin001.com/) * LinkedIn (https://www.linkedin.com/) +* Microsoft Azure Active Directory (Azure AD) (http://azure.microsoft.com/) * Microsoft Live (https://login.live.com/) * Mail.Ru (https://mail.ru/) * Meetup (http://www.meetup.com/) diff --git a/changelog b/changelog index f26621947..fb5e1eaad 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * drop optional dependency on Apache commons-codec * add API - Dataporten (https://docs.dataporten.no/) (thanks to https://github.com/xibriz) + * add API - Microsoft Azure Active Directory (Azure AD) (thanks to https://github.com/kaushalmall) [5.0.0] * drop Java 7 backward compatibility support, become Java 8 only diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java deleted file mode 100644 index 41fe05f0d..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/AzureActiveDirectoryApi.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.apis.service.AzureActiveDirectoryService; -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.utils.OAuthEncoder; - -import java.util.Map; - -/** - * Microsoft Azure Active Directory Api - * - * Some helpful links - * https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-code - * https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-devquickstarts-webapp-java - * https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/signed-in-user-operations - * https://portal.azure.com - */ -public class AzureActiveDirectoryApi extends DefaultApi20 { - - private static final String MSFT_GRAPH_URL = "https://graph.windows.net"; - - private static final String AUTHORIZE_URL = "?client_id=%s&redirect_uri=%s&response_type=code&resource=" - + MSFT_GRAPH_URL; - private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s"; - - private static final String MSFT_LOGIN_URL = "https://login.microsoftonline.com"; - private static final String SLASH = "/"; - private static final String COMMON = "common"; - private static final String TOKEN_URI = "oauth2/token"; - private static final String AUTH_URI = "oauth2/authorize"; - - private static class InstanceHolder { - - private static final AzureActiveDirectoryApi INSTANCE = new AzureActiveDirectoryApi(); - } - - public static AzureActiveDirectoryApi instance() { - return AzureActiveDirectoryApi.InstanceHolder.INSTANCE; - } - - @Override - public String getAccessTokenEndpoint() { - return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + TOKEN_URI; - } - - @Override - protected String getAuthorizationBaseUrl() { - return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI; - } - - @Override - public Verb getAccessTokenVerb() { - return Verb.POST; - } - - @Override - public AzureActiveDirectoryService createService(OAuthConfig config) { - return new AzureActiveDirectoryService(this, config); - } - - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } - - @Override - public String getAuthorizationUrl(OAuthConfig config, Map additionalParams) { - - final String scope = config.getScope(); - - if (scope == null) { - return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI - + String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), - OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope())); - } else { - return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI - + String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); - } - } - -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java new file mode 100644 index 000000000..44ea915e5 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java @@ -0,0 +1,58 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.service.MicrosoftAzureActiveDirectoryService; +import com.github.scribejava.core.builder.api.ClientAuthenticationType; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; + +/** + * Microsoft Azure Active Directory Api + * + * @see + * Understand the OAuth 2.0 authorization code flow in Azure AD | Microsoft Docs + * @see + * Azure AD Java web app Getting Started | Microsoft Docs + * @see + * Azure AD Graph API Operations on the Signed-in User + * @see https://portal.azure.com + */ +public class MicrosoftAzureActiveDirectoryApi extends DefaultApi20 { + + private static final String MSFT_GRAPH_URL = "https://graph.windows.net"; + + private static final String MSFT_LOGIN_URL = "https://login.microsoftonline.com"; + private static final String SLASH = "/"; + private static final String COMMON = "common"; + private static final String TOKEN_URI = "oauth2/token"; + private static final String AUTH_URI = "oauth2/authorize?resource=" + MSFT_GRAPH_URL; + + private static class InstanceHolder { + + private static final MicrosoftAzureActiveDirectoryApi INSTANCE = new MicrosoftAzureActiveDirectoryApi(); + } + + public static MicrosoftAzureActiveDirectoryApi instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + TOKEN_URI; + } + + @Override + protected String getAuthorizationBaseUrl() { + return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI; + } + + @Override + public MicrosoftAzureActiveDirectoryService createService(OAuthConfig config) { + return new MicrosoftAzureActiveDirectoryService(this, config); + } + + @Override + public ClientAuthenticationType getClientAuthenticationType() { + return ClientAuthenticationType.REQUEST_BODY; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java deleted file mode 100644 index 03e0d2ead..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/AzureActiveDirectoryService.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; - -public class AzureActiveDirectoryService extends OAuth20Service { - - private static final String ACCEPTED_FORMAT = "application/json; " + - "odata=minimalmetadata; streaming=true; charset=utf-8"; - private final DefaultApi20 api; - - public AzureActiveDirectoryService(DefaultApi20 api, OAuthConfig config) { - super(api, config); - this.api = api; - } - - @Override - public OAuthRequest createAccessTokenRequest(String code) { - final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - final OAuthConfig config = getConfig(); - - request.addHeader(OAuthConstants.CONTENT_TYPE, OAuthConstants.APPLICATION_X_WWW_FORM_URLENCODED); - - request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - final String apiSecret = config.getApiSecret(); - if (apiSecret != null) { - request.addBodyParameter(OAuthConstants.CLIENT_SECRET, apiSecret); - } - request.addBodyParameter(OAuthConstants.CODE, code); - request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); - final String scope = config.getScope(); - if (scope != null) { - request.addBodyParameter(OAuthConstants.SCOPE, scope); - } - request.addBodyParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); - - return request; - } - - @Override - public void signRequest(String accessToken, OAuthRequest request) { - request.addHeader(OAuthConstants.AUTHORIZATION, OAuthConstants.BEARER + accessToken); - request.addHeader(OAuthConstants.ACCEPT, ACCEPTED_FORMAT); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java new file mode 100644 index 000000000..703257eac --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java @@ -0,0 +1,22 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; + +public class MicrosoftAzureActiveDirectoryService extends OAuth20Service { + + private static final String ACCEPTED_FORMAT + = "application/json; odata=minimalmetadata; streaming=true; charset=utf-8"; + + public MicrosoftAzureActiveDirectoryService(DefaultApi20 api, OAuthConfig config) { + super(api, config); + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + super.signRequest(accessToken, request); + request.addHeader("Accept", ACCEPTED_FORMAT); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java similarity index 92% rename from scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java rename to scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java index 9f82c9b81..86c2fc4a6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java @@ -1,6 +1,6 @@ package com.github.scribejava.apis.examples; -import com.github.scribejava.apis.AzureActiveDirectoryApi; +import com.github.scribejava.apis.MicrosoftAzureActiveDirectoryApi; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; @@ -12,14 +12,12 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; - - -public class MicrosoftAzureExample { +public class MicrosoftAzureActiveDirectoryExample { private static final String NETWORK_NAME = "Microsoft Azure Active Directory"; private static final String PROTECTED_RESOURCE_URL = "https://graph.windows.net/me?api-version=1.6"; - private MicrosoftAzureExample(){ + private MicrosoftAzureActiveDirectoryExample() { } @@ -31,7 +29,7 @@ public static void main(String... args) throws IOException, InterruptedException .apiSecret(clientSecret) .scope("openid") .callback("http://www.example.com/oauth_callback/") - .build(AzureActiveDirectoryApi.instance()); + .build(MicrosoftAzureActiveDirectoryApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java index 1d130fdc8..60bd33403 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java @@ -41,9 +41,4 @@ public interface OAuthConstants { //not OAuth specific String USER_AGENT_HEADER_NAME = "User-Agent"; - String CONTENT_TYPE = "Content-Type"; - String APPLICATION_X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded"; - String AUTHORIZATION = "Authorization"; - String BEARER = "Bearer "; - String ACCEPT = "Accept"; } From dd5b08858466ce112a4aedf388db188c3a9d9492 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 10 Jan 2018 13:08:56 +0300 Subject: [PATCH 036/481] fix LinkedInApi20 (thanks to https://github.com/jhorowitz-firedrum) --- changelog | 1 + .../main/java/com/github/scribejava/apis/LinkedInApi20.java | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/changelog b/changelog index fb5e1eaad..35cf8287b 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * drop optional dependency on Apache commons-codec * add API - Dataporten (https://docs.dataporten.no/) (thanks to https://github.com/xibriz) * add API - Microsoft Azure Active Directory (Azure AD) (thanks to https://github.com/kaushalmall) + * fix LinkedInApi20 (thanks to https://github.com/jhorowitz-firedrum) [5.0.0] * drop Java 7 backward compatibility support, become Java 8 only diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java index 0d22d705c..97f78b354 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java @@ -1,5 +1,6 @@ package com.github.scribejava.apis; +import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; public class LinkedInApi20 extends DefaultApi20 { @@ -24,4 +25,9 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://www.linkedin.com/oauth/v2/authorization"; } + + @Override + public ClientAuthenticationType getClientAuthenticationType() { + return ClientAuthenticationType.REQUEST_BODY; + } } From 001686af4b358a48ebda9f0ec51b2c63883f5505 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 10 Jan 2018 13:13:29 +0300 Subject: [PATCH 037/481] update some dependencies --- pom.xml | 28 +++------------------------- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- 3 files changed, 5 insertions(+), 27 deletions(-) diff --git a/pom.xml b/pom.xml index 5fda43fc8..aa216cd8a 100644 --- a/pom.xml +++ b/pom.xml @@ -53,28 +53,6 @@ +7-909-677-11-16 - - chernatkin - Sergey Chernatkin - s.chernatkin@hh.ru - hh.ru - http://hh.ru - - all - - +3 - - - igaranina - Irina Garanina - i.garanina@hh.ru - hh.ru - http://hh.ru - - all - - +3 -
@@ -103,7 +81,7 @@ org.apache.felix maven-bundle-plugin - 3.3.0 + 3.5.0 bundle-manifest @@ -132,7 +110,7 @@ com.puppycrawl.tools checkstyle - 8.4 + 8.7 @@ -193,7 +171,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.10.4 + 3.0.0 UTF-8 diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 5a35925a3..4b111458a 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.0.37 + 2.0.38 com.github.scribejava diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 95b48da1b..84d9b4143 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -23,7 +23,7 @@ org.apache.httpcomponents httpclient - 4.5.3 + 4.5.4 org.apache.httpcomponents From a629df3e840d40f1dc7ac8acb721ca275558eb4e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 10 Jan 2018 13:30:35 +0300 Subject: [PATCH 038/481] prepare 5.1.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2e953db75..c0a6ce197 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 5.0.0 + 5.1.0 ``` @@ -114,7 +114,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 5.0.0 + 5.1.0 ``` diff --git a/changelog b/changelog index 35cf8287b..f42671a6f 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[5.1.0] * drop optional dependency on Apache commons-codec * add API - Dataporten (https://docs.dataporten.no/) (thanks to https://github.com/xibriz) * add API - Microsoft Azure Active Directory (Azure AD) (thanks to https://github.com/kaushalmall) From 57617806d8ce09df9cd832b565e41ff62ab21266 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 10 Jan 2018 13:31:28 +0300 Subject: [PATCH 039/481] [maven-release-plugin] prepare release scribejava-5.1.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index aa216cd8a..abe672be6 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.0.1-SNAPSHOT + 5.1.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-5.1.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 9a7b21a63..6739ad368 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.1-SNAPSHOT + 5.1.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 3af1df7aa..07a7b191a 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.1-SNAPSHOT + 5.1.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 4b111458a..617664b76 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.1-SNAPSHOT + 5.1.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 84d9b4143..961d429d3 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.1-SNAPSHOT + 5.1.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index bb88941ae..1f1d3030c 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.1-SNAPSHOT + 5.1.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index c032e7667..ab1685a74 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.0.1-SNAPSHOT + 5.1.0 ../pom.xml From 5d7f6865660ca33bc3cfdaf3bccbb26700c0fc2d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 10 Jan 2018 13:31:38 +0300 Subject: [PATCH 040/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index abe672be6..cecfab589 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.1.0 + 5.1.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-5.1.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 6739ad368..441f75844 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.1.0 + 5.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 07a7b191a..325caa51e 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.1.0 + 5.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 617664b76..0294d6bfd 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.1.0 + 5.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 961d429d3..7d7d35147 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.1.0 + 5.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 1f1d3030c..7a247ffc6 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.1.0 + 5.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index ab1685a74..ab55c992f 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.1.0 + 5.1.1-SNAPSHOT ../pom.xml From 7b8aab5eaba99495518b69f36924e216fe1a037f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 15 Jan 2018 15:03:49 +0300 Subject: [PATCH 041/481] allow 'null' as callback. It's an optional parameter. Remove "oob" as default (thanks to https://github.com/massongit) --- changelog | 3 +++ .../com/github/scribejava/core/builder/ServiceBuilder.java | 4 +--- .../com/github/scribejava/core/model/OAuthConstants.java | 1 - .../github/scribejava/core/builder/ServiceBuilderTest.java | 7 +++---- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/changelog b/changelog index f42671a6f..e39f3eee5 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * allow 'null' as callback. It's an optional parameter. Remove "oob" as default (thanks to https://github.com/massongit) + [5.1.0] * drop optional dependency on Apache commons-codec * add API - Dataporten (https://docs.dataporten.no/) (thanks to https://github.com/xibriz) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index c003e7d18..d98e18ad7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -4,7 +4,6 @@ import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.core.utils.Preconditions; @@ -15,7 +14,7 @@ */ public class ServiceBuilder { - private String callback = OAuthConstants.OUT_OF_BAND; + private String callback; private String apiKey; private String apiSecret; private String scope; @@ -38,7 +37,6 @@ public ServiceBuilder(String apiKey) { * @return the {@link ServiceBuilder} instance for method chaining */ public ServiceBuilder callback(String callback) { - Preconditions.checkNotNull(callback, "Callback can't be null"); this.callback = callback; return this; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java index 60bd33403..93d936291 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java @@ -17,7 +17,6 @@ public interface OAuthConstants { String PARAM_PREFIX = "oauth_"; String TOKEN = "oauth_token"; String TOKEN_SECRET = "oauth_token_secret"; - String OUT_OF_BAND = "oob"; String VERIFIER = "oauth_verifier"; String HEADER = "Authorization"; String SCOPE = "scope"; diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java index c7d4a4dac..b2480af45 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java @@ -5,7 +5,6 @@ import org.junit.Test; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.oauth.OAuth20Service; public class ServiceBuilderTest { @@ -26,7 +25,7 @@ public void shouldReturnConfigDefaultValues() { final OAuthConfig config = api.getConfig(); assertEquals(config.getApiKey(), "key"); assertEquals(config.getApiSecret(), "secret"); - assertEquals(config.getCallback(), OAuthConstants.OUT_OF_BAND); + assertEquals(config.getCallback(), null); } @Test @@ -39,8 +38,8 @@ public void shouldAcceptValidCallbackUrl() { assertEquals(config.getCallback(), "http://example.com"); } - @Test(expected = IllegalArgumentException.class) - public void shouldNotAcceptNullAsCallback() { + @Test + public void shouldAcceptNullAsCallback() { builder.apiKey("key").apiSecret("secret").callback(null).build(api); } From bca97ef62c7a948eeb69be0c91dfa3e686f07eaa Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 24 Jan 2018 13:41:09 +0300 Subject: [PATCH 042/481] java7 compatible again! --- changelog | 1 + pom.xml | 7 +- .../apis/service/MailruOAuthService.java | 14 +- .../service/OdnoklassnikiOAuthService.java | 12 +- .../apis/examples/RenrenExample.java | 28 +- .../core/builder/ServiceBuilder.java | 4 +- .../builder/api/ClientAuthenticationType.java | 2 +- .../core/extractors/HeaderExtractorImpl.java | 24 +- .../core/httpclient/jdk/JDKHttpClient.java | 17 +- .../github/scribejava/core/java8/Base64.java | 977 ++++++++++++++++++ .../scribejava/core/java8/Consumer.java | 47 + .../scribejava/core/model/ParameterList.java | 15 +- .../core/oauth/OAuth10aService.java | 19 +- .../scribejava/core/oauth/OAuth20Service.java | 18 +- .../core/pkce/PKCECodeChallengeMethod.java | 2 +- .../scribejava/core/pkce/PKCEService.java | 2 +- .../core/services/SignatureService.java | 2 +- .../core/oauth/OAuth20ServiceTest.java | 2 +- .../core/oauth/OAuth20ServiceUnit.java | 5 +- .../httpclient/ahc/AhcHttpClient.java | 69 +- .../ahc/OAuthAsyncCompletionHandler.java | 4 +- .../httpclient/ahc/AhcHttpClientTest.java | 2 + .../httpclient/apache/ApacheHttpClient.java | 4 +- .../apache/OAuthAsyncCompletionHandler.java | 9 +- .../OauthAsyncCompletionHandlerTest.java | 31 +- .../httpclient/ning/NingHttpClient.java | 69 +- .../ning/OAuthAsyncCompletionHandler.java | 15 +- .../httpclient/okhttp/OkHttpHttpClient.java | 13 +- 28 files changed, 1311 insertions(+), 103 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/java8/Consumer.java diff --git a/changelog b/changelog index e39f3eee5..b62048c26 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * allow 'null' as callback. It's an optional parameter. Remove "oob" as default (thanks to https://github.com/massongit) + * java7 compatible again! [5.1.0] * drop optional dependency on Apache commons-codec diff --git a/pom.xml b/pom.xml index cecfab589..e752fc7cb 100644 --- a/pom.xml +++ b/pom.xml @@ -110,7 +110,7 @@ com.puppycrawl.tools checkstyle - 8.7 + 6.19 @@ -129,8 +129,8 @@ 3.7.0 UTF-8 - 1.8 - 1.8 + 1.7 + 1.7 true @@ -192,6 +192,7 @@ validate validate + main/java/com/github/scribejava/core/java8/* ${basedir}/src checkstyle.xml UTF-8 diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java index 625140ed9..f31503098 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java @@ -12,7 +12,6 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Formatter; -import java.util.stream.Collectors; public class MailruOAuthService extends OAuth20Service { @@ -37,10 +36,15 @@ public void signRequest(String accessToken, OAuthRequest request) { final String[] parts = param.split("="); map.put(parts[0], (parts.length == 1) ? "" : parts[1]); } - final String urlNew = map.entrySet().stream() - .map(entry -> entry.getKey() + '=' + entry.getValue()) - .collect(Collectors.joining()); - final String sigSource = URLDecoder.decode(urlNew, "UTF-8") + clientSecret; + + final StringBuilder urlNew = new StringBuilder(); + for (Map.Entry entry : map.entrySet()) { + urlNew.append(entry.getKey()); + urlNew.append('='); + urlNew.append(entry.getValue()); + } + + final String sigSource = URLDecoder.decode(urlNew.toString(), "UTF-8") + clientSecret; request.addQuerystringParameter("sig", md5(sigSource)); } } catch (UnsupportedEncodingException e) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java index 4b0ea020b..517d097ab 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java @@ -15,7 +15,6 @@ import java.util.Collections; import java.util.Formatter; import java.util.List; -import java.util.stream.Collectors; public class OdnoklassnikiOAuthService extends OAuth20Service { @@ -35,11 +34,14 @@ public void signRequest(String accessToken, OAuthRequest request) { Collections.sort(allParams); - final String stringParams = allParams.stream() - .map(param -> param.getKey() + '=' + param.getValue()) - .collect(Collectors.joining()); + final StringBuilder stringParams = new StringBuilder(); + for (Parameter param : allParams) { + stringParams.append(param.getKey()) + .append('=') + .append(param.getValue()); + } - final String sigSource = URLDecoder.decode(stringParams, "UTF-8") + tokenDigest; + final String sigSource = URLDecoder.decode(stringParams.toString(), "UTF-8") + tokenDigest; request.addQuerystringParameter("sig", md5(sigSource).toLowerCase()); super.signRequest(accessToken, request); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 31f043d6e..9f31e0af3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -15,10 +15,11 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; import java.util.Formatter; +import java.util.List; import java.util.concurrent.ExecutionException; -import java.util.stream.Collectors; -import java.util.stream.Stream; public final class RenrenExample { @@ -68,17 +69,20 @@ public static void main(String... args) throws IOException, InterruptedException parameters.put("format", "json"); parameters.put("v", "1.0"); - parameters.forEach((key, value) -> request.addQuerystringParameter(key, value)); - - final String sig = Stream.concat( - Stream.concat( - parameters.entrySet().stream() - .map(entry -> String.format("%s=%s", entry.getKey(), entry.getValue())), - Stream.of(String.format("%s=%s", OAuthConstants.ACCESS_TOKEN, accessToken.getAccessToken()))) - .sorted(), - Stream.of(apiSecret)) - .collect(Collectors.joining()); + final List sigString = new ArrayList<>(parameters.size() + 1); + for (Map.Entry parameter : parameters.entrySet()) { + request.addQuerystringParameter(parameter.getKey(), parameter.getValue()); + sigString.add(String.format("%s=%s", parameter.getKey(), parameter.getValue())); + } + sigString.add(String.format("%s=%s", OAuthConstants.ACCESS_TOKEN, accessToken.getAccessToken())); + Collections.sort(sigString); + final StringBuilder sigBuilder = new StringBuilder(); + for (String param : sigString) { + sigBuilder.append(param); + } + sigBuilder.append(apiSecret); + final String sig = sigBuilder.toString(); System.out.println("Sig string: " + sig); request.addQuerystringParameter("sig", md5(sig)); service.signRequest(accessToken, request); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index d98e18ad7..2ec6b1b22 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -129,11 +129,11 @@ public ServiceBuilder debug() { } /** - * Returns the fully configured {@link S} + * Returns the fully configured {@link OAuthService} * * @param OAuthService implementation (OAuth1/OAuth2/any API specific) * @param api will build Service for this API - * @return fully configured {@link S} + * @return fully configured {@link OAuthService} */ public S build(BaseApi api) { return api.createService(new OAuthConfig(apiKey, apiSecret, callback, scope, debugStream, state, responseType, diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java index 7e2526b0e..21c7f3793 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java @@ -1,10 +1,10 @@ package com.github.scribejava.core.builder.api; +import com.github.scribejava.core.java8.Base64; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import java.nio.charset.Charset; -import java.util.Base64; /** * Represents
diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java index a29ba9839..5ffe0c023 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/HeaderExtractorImpl.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; -import java.util.stream.Collectors; /** * Default implementation of {@link HeaderExtractor}. Conforms to OAuth 1.0a @@ -24,15 +23,26 @@ public String extract(OAuthRequest request) { checkPreconditions(request); final Map parameters = request.getOauthParameters(); - final String paramsString = parameters.entrySet().stream() - .map(entry -> String.format("%s=\"%s\"", entry.getKey(), OAuthEncoder.encode(entry.getValue()))) - .collect(Collectors.joining(PARAM_SEPARATOR, PREAMBLE, "")); + final StringBuilder header = new StringBuilder(PREAMBLE); - if (request.getRealm() == null || request.getRealm().isEmpty()) { - return paramsString; + for (Map.Entry parameter : parameters.entrySet()) { + if (header.length() > PREAMBLE.length()) { + header.append(PARAM_SEPARATOR); + } + header.append(parameter.getKey()) + .append("=\"") + .append(OAuthEncoder.encode(parameter.getValue())) + .append('"'); } - return paramsString + PARAM_SEPARATOR + String.format("%s=\"%s\"", OAuthConstants.REALM, request.getRealm()); + if (request.getRealm() != null && !request.getRealm().isEmpty()) { + header.append(PARAM_SEPARATOR) + .append(OAuthConstants.REALM) + .append("=\"") + .append(request.getRealm()) + .append('"'); + } + return header.toString(); } private void checkPreconditions(OAuthRequest request) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 5e173eb7e..6e970bb07 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -13,6 +13,7 @@ import java.net.URL; import java.net.UnknownHostException; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -140,18 +141,24 @@ abstract void setBody(HttpURLConnection connection, Object bodyContents, boolean private static Map parseHeaders(HttpURLConnection conn) { final Map headers = new HashMap<>(); - conn.getHeaderFields().forEach((key, value) -> { + + for (Map.Entry> headerField : conn.getHeaderFields().entrySet()) { + final String key = headerField.getKey(); + final String value = headerField.getValue().get(0); if ("Content-Encoding".equalsIgnoreCase(key)) { - headers.put("Content-Encoding", value.get(0)); + headers.put("Content-Encoding", value); } else { - headers.put(key, value.get(0)); + headers.put(key, value); } - }); + } return headers; } private static void addHeaders(HttpURLConnection connection, Map headers, String userAgent) { - headers.forEach((key, value) -> connection.setRequestProperty(key, value)); + for (Map.Entry header : headers.entrySet()) { + connection.setRequestProperty(header.getKey(), header.getValue()); + } + if (userAgent != null) { connection.setRequestProperty(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java new file mode 100644 index 000000000..7e599c6e5 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java @@ -0,0 +1,977 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.github.scribejava.core.java8; + +import java.io.FilterOutputStream; +import java.io.InputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.Objects; + +/** + * This class consists exclusively of static methods for obtaining encoders and decoders for the Base64 encoding scheme. + * The implementation of this class supports the following types of Base64 as specified in + * RFC 4648 and + * RFC 2045. + * + *
    + *
  • Basic + *

    + * Uses "The Base64 Alphabet" as specified in Table 1 of RFC 4648 and RFC 2045 for encoding and decoding operation. The + * encoder does not add any line feed (line separator) character. The decoder rejects data that contains characters + * outside the base64 alphabet.

  • + * + *
  • URL and Filename safe + *

    + * Uses the "URL and Filename safe Base64 Alphabet" as specified in Table 2 of RFC 4648 for encoding and decoding. The + * encoder does not add any line feed (line separator) character. The decoder rejects data that contains characters + * outside the base64 alphabet.

  • + * + *
  • MIME + *

    + * Uses the "The Base64 Alphabet" as specified in Table 1 of RFC 2045 for encoding and decoding operation. The encoded + * output must be represented in lines of no more than 76 characters each and uses a carriage return {@code '\r'} + * followed immediately by a linefeed {@code '\n'} as the line separator. No line separator is added to the end of the + * encoded output. All line separators or other characters not found in the base64 alphabet table are ignored in + * decoding operation.

  • + *
+ * + *

+ * Unless otherwise noted, passing a {@code null} argument to a method of this class will cause a {@link java.lang.NullPointerException + * NullPointerException} to be thrown. + * + * @author Xueming Shen + * @since 1.8 + */ +public class Base64 { + + private Base64() { + } + + /** + * Returns a {@link Encoder} that encodes using the + * Basic type base64 encoding scheme. + * + * @return A Base64 encoder. + */ + public static Encoder getEncoder() { + return Encoder.RFC4648; + } + + /** + * Returns a {@link Encoder} that encodes using the + * URL and Filename safe type base64 encoding scheme. + * + * @return A Base64 encoder. + */ + public static Encoder getUrlEncoder() { + return Encoder.RFC4648_URLSAFE; + } + + /** + * Returns a {@link Encoder} that encodes using the + * MIME type base64 encoding scheme. + * + * @return A Base64 encoder. + */ + public static Encoder getMimeEncoder() { + return Encoder.RFC2045; + } + + /** + * Returns a {@link Encoder} that encodes using the + * MIME type base64 encoding scheme with specified line length and line separators. + * + * @param lineLength the length of each output line (rounded down to nearest multiple of 4). If + * {@code lineLength <= 0} the output will not be separated in lines + * @param lineSeparator the line separator for each output line + * + * @return A Base64 encoder. + * + * @throws IllegalArgumentException if {@code lineSeparator} includes any character of "The Base64 Alphabet" as + * specified in Table 1 of RFC 2045. + */ + public static Encoder getMimeEncoder(int lineLength, byte[] lineSeparator) { + Objects.requireNonNull(lineSeparator); + int[] base64 = Decoder.FROM_BASE_64; + for (byte b : lineSeparator) { + if (base64[b & 0xff] != -1) { + throw new IllegalArgumentException( + "Illegal base64 line separator character 0x" + Integer.toString(b, 16)); + } + } + if (lineLength <= 0) { + return Encoder.RFC4648; + } + return new Encoder(false, lineSeparator, lineLength >> 2 << 2, true); + } + + /** + * Returns a {@link Decoder} that decodes using the + * Basic type base64 encoding scheme. + * + * @return A Base64 decoder. + */ + public static Decoder getDecoder() { + return Decoder.RFC4648; + } + + /** + * Returns a {@link Decoder} that decodes using the + * URL and Filename safe type base64 encoding scheme. + * + * @return A Base64 decoder. + */ + public static Decoder getUrlDecoder() { + return Decoder.RFC4648_URLSAFE; + } + + /** + * Returns a {@link Decoder} that decodes using the + * MIME type base64 decoding scheme. + * + * @return A Base64 decoder. + */ + public static Decoder getMimeDecoder() { + return Decoder.RFC2045; + } + + /** + * This class implements an encoder for encoding byte data using the Base64 encoding scheme as specified in RFC 4648 + * and RFC 2045. + * + *

+ * Instances of {@link Encoder} class are safe for use by multiple concurrent threads. + * + *

+ * Unless otherwise noted, passing a {@code null} argument to a method of this class will cause a + * {@link java.lang.NullPointerException NullPointerException} to be thrown. + * + * @see Decoder + * @since 1.8 + */ + public static class Encoder { + + private final byte[] newline; + private final int linemax; + private final boolean isURL; + private final boolean doPadding; + + /** + * This array is a lookup table that translates 6-bit positive integer index values into their "Base64 Alphabet" + * equivalents as specified in "Table 1: The Base64 Alphabet" of RFC 2045 (and RFC 4648). + */ + private static final char[] TO_BASE_64 = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' + }; + + /** + * It's the lookup table for "URL and Filename safe Base64" as specified in Table 2 of the RFC 4648, with the + * '+' and '/' changed to '-' and '_'. This table is used when BASE64_URL is specified. + */ + private static final char[] TO_BASE_64_URL = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_' + }; + + private static final int MIMELINEMAX = 76; + private static final byte[] CRLF = new byte[]{'\r', '\n'}; + + static final Encoder RFC4648 = new Encoder(false, null, -1, true); + static final Encoder RFC4648_URLSAFE = new Encoder(true, null, -1, true); + static final Encoder RFC2045 = new Encoder(false, CRLF, MIMELINEMAX, true); + + private Encoder(boolean isURL, byte[] newline, int linemax, boolean doPadding) { + this.isURL = isURL; + this.newline = newline; + this.linemax = linemax; + this.doPadding = doPadding; + } + + private int outLength(int srclen) { + int len; + if (doPadding) { + len = 4 * ((srclen + 2) / 3); + } else { + int n = srclen % 3; + len = 4 * (srclen / 3) + (n == 0 ? 0 : n + 1); + } + if (linemax > 0) // line separators + { + len += (len - 1) / linemax * newline.length; + } + return len; + } + + /** + * Encodes all bytes from the specified byte array into a newly-allocated byte array using the {@link Base64} + * encoding scheme. The returned byte array is of the length of the resulting bytes. + * + * @param src the byte array to encode + * @return A newly-allocated byte array containing the resulting encoded bytes. + */ + public byte[] encode(byte[] src) { + int len = outLength(src.length); // dst array size + byte[] dst = new byte[len]; + int ret = encode0(src, 0, src.length, dst); + if (ret != dst.length) { + return Arrays.copyOf(dst, ret); + } + return dst; + } + + /** + * Encodes all bytes from the specified byte array using the {@link Base64} encoding scheme, writing the + * resulting bytes to the given output byte array, starting at offset 0. + * + *

+ * It is the responsibility of the invoker of this method to make sure the output byte array {@code dst} has + * enough space for encoding all bytes from the input byte array. No bytes will be written to the output byte + * array if the output byte array is not big enough. + * + * @param src the byte array to encode + * @param dst the output byte array + * @return The number of bytes written to the output byte array + * + * @throws IllegalArgumentException if {@code dst} does not have enough space for encoding all input bytes. + */ + public int encode(byte[] src, byte[] dst) { + int len = outLength(src.length); // dst array size + if (dst.length < len) { + throw new IllegalArgumentException( + "Output byte array is too small for encoding all input bytes"); + } + return encode0(src, 0, src.length, dst); + } + + /** + * Encodes the specified byte array into a String using the {@link Base64} encoding scheme. + * + *

+ * This method first encodes all input bytes into a base64 encoded byte array and then constructs a new String + * by using the encoded byte array and the {@link java.nio.charset.StandardCharsets#ISO_8859_1 + * ISO-8859-1} charset. + * + *

+ * In other words, an invocation of this method has exactly the same effect as invoking + * {@code new String(encode(src), StandardCharsets.ISO_8859_1)}. + * + * @param src the byte array to encode + * @return A String containing the resulting Base64 encoded characters + */ + @SuppressWarnings("deprecation") + public String encodeToString(byte[] src) { + byte[] encoded = encode(src); + return new String(encoded, 0, 0, encoded.length); + } + + /** + * Encodes all remaining bytes from the specified byte buffer into a newly-allocated ByteBuffer using the + * {@link Base64} encoding scheme. + * + * Upon return, the source buffer's position will be updated to its limit; its limit will not have been changed. + * The returned output buffer's position will be zero and its limit will be the number of resulting encoded + * bytes. + * + * @param buffer the source ByteBuffer to encode + * @return A newly-allocated byte buffer containing the encoded bytes. + */ + public ByteBuffer encode(ByteBuffer buffer) { + int len = outLength(buffer.remaining()); + byte[] dst = new byte[len]; + int ret; + if (buffer.hasArray()) { + ret = encode0(buffer.array(), + buffer.arrayOffset() + buffer.position(), + buffer.arrayOffset() + buffer.limit(), + dst); + buffer.position(buffer.limit()); + } else { + byte[] src = new byte[buffer.remaining()]; + buffer.get(src); + ret = encode0(src, 0, src.length, dst); + } + if (ret != dst.length) { + dst = Arrays.copyOf(dst, ret); + } + return ByteBuffer.wrap(dst); + } + + /** + * Wraps an output stream for encoding byte data using the {@link Base64} encoding scheme. + * + *

+ * It is recommended to promptly close the returned output stream after use, during which it will flush all + * possible leftover bytes to the underlying output stream. Closing the returned output stream will close the + * underlying output stream. + * + * @param os the output stream. + * @return the output stream for encoding the byte data into the specified Base64 encoded format + */ + public OutputStream wrap(OutputStream os) { + Objects.requireNonNull(os); + return new EncOutputStream(os, isURL ? TO_BASE_64_URL : TO_BASE_64, + newline, linemax, doPadding); + } + + /** + * Returns an encoder instance that encodes equivalently to this one, but without adding any padding character + * at the end of the encoded byte data. + * + *

+ * The encoding scheme of this encoder instance is unaffected by this invocation. The returned encoder instance + * should be used for non-padding encoding operation. + * + * @return an equivalent encoder that encodes without adding any padding character at the end + */ + public Encoder withoutPadding() { + if (!doPadding) { + return this; + } + return new Encoder(isURL, newline, linemax, false); + } + + private int encode0(byte[] src, int off, int end, byte[] dst) { + char[] base64 = isURL ? TO_BASE_64_URL : TO_BASE_64; + int sp = off; + int slen = (end - off) / 3 * 3; + int sl = off + slen; + if (linemax > 0 && slen > linemax / 4 * 3) { + slen = linemax / 4 * 3; + } + int dp = 0; + while (sp < sl) { + int sl0 = Math.min(sp + slen, sl); + for (int sp0 = sp, dp0 = dp; sp0 < sl0;) { + int bits = (src[sp0++] & 0xff) << 16 + | (src[sp0++] & 0xff) << 8 + | (src[sp0++] & 0xff); + dst[dp0++] = (byte) base64[(bits >>> 18) & 0x3f]; + dst[dp0++] = (byte) base64[(bits >>> 12) & 0x3f]; + dst[dp0++] = (byte) base64[(bits >>> 6) & 0x3f]; + dst[dp0++] = (byte) base64[bits & 0x3f]; + } + int dlen = (sl0 - sp) / 3 * 4; + dp += dlen; + sp = sl0; + if (dlen == linemax && sp < end) { + for (byte b : newline) { + dst[dp++] = b; + } + } + } + if (sp < end) { // 1 or 2 leftover bytes + int b0 = src[sp++] & 0xff; + dst[dp++] = (byte) base64[b0 >> 2]; + if (sp == end) { + dst[dp++] = (byte) base64[(b0 << 4) & 0x3f]; + if (doPadding) { + dst[dp++] = '='; + dst[dp++] = '='; + } + } else { + int b1 = src[sp++] & 0xff; + dst[dp++] = (byte) base64[(b0 << 4) & 0x3f | (b1 >> 4)]; + dst[dp++] = (byte) base64[(b1 << 2) & 0x3f]; + if (doPadding) { + dst[dp++] = '='; + } + } + } + return dp; + } + } + + /** + * This class implements a decoder for decoding byte data using the Base64 encoding scheme as specified in RFC 4648 + * and RFC 2045. + * + *

+ * The Base64 padding character {@code '='} is accepted and interpreted as the end of the encoded byte data, but is + * not required. So if the final unit of the encoded byte data only has two or three Base64 characters (without the + * corresponding padding character(s) padded), they are decoded as if followed by padding character(s). If there is + * a padding character present in the final unit, the correct number of padding character(s) must be present, + * otherwise {@code IllegalArgumentException} ( {@code IOException} when reading from a Base64 stream) is thrown + * during decoding. + * + *

+ * Instances of {@link Decoder} class are safe for use by multiple concurrent threads. + * + *

+ * Unless otherwise noted, passing a {@code null} argument to a method of this class will cause a + * {@link java.lang.NullPointerException NullPointerException} to be thrown. + * + * @see Encoder + * @since 1.8 + */ + public static class Decoder { + + private final boolean isURL; + private final boolean isMIME; + + /** + * Lookup table for decoding unicode characters drawn from the "Base64 Alphabet" (as specified in Table 1 of RFC + * 2045) into their 6-bit positive integer equivalents. Characters that are not in the Base64 alphabet but fall + * within the bounds of the array are encoded to -1. + * + */ + private static final int[] FROM_BASE_64 = new int[256]; + static { + Arrays.fill(FROM_BASE_64, -1); + for (int i = 0; i < Encoder.TO_BASE_64.length; i++) { + FROM_BASE_64[Encoder.TO_BASE_64[i]] = i; + } + FROM_BASE_64['='] = -2; + } + + /** + * Lookup table for decoding "URL and Filename safe Base64 Alphabet" as specified in Table2 of the RFC 4648. + */ + private static final int[] FROM_BASE_64_URL = new int[256]; + static { + Arrays.fill(FROM_BASE_64_URL, -1); + for (int i = 0; i < Encoder.TO_BASE_64_URL.length; i++) { + FROM_BASE_64_URL[Encoder.TO_BASE_64_URL[i]] = i; + } + FROM_BASE_64_URL['='] = -2; + } + + static final Decoder RFC4648 = new Decoder(false, false); + static final Decoder RFC4648_URLSAFE = new Decoder(true, false); + static final Decoder RFC2045 = new Decoder(false, true); + + private Decoder(boolean isURL, boolean isMIME) { + this.isURL = isURL; + this.isMIME = isMIME; + } + + /** + * Decodes all bytes from the input byte array using the {@link Base64} encoding scheme, writing the results + * into a newly-allocated output byte array. The returned byte array is of the length of the resulting bytes. + * + * @param src the byte array to decode + * + * @return A newly-allocated byte array containing the decoded bytes. + * + * @throws IllegalArgumentException if {@code src} is not in valid Base64 scheme + */ + public byte[] decode(byte[] src) { + byte[] dst = new byte[outLength(src, 0, src.length)]; + int ret = decode0(src, 0, src.length, dst); + if (ret != dst.length) { + dst = Arrays.copyOf(dst, ret); + } + return dst; + } + + /** + * Decodes a Base64 encoded String into a newly-allocated byte array using the {@link Base64} encoding scheme. + * + *

+ * An invocation of this method has exactly the same effect as invoking + * {@code decode(src.getBytes(StandardCharsets.ISO_8859_1))} + * + * @param src the string to decode + * + * @return A newly-allocated byte array containing the decoded bytes. + * + * @throws IllegalArgumentException if {@code src} is not in valid Base64 scheme + */ + public byte[] decode(String src) { + return decode(src.getBytes(StandardCharsets.ISO_8859_1)); + } + + /** + * Decodes all bytes from the input byte array using the {@link Base64} encoding scheme, writing the results + * into the given output byte array, starting at offset 0. + * + *

+ * It is the responsibility of the invoker of this method to make sure the output byte array {@code dst} has + * enough space for decoding all bytes from the input byte array. No bytes will be be written to the output byte + * array if the output byte array is not big enough. + * + *

+ * If the input byte array is not in valid Base64 encoding scheme then some bytes may have been written to the + * output byte array before IllegalargumentException is thrown. + * + * @param src the byte array to decode + * @param dst the output byte array + * + * @return The number of bytes written to the output byte array + * + * @throws IllegalArgumentException if {@code src} is not in valid Base64 scheme, or {@code dst} does not have + * enough space for decoding all input bytes. + */ + public int decode(byte[] src, byte[] dst) { + int len = outLength(src, 0, src.length); + if (dst.length < len) { + throw new IllegalArgumentException( + "Output byte array is too small for decoding all input bytes"); + } + return decode0(src, 0, src.length, dst); + } + + /** + * Decodes all bytes from the input byte buffer using the {@link Base64} encoding scheme, writing the results + * into a newly-allocated ByteBuffer. + * + *

+ * Upon return, the source buffer's position will be updated to its limit; its limit will not have been changed. + * The returned output buffer's position will be zero and its limit will be the number of resulting decoded + * bytes + * + *

+ * {@code IllegalArgumentException} is thrown if the input buffer is not in valid Base64 encoding scheme. The + * position of the input buffer will not be advanced in this case. + * + * @param buffer the ByteBuffer to decode + * + * @return A newly-allocated byte buffer containing the decoded bytes + * + * @throws IllegalArgumentException if {@code src} is not in valid Base64 scheme. + */ + public ByteBuffer decode(ByteBuffer buffer) { + int pos0 = buffer.position(); + try { + byte[] src; + int sp, sl; + if (buffer.hasArray()) { + src = buffer.array(); + sp = buffer.arrayOffset() + buffer.position(); + sl = buffer.arrayOffset() + buffer.limit(); + buffer.position(buffer.limit()); + } else { + src = new byte[buffer.remaining()]; + buffer.get(src); + sp = 0; + sl = src.length; + } + byte[] dst = new byte[outLength(src, sp, sl)]; + return ByteBuffer.wrap(dst, 0, decode0(src, sp, sl, dst)); + } catch (IllegalArgumentException iae) { + buffer.position(pos0); + throw iae; + } + } + + /** + * Returns an input stream for decoding {@link Base64} encoded byte stream. + * + *

+ * The {@code read} methods of the returned {@code InputStream} will throw {@code IOException} when reading + * bytes that cannot be decoded. + * + *

+ * Closing the returned input stream will close the underlying input stream. + * + * @param is the input stream + * + * @return the input stream for decoding the specified Base64 encoded byte stream + */ + public InputStream wrap(InputStream is) { + Objects.requireNonNull(is); + return new DecInputStream(is, isURL ? FROM_BASE_64_URL : FROM_BASE_64, isMIME); + } + + private int outLength(byte[] src, int sp, int sl) { + int[] base64 = isURL ? FROM_BASE_64_URL : FROM_BASE_64; + int paddings = 0; + int len = sl - sp; + if (len == 0) { + return 0; + } + if (len < 2) { + if (isMIME && base64[0] == -1) { + return 0; + } + throw new IllegalArgumentException( + "Input byte[] should at least have 2 bytes for base64 bytes"); + } + if (isMIME) { + // scan all bytes to fill out all non-alphabet. a performance + // trade-off of pre-scan or Arrays.copyOf + int n = 0; + while (sp < sl) { + int b = src[sp++] & 0xff; + if (b == '=') { + len -= (sl - sp + 1); + break; + } + if ((b = base64[b]) == -1) { + n++; + } + } + len -= n; + } else { + if (src[sl - 1] == '=') { + paddings++; + if (src[sl - 2] == '=') { + paddings++; + } + } + } + if (paddings == 0 && (len & 0x3) != 0) { + paddings = 4 - (len & 0x3); + } + return 3 * ((len + 3) / 4) - paddings; + } + + private int decode0(byte[] src, int sp, int sl, byte[] dst) { + int[] base64 = isURL ? FROM_BASE_64_URL : FROM_BASE_64; + int dp = 0; + int bits = 0; + int shiftto = 18; // pos of first byte of 4-byte atom + while (sp < sl) { + int b = src[sp++] & 0xff; + if ((b = base64[b]) < 0) { + if (b == -2) { // padding byte '=' + // = shiftto==18 unnecessary padding + // x= shiftto==12 a dangling single x + // x to be handled together with non-padding case + // xx= shiftto==6&&sp==sl missing last = + // xx=y shiftto==6 last is not = + if (shiftto == 6 && (sp == sl || src[sp++] != '=') + || shiftto == 18) { + throw new IllegalArgumentException( + "Input byte array has wrong 4-byte ending unit"); + } + break; + } + if (isMIME) // skip if for rfc2045 + { + continue; + } else { + throw new IllegalArgumentException( + "Illegal base64 character " + + Integer.toString(src[sp - 1], 16)); + } + } + bits |= b << shiftto; + shiftto -= 6; + if (shiftto < 0) { + dst[dp++] = (byte) (bits >> 16); + dst[dp++] = (byte) (bits >> 8); + dst[dp++] = (byte) (bits); + shiftto = 18; + bits = 0; + } + } + // reached end of byte array or hit padding '=' characters. + if (shiftto == 6) { + dst[dp++] = (byte) (bits >> 16); + } else if (shiftto == 0) { + dst[dp++] = (byte) (bits >> 16); + dst[dp++] = (byte) (bits >> 8); + } else if (shiftto == 12) { + // dangling single "x", incorrectly encoded. + throw new IllegalArgumentException( + "Last unit does not have enough valid bits"); + } + // anything left is invalid, if is not MIME. + // if MIME, ignore all non-base64 character + while (sp < sl) { + if (isMIME && base64[src[sp++]] < 0) { + continue; + } + throw new IllegalArgumentException( + "Input byte array has incorrect ending byte at " + sp); + } + return dp; + } + } + + /* + * An output stream for encoding bytes into the Base64. + */ + private static class EncOutputStream extends FilterOutputStream { + + private int leftover; + private int b0, b1, b2; + private boolean closed; + + private final char[] base64; // byte->base64 mapping + private final byte[] newline; // line separator, if needed + private final int linemax; + private final boolean doPadding;// whether or not to pad + private int linepos; + + EncOutputStream(OutputStream os, char[] base64, + byte[] newline, int linemax, boolean doPadding) { + super(os); + this.base64 = base64; + this.newline = newline; + this.linemax = linemax; + this.doPadding = doPadding; + } + + @Override + public void write(int b) throws IOException { + byte[] buf = new byte[1]; + buf[0] = (byte) (b & 0xff); + write(buf, 0, 1); + } + + private void checkNewline() throws IOException { + if (linepos == linemax) { + out.write(newline); + linepos = 0; + } + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + if (closed) { + throw new IOException("Stream is closed"); + } + if (off < 0 || len < 0 || off + len > b.length) { + throw new ArrayIndexOutOfBoundsException(); + } + if (len == 0) { + return; + } + if (leftover != 0) { + if (leftover == 1) { + b1 = b[off++] & 0xff; + len--; + if (len == 0) { + leftover++; + return; + } + } + b2 = b[off++] & 0xff; + len--; + checkNewline(); + out.write(base64[b0 >> 2]); + out.write(base64[(b0 << 4) & 0x3f | (b1 >> 4)]); + out.write(base64[(b1 << 2) & 0x3f | (b2 >> 6)]); + out.write(base64[b2 & 0x3f]); + linepos += 4; + } + int nBits24 = len / 3; + leftover = len - (nBits24 * 3); + while (nBits24-- > 0) { + checkNewline(); + int bits = (b[off++] & 0xff) << 16 + | (b[off++] & 0xff) << 8 + | (b[off++] & 0xff); + out.write(base64[(bits >>> 18) & 0x3f]); + out.write(base64[(bits >>> 12) & 0x3f]); + out.write(base64[(bits >>> 6) & 0x3f]); + out.write(base64[bits & 0x3f]); + linepos += 4; + } + if (leftover == 1) { + b0 = b[off++] & 0xff; + } else if (leftover == 2) { + b0 = b[off++] & 0xff; + b1 = b[off++] & 0xff; + } + } + + @Override + public void close() throws IOException { + if (!closed) { + closed = true; + if (leftover == 1) { + checkNewline(); + out.write(base64[b0 >> 2]); + out.write(base64[(b0 << 4) & 0x3f]); + if (doPadding) { + out.write('='); + out.write('='); + } + } else if (leftover == 2) { + checkNewline(); + out.write(base64[b0 >> 2]); + out.write(base64[(b0 << 4) & 0x3f | (b1 >> 4)]); + out.write(base64[(b1 << 2) & 0x3f]); + if (doPadding) { + out.write('='); + } + } + leftover = 0; + out.close(); + } + } + } + + /* + * An input stream for decoding Base64 bytes + */ + private static class DecInputStream extends InputStream { + + private final InputStream is; + private final boolean isMIME; + private final int[] base64; // base64 -> byte mapping + private int bits; // 24-bit buffer for decoding + private int nextin = 18; // next available "off" in "bits" for input; + // -> 18, 12, 6, 0 + private int nextout = -8; // next available "off" in "bits" for output; + // -> 8, 0, -8 (no byte for output) + private boolean eof; + private boolean closed; + + private final byte[] sbBuf = new byte[1]; + + DecInputStream(InputStream is, int[] base64, boolean isMIME) { + this.is = is; + this.base64 = base64; + this.isMIME = isMIME; + } + + @Override + public int read() throws IOException { + return read(sbBuf, 0, 1) == -1 ? -1 : sbBuf[0] & 0xff; + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + if (closed) { + throw new IOException("Stream is closed"); + } + if (eof && nextout < 0) // eof and no leftover + { + return -1; + } + if (off < 0 || len < 0 || len > b.length - off) { + throw new IndexOutOfBoundsException(); + } + int oldOff = off; + if (nextout >= 0) { // leftover output byte(s) in bits buf + do { + if (len == 0) { + return off - oldOff; + } + b[off++] = (byte) (bits >> nextout); + len--; + nextout -= 8; + } while (nextout >= 0); + bits = 0; + } + while (len > 0) { + int v = is.read(); + if (v == -1) { + eof = true; + if (nextin != 18) { + if (nextin == 12) { + throw new IOException("Base64 stream has one un-decoded dangling byte."); + } + // treat ending xx/xxx without padding character legal. + // same logic as v == '=' below + b[off++] = (byte) (bits >> (16)); + len--; + if (nextin == 0) { // only one padding byte + if (len == 0) { // no enough output space + bits >>= 8; // shift to lowest byte + nextout = 0; + } else { + b[off++] = (byte) (bits >> 8); + } + } + } + if (off == oldOff) { + return -1; + } else { + return off - oldOff; + } + } + if (v == '=') { // padding byte(s) + // = shiftto==18 unnecessary padding + // x= shiftto==12 dangling x, invalid unit + // xx= shiftto==6 && missing last '=' + // xx=y or last is not '=' + if (nextin == 18 || nextin == 12 + || nextin == 6 && is.read() != '=') { + throw new IOException("Illegal base64 ending sequence:" + nextin); + } + b[off++] = (byte) (bits >> (16)); + len--; + if (nextin == 0) { // only one padding byte + if (len == 0) { // no enough output space + bits >>= 8; // shift to lowest byte + nextout = 0; + } else { + b[off++] = (byte) (bits >> 8); + } + } + eof = true; + break; + } + if ((v = base64[v]) == -1) { + if (isMIME) // skip if for rfc2045 + { + continue; + } else { + throw new IOException("Illegal base64 character " + + Integer.toString(v, 16)); + } + } + bits |= v << nextin; + if (nextin == 0) { + nextin = 18; // clear for next + nextout = 16; + while (nextout >= 0) { + b[off++] = (byte) (bits >> nextout); + len--; + nextout -= 8; + if (len == 0 && nextout >= 0) { // don't clean "bits" + return off - oldOff; + } + } + bits = 0; + } else { + nextin -= 6; + } + } + return off - oldOff; + } + + @Override + public int available() throws IOException { + if (closed) { + throw new IOException("Stream is closed"); + } + return is.available(); // TBD: + } + + @Override + public void close() throws IOException { + if (!closed) { + closed = true; + is.close(); + } + } + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Consumer.java b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Consumer.java new file mode 100644 index 000000000..83306b7be --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Consumer.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.github.scribejava.core.java8; + +/** + * Represents an operation that accepts a single input argument and returns no result. Unlike most other functional + * interfaces, {@code Consumer} is expected to operate via side-effects. + * + *

+ * This is a functional interface + * whose functional method is {@link #accept(Object)}. + * + * @param the type of the input to the operation + * + * @since 1.8 + */ +public interface Consumer { + + /** + * Performs this operation on the given argument. + * + * @param t the input argument + */ + void accept(T t); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java index 0282eaca7..39d806652 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java @@ -6,7 +6,6 @@ import java.util.Map; import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; -import java.util.stream.Collectors; public class ParameterList { @@ -28,9 +27,9 @@ public ParameterList() { public ParameterList(Map map) { this(); if (map != null && !map.isEmpty()) { - map.entrySet().stream() - .map(entry -> new Parameter(entry.getKey(), entry.getValue())) - .forEach(params::add); + for (Map.Entry entry : map.entrySet()) { + params.add(new Parameter(entry.getKey(), entry.getValue())); + } } } @@ -59,9 +58,11 @@ public String asFormUrlEncodedString() { return EMPTY_STRING; } - return params.stream() - .map(Parameter::asUrlEncodedPair) - .collect(Collectors.joining(PARAM_SEPARATOR)); + final StringBuilder builder = new StringBuilder(); + for (Parameter p : params) { + builder.append(PARAM_SEPARATOR).append(p.asUrlEncodedPair()); + } + return builder.substring(1); } public void addAll(ParameterList other) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index a006c70b2..9c62620ab 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -11,6 +11,7 @@ import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; +import java.util.Map; import java.util.concurrent.ExecutionException; /** @@ -55,7 +56,12 @@ public final Future getRequestTokenAsync( final OAuthConfig config = getConfig(); config.log("async obtaining request token from " + api.getRequestTokenEndpoint()); final OAuthRequest request = prepareRequestTokenRequest(); - return execute(request, callback, response -> getApi().getRequestTokenExtractor().extract(response)); + return execute(request, callback, new OAuthRequest.ResponseConverter() { + @Override + public OAuth1RequestToken convert(Response response) throws IOException { + return getApi().getRequestTokenExtractor().extract(response); + } + }); } protected OAuthRequest prepareRequestTokenRequest() { @@ -110,7 +116,12 @@ public final Future getAccessTokenAsync(OAuth1RequestToken re final OAuthConfig config = getConfig(); config.log("async obtaining access token from " + api.getAccessTokenEndpoint()); final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier); - return execute(request, callback, response -> getApi().getAccessTokenExtractor().extract(response)); + return execute(request, callback, new OAuthRequest.ResponseConverter() { + @Override + public OAuth1AccessToken convert(Response response) throws IOException { + return getApi().getAccessTokenExtractor().extract(response); + } + }); } protected OAuthRequest prepareAccessTokenRequest(OAuth1RequestToken requestToken, String oauthVerifier) { @@ -176,7 +187,9 @@ protected void appendSignature(OAuthRequest request) { case QueryString: config.log("using Querystring signature"); - request.getOauthParameters().forEach((key, value) -> request.addQuerystringParameter(key, value)); + for (Map.Entry oauthParameter : request.getOauthParameters().entrySet()) { + request.addQuerystringParameter(oauthParameter.getKey(), oauthParameter.getValue()); + } break; default: throw new IllegalStateException("Unknown new Signature Type '" + signatureType + "'."); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 9b9b22e41..ae7233798 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -52,7 +52,12 @@ protected Future sendAccessTokenRequestAsync(OAuthRequest req protected Future sendAccessTokenRequestAsync(OAuthRequest request, OAuthAsyncRequestCallback callback) { - return execute(request, callback, response -> getApi().getAccessTokenExtractor().extract(response)); + return execute(request, callback, new OAuthRequest.ResponseConverter() { + @Override + public OAuth2AccessToken convert(Response response) throws IOException { + return getApi().getAccessTokenExtractor().extract(response); + } + }); } public final Future getAccessTokenAsync(String code) { @@ -288,7 +293,7 @@ public String getAuthorizationUrl(Map additionalParams, PKCE pkc if (pkce == null) { params = additionalParams; } else { - params = additionalParams == null ? new HashMap<>() : new HashMap<>(additionalParams); + params = additionalParams == null ? new HashMap() : new HashMap<>(additionalParams); params.putAll(pkce.getAuthorizationUrlParams()); } return api.getAuthorizationUrl(getConfig(), params); @@ -337,9 +342,12 @@ public final Future revokeToken(String tokenToRevoke, OAuthAsyncRequestCal TokenTypeHint tokenTypeHint) { final OAuthRequest request = createRevokeTokenRequest(tokenToRevoke, tokenTypeHint); - return execute(request, callback, response -> { - checkForErrorRevokeToken(response); - return null; + return execute(request, callback, new OAuthRequest.ResponseConverter() { + @Override + public Void convert(Response response) throws IOException { + checkForErrorRevokeToken(response); + return null; + } }); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java index 69dbe17c6..29648859c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java @@ -1,9 +1,9 @@ package com.github.scribejava.core.pkce; +import com.github.scribejava.core.java8.Base64; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.util.Base64; public enum PKCECodeChallengeMethod { S256 { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java index 86cbb22af..2af370a75 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java @@ -1,8 +1,8 @@ package com.github.scribejava.core.pkce; +import com.github.scribejava.core.java8.Base64; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; -import java.util.Base64; /** * Used to implement Proof Key for Code Exchange by OAuth Public Clients https://tools.ietf.org/html/rfc7636 diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java index 0b180d49f..2248643c5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java @@ -1,6 +1,6 @@ package com.github.scribejava.core.services; -import java.util.Base64; +import com.github.scribejava.core.java8.Base64; /** * Signs a base string, returning the OAuth signature diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java index f62c49e86..b7a0febd0 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java @@ -1,6 +1,7 @@ package com.github.scribejava.core.oauth; import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.java8.Base64; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2Authorization; import com.github.scribejava.core.model.OAuthConstants; @@ -12,7 +13,6 @@ import org.junit.Test; import java.nio.charset.Charset; -import java.util.Base64; import java.util.Map; import java.util.concurrent.ExecutionException; diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index 76bd0e8c6..7a7db4555 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -6,6 +6,7 @@ import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Parameter; import com.google.gson.Gson; import java.util.HashMap; @@ -37,7 +38,9 @@ private String prepareRawResponse(OAuthRequest request) { response.putAll(request.getHeaders()); response.putAll(request.getOauthParameters()); - request.getBodyParams().getParams().forEach(p -> response.put("query-" + p.getKey(), p.getValue())); + for (Parameter param : request.getBodyParams().getParams()) { + response.put("query-" + param.getKey(), param.getValue()); + } return json.toJson(response); } diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java index ce705c372..623e5d49d 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java @@ -1,6 +1,7 @@ package com.github.scribejava.httpclient.ahc; import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; +import com.github.scribejava.core.java8.Consumer; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; @@ -13,7 +14,6 @@ import java.util.concurrent.Future; import java.io.File; -import java.util.function.Consumer; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.BoundRequestBuilder; @@ -41,23 +41,26 @@ public void close() throws IOException { @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - requestBuilder -> requestBuilder.setBody(bodyContents), callback, converter); + final byte[] bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new ByteArrayConsumer(bodyContents), callback, + converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - requestBuilder -> requestBuilder.setBody(bodyContents), callback, converter); + final String bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new StringConsumer(bodyContents), callback, + converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - requestBuilder -> requestBuilder.setBody(bodyContents), callback, converter); + final File bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new FileConsumer(bodyContents), callback, + converter); } private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, @@ -88,7 +91,9 @@ private Future doExecuteAsync(String userAgent, Map heade bodySetter.accept(boundRequestBuilder); } - headers.forEach((headerKey, headerValue) -> boundRequestBuilder.addHeader(headerKey, headerValue)); + for (Map.Entry header : headers.entrySet()) { + boundRequestBuilder.addHeader(header.getKey(), header.getValue()); + } if (userAgent != null) { boundRequestBuilder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); @@ -96,4 +101,46 @@ private Future doExecuteAsync(String userAgent, Map heade return boundRequestBuilder.execute(new OAuthAsyncCompletionHandler<>(callback, converter)); } + + private static class ByteArrayConsumer implements Consumer { + + private final byte[] bodyContents; + + private ByteArrayConsumer(byte[] bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public void accept(BoundRequestBuilder requestBuilder) { + requestBuilder.setBody(bodyContents); + } + } + + private static class StringConsumer implements Consumer { + + private final String bodyContents; + + private StringConsumer(String bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public void accept(BoundRequestBuilder requestBuilder) { + requestBuilder.setBody(bodyContents); + } + } + + private static class FileConsumer implements Consumer { + + private final File bodyContents; + + private FileConsumer(File bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public void accept(BoundRequestBuilder requestBuilder) { + requestBuilder.setBody(bodyContents); + } + } } diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java index 444f52226..100406fda 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java @@ -22,7 +22,9 @@ public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, @Override public T onCompleted(org.asynchttpclient.Response ahcResponse) throws IOException { final Map headersMap = new HashMap<>(); - ahcResponse.getHeaders().forEach(header -> headersMap.put(header.getKey(), header.getValue())); + for (Map.Entry header : ahcResponse.getHeaders()) { + headersMap.put(header.getKey(), header.getValue()); + } final Response response = new Response(ahcResponse.getStatusCode(), ahcResponse.getStatusText(), headersMap, ahcResponse.getResponseBodyAsStream()); diff --git a/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java b/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java index 5de2d153e..1ee1ebaa1 100644 --- a/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java +++ b/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java @@ -2,7 +2,9 @@ import com.github.scribejava.core.AbstractClientTest; import com.github.scribejava.core.httpclient.HttpClient; +import org.junit.Ignore; +@Ignore(value = "we are java7 and AHC is java8") public class AhcHttpClientTest extends AbstractClientTest { @Override diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java index e11eb3393..9075ff1ef 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java @@ -80,7 +80,9 @@ private Future doExecuteAsync(String userAgent, Map heade builder.setEntity(entity); } - headers.forEach((headerKey, headerValue) -> builder.addHeader(headerKey, headerValue)); + for (Map.Entry header : headers.entrySet()) { + builder.addHeader(header.getKey(), header.getValue()); + } if (userAgent != null) { builder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java index eeef72e75..02fc7616f 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java @@ -8,14 +8,13 @@ import org.apache.http.concurrent.FutureCallback; import java.io.IOException; -import java.util.Arrays; +import java.util.HashMap; import java.util.Map; import java.util.concurrent.CancellationException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import java.util.stream.Collectors; import org.apache.http.StatusLine; public class OAuthAsyncCompletionHandler implements FutureCallback { @@ -35,8 +34,10 @@ public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, Respon @Override public void completed(HttpResponse httpResponse) { try { - final Map headersMap = Arrays.stream(httpResponse.getAllHeaders()) - .collect(Collectors.toMap(Header::getName, Header::getValue)); + final Map headersMap = new HashMap<>(); + for (Header header : httpResponse.getAllHeaders()) { + headersMap.put(header.getName(), header.getValue()); + } final StatusLine statusLine = httpResponse.getStatusLine(); diff --git a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java index 89f3de1bc..3b0065c06 100644 --- a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java @@ -1,6 +1,8 @@ package com.github.scribejava.httpclient.apache; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; import org.apache.http.HttpResponse; import org.apache.http.ProtocolVersion; import org.apache.http.entity.BasicHttpEntity; @@ -22,6 +24,9 @@ public class OauthAsyncCompletionHandlerTest { + private static final AllGoodResponseConverter ALL_GOOD_RESPONSE_CONVERTER = new AllGoodResponseConverter(); + private static final ExceptionResponseConverter EXCEPTION_RESPONSE_CONVERTER = new ExceptionResponseConverter(); + private OAuthAsyncCompletionHandler handler; private TestCallback callback; @@ -57,7 +62,7 @@ public void setUp() { @Test public void shouldReleaseLatchOnSuccess() throws Exception { - handler = new OAuthAsyncCompletionHandler<>(callback, response -> "All good"); + handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER); final HttpResponse response = new BasicHttpResponse(new BasicStatusLine( new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); @@ -72,9 +77,7 @@ public void shouldReleaseLatchOnSuccess() throws Exception { @Test public void shouldReleaseLatchOnIOException() throws Exception { - handler = new OAuthAsyncCompletionHandler<>(callback, response -> { - throw new IOException("Failed to convert"); - }); + handler = new OAuthAsyncCompletionHandler<>(callback, EXCEPTION_RESPONSE_CONVERTER); final HttpResponse response = new BasicHttpResponse(new BasicStatusLine( new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); @@ -95,7 +98,7 @@ public void shouldReleaseLatchOnIOException() throws Exception { @Test public void shouldReleaseLatchOnCancel() throws Exception { - handler = new OAuthAsyncCompletionHandler<>(callback, response -> "All good"); + handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER); final HttpResponse response = new BasicHttpResponse(new BasicStatusLine( new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); @@ -116,7 +119,7 @@ public void shouldReleaseLatchOnCancel() throws Exception { @Test public void shouldReleaseLatchOnFailure() throws Exception { - handler = new OAuthAsyncCompletionHandler<>(callback, response -> "All good"); + handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER); final HttpResponse response = new BasicHttpResponse(new BasicStatusLine( new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); @@ -134,4 +137,20 @@ public void shouldReleaseLatchOnFailure() throws Exception { // expected } } + + private static class AllGoodResponseConverter implements OAuthRequest.ResponseConverter { + + @Override + public String convert(Response response) throws IOException { + return "All good"; + } + } + + private static class ExceptionResponseConverter implements OAuthRequest.ResponseConverter { + + @Override + public String convert(Response response) throws IOException { + throw new IOException("Failed to convert"); + } + } } diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java index 32398b5aa..90fc92fec 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java @@ -1,6 +1,7 @@ package com.github.scribejava.httpclient.ning; import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; +import com.github.scribejava.core.java8.Consumer; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; @@ -12,7 +13,6 @@ import com.ning.http.client.AsyncHttpClientConfig; import java.io.File; -import java.util.function.Consumer; public class NingHttpClient extends AbstractAsyncOnlyHttpClient { @@ -46,26 +46,29 @@ public void close() { @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + final byte[] bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - requestBuilder -> requestBuilder.setBody(bodyContents), callback, converter); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new ByteArrayConsumer(bodyContents), callback, + converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + final String bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - requestBuilder -> requestBuilder.setBody(bodyContents), callback, converter); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new StringConsumer(bodyContents), callback, + converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + final File bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - requestBuilder -> requestBuilder.setBody(bodyContents), callback, converter); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new FileConsumer(bodyContents), callback, + converter); } private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, @@ -96,7 +99,9 @@ private Future doExecuteAsync(String userAgent, Map heade bodySetter.accept(boundRequestBuilder); } - headers.forEach((headerKey, headerValue) -> boundRequestBuilder.addHeader(headerKey, headerValue)); + for (Map.Entry header : headers.entrySet()) { + boundRequestBuilder.addHeader(header.getKey(), header.getValue()); + } if (userAgent != null) { boundRequestBuilder.setHeader(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); @@ -104,4 +109,46 @@ private Future doExecuteAsync(String userAgent, Map heade return boundRequestBuilder.execute(new OAuthAsyncCompletionHandler<>(callback, converter)); } + + private static class ByteArrayConsumer implements Consumer { + + private final byte[] bodyContents; + + private ByteArrayConsumer(byte[] bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public void accept(AsyncHttpClient.BoundRequestBuilder requestBuilder) { + requestBuilder.setBody(bodyContents); + } + } + + private static class StringConsumer implements Consumer { + + private final String bodyContents; + + private StringConsumer(String bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public void accept(AsyncHttpClient.BoundRequestBuilder requestBuilder) { + requestBuilder.setBody(bodyContents); + } + } + + private static class FileConsumer implements Consumer { + + private final File bodyContents; + + private FileConsumer(File bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public void accept(AsyncHttpClient.BoundRequestBuilder requestBuilder) { + requestBuilder.setBody(bodyContents); + } + } } diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java index c60388ac0..c0aa14ecd 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java @@ -5,8 +5,9 @@ import com.github.scribejava.core.model.Response; import com.ning.http.client.AsyncCompletionHandler; import java.io.IOException; +import java.util.HashMap; +import java.util.List; import java.util.Map; -import java.util.stream.Collectors; public class OAuthAsyncCompletionHandler extends AsyncCompletionHandler { @@ -21,9 +22,15 @@ public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, @Override public T onCompleted(com.ning.http.client.Response ningResponse) throws IOException { - final Map headersMap = ningResponse.getHeaders().entrySet().stream() - .collect(Collectors.toMap(header -> header.getKey(), - header -> header.getValue().stream().collect(Collectors.joining()))); + final Map headersMap = new HashMap<>(); + + for (Map.Entry> header : ningResponse.getHeaders().entrySet()) { + final StringBuilder value = new StringBuilder(); + for (String str : header.getValue()) { + value.append(str); + } + headersMap.put(header.getKey(), value.toString()); + } final Response response = new Response(ningResponse.getStatusCode(), ningResponse.getStatusText(), headersMap, ningResponse.getResponseBodyAsStream()); diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index f4638d3ab..123c943ba 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -18,9 +18,8 @@ import com.github.scribejava.core.model.Response; import java.io.File; +import java.util.HashMap; import java.util.concurrent.ExecutionException; -import java.util.function.Function; -import java.util.stream.Collectors; import okhttp3.Cache; import okhttp3.Headers; import okhttp3.ResponseBody; @@ -130,7 +129,9 @@ private Call createCall(String userAgent, Map headers, Verb http requestBuilder.method(method, body); // fill headers - headers.forEach((key, value) -> requestBuilder.addHeader(key, value)); + for (Map.Entry header : headers.entrySet()) { + requestBuilder.addHeader(header.getKey(), header.getValue()); + } if (userAgent != null) { requestBuilder.header(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); @@ -165,8 +166,10 @@ RequestBody createBody(MediaType mediaType, Object bodyContents) { static Response convertResponse(okhttp3.Response okHttpResponse) { final Headers headers = okHttpResponse.headers(); - final Map headersMap = headers.names().stream() - .collect(Collectors.toMap(Function.identity(), headers::get)); + final Map headersMap = new HashMap<>(); + for (String headerName : headers.names()) { + headersMap.put(headerName, headers.get(headerName)); + } final ResponseBody body = okHttpResponse.body(); return new Response(okHttpResponse.code(), okHttpResponse.message(), headersMap, From f0f4603b08b6086ebf7d6d0a443617bb69d7b12a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 24 Jan 2018 13:49:44 +0300 Subject: [PATCH 043/481] update maven dependencies --- pom.xml | 6 ++++-- scribejava-httpclient-ahc/pom.xml | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index e752fc7cb..09da42ad3 100644 --- a/pom.xml +++ b/pom.xml @@ -105,7 +105,7 @@ org.apache.maven.plugins maven-checkstyle-plugin - 2.17 + 3.0.0 com.puppycrawl.tools @@ -193,7 +193,9 @@ validate main/java/com/github/scribejava/core/java8/* - ${basedir}/src + + ${basedir}/src + checkstyle.xml UTF-8 true diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 0294d6bfd..b4b02f4ad 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.0.38 + 2.1.2 com.github.scribejava From 213cc02632d76b7291ea1fb4839c6a0b7413a300 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 24 Jan 2018 14:04:59 +0300 Subject: [PATCH 044/481] force jdk7 to compile the project --- .travis.yml | 3 +-- README.md | 4 ++++ pom.xml | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 80a91cb59..1420112b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ dist: trusty language: java script: mvn clean package jdk: - - oraclejdk8 - - openjdk8 + - openjdk7 os: - linux diff --git a/README.md b/README.md index c0a6ce197..31fe12be4 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,10 @@ Working runnable examples are [here](https://github.com/scribejava/scribejava/tr Hit ScribeJava as hard and with many threads as you like. +### Java 7 compatible + +That's it. You can use it in old environments and in android apps. + ### Async and other HTTP clients ScribeJava support out-of-box several HTTP clients: diff --git a/pom.xml b/pom.xml index 09da42ad3..b0d497121 100644 --- a/pom.xml +++ b/pom.xml @@ -206,6 +206,26 @@ + + org.apache.maven.plugins + maven-enforcer-plugin + 1.4.1 + + + enforce-java + + enforce + + + + + (,1.8) + + + + + + From b1adbc121caeda26d89946e685bcca8490ac1de5 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 24 Jan 2018 14:23:41 +0300 Subject: [PATCH 045/481] prepare release 5.2.0-java7again --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 31fe12be4..7359b47da 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 5.1.0 + 5.2.0-java7again ``` @@ -118,7 +118,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 5.1.0 + 5.2.0-java7again ``` diff --git a/changelog b/changelog index b62048c26..7e2a30ff2 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[5.2.0-java7again] * allow 'null' as callback. It's an optional parameter. Remove "oob" as default (thanks to https://github.com/massongit) * java7 compatible again! From 3c9b41cdc7fa0231b1049b77f1f188901a160ae0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 24 Jan 2018 14:25:05 +0300 Subject: [PATCH 046/481] [maven-release-plugin] prepare release scribejava-5.2.0-java7again --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index b0d497121..8ba180af1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.1.1-SNAPSHOT + 5.2.0-java7again ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-5.2.0-java7again diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 441f75844..44cff6163 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.1.1-SNAPSHOT + 5.2.0-java7again ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 325caa51e..4380a738d 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.1.1-SNAPSHOT + 5.2.0-java7again ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index b4b02f4ad..261451f03 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.1.1-SNAPSHOT + 5.2.0-java7again ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 7d7d35147..2d19166b1 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.1.1-SNAPSHOT + 5.2.0-java7again ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 7a247ffc6..ec22d7c53 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.1.1-SNAPSHOT + 5.2.0-java7again ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index ab55c992f..0191f8704 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.1.1-SNAPSHOT + 5.2.0-java7again ../pom.xml From 5639536170de1e6be81b6fe506743d2c7e444ed4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 24 Jan 2018 14:25:28 +0300 Subject: [PATCH 047/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 8ba180af1..9fec9cbbb 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.2.0-java7again + 5.2.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-5.2.0-java7again + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 44cff6163..b2f8f67a5 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.2.0-java7again + 5.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 4380a738d..b4bccf1c3 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.2.0-java7again + 5.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 261451f03..c158ba42f 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.2.0-java7again + 5.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 2d19166b1..7fc9b7b62 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.2.0-java7again + 5.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index ec22d7c53..f688e597d 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.2.0-java7again + 5.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 0191f8704..6c7d94c39 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.2.0-java7again + 5.2.1-SNAPSHOT ../pom.xml From fb1fe95bf8c01d8ac0fd0827fe25a099fea213de Mon Sep 17 00:00:00 2001 From: Ethan Luis McDonough Date: Mon, 29 Jan 2018 02:31:27 -0600 Subject: [PATCH 048/481] I fixed a grammatical error --- .../com/github/scribejava/apis/examples/AWeberExample.java | 2 +- .../com/github/scribejava/apis/examples/Box20Example.java | 2 +- .../github/scribejava/apis/examples/DataportenExample.java | 2 +- .../java/com/github/scribejava/apis/examples/DiggExample.java | 2 +- .../java/com/github/scribejava/apis/examples/EtsyExample.java | 2 +- .../scribejava/apis/examples/FacebookAsyncApacheExample.java | 2 +- .../scribejava/apis/examples/FacebookAsyncNingExample.java | 2 +- .../com/github/scribejava/apis/examples/FacebookExample.java | 2 +- .../com/github/scribejava/apis/examples/FlickrExample.java | 2 +- .../github/scribejava/apis/examples/Foursquare2Example.java | 2 +- .../github/scribejava/apis/examples/FoursquareExample.java | 2 +- .../com/github/scribejava/apis/examples/FrappeExample.java | 2 +- .../github/scribejava/apis/examples/FreelancerExample.java | 4 ++-- .../scribejava/apis/examples/GitHubAsyncOkHttpExample.java | 2 +- .../com/github/scribejava/apis/examples/GitHubExample.java | 2 +- .../scribejava/apis/examples/Google20AsyncAHCExample.java | 4 ++-- .../com/github/scribejava/apis/examples/Google20Example.java | 4 ++-- .../scribejava/apis/examples/Google20RevokeExample.java | 2 +- .../scribejava/apis/examples/Google20WithPKCEExample.java | 4 ++-- .../java/com/github/scribejava/apis/examples/HHExample.java | 2 +- .../com/github/scribejava/apis/examples/ImgurExample.java | 2 +- .../com/github/scribejava/apis/examples/Kaixin20Example.java | 2 +- .../github/scribejava/apis/examples/LinkedIn20Example.java | 2 +- .../com/github/scribejava/apis/examples/LinkedInExample.java | 2 +- .../scribejava/apis/examples/LinkedInExampleWithScopes.java | 2 +- .../java/com/github/scribejava/apis/examples/LiveExample.java | 2 +- .../github/scribejava/apis/examples/MailruAsyncExample.java | 2 +- .../com/github/scribejava/apis/examples/MailruExample.java | 2 +- .../com/github/scribejava/apis/examples/MeetupExample.java | 2 +- .../apis/examples/MicrosoftAzureActiveDirectoryExample.java | 2 +- .../com/github/scribejava/apis/examples/MisfitExample.java | 2 +- .../com/github/scribejava/apis/examples/NaverExample.java | 2 +- .../github/scribejava/apis/examples/NeteaseWeiboExample.java | 2 +- .../github/scribejava/apis/examples/OdnoklassnikiExample.java | 4 ++-- .../com/github/scribejava/apis/examples/PinterestExample.java | 2 +- .../com/github/scribejava/apis/examples/Px500Example.java | 2 +- .../com/github/scribejava/apis/examples/RenrenExample.java | 2 +- .../github/scribejava/apis/examples/SalesforceExample.java | 2 +- .../scribejava/apis/examples/SalesforceNingAsyncExample.java | 2 +- .../github/scribejava/apis/examples/SinaWeibo2Example.java | 2 +- .../com/github/scribejava/apis/examples/SinaWeiboExample.java | 2 +- .../com/github/scribejava/apis/examples/SkyrockExample.java | 2 +- .../com/github/scribejava/apis/examples/SohuWeiboExample.java | 2 +- .../github/scribejava/apis/examples/StackExchangeExample.java | 2 +- .../apis/examples/TheThingsNetworkV1StagingExample.java | 2 +- .../apis/examples/TheThingsNetworkV2PreviewExample.java | 2 +- .../com/github/scribejava/apis/examples/TrelloExample.java | 2 +- .../com/github/scribejava/apis/examples/TumblrExample.java | 2 +- .../com/github/scribejava/apis/examples/TutByExample.java | 2 +- .../com/github/scribejava/apis/examples/TwitterExample.java | 2 +- .../java/com/github/scribejava/apis/examples/UcozExample.java | 2 +- .../com/github/scribejava/apis/examples/ViadeoExample.java | 2 +- .../com/github/scribejava/apis/examples/VkontakteExample.java | 2 +- .../apis/examples/VkontakteExternalHttpExample.java | 2 +- .../java/com/github/scribejava/apis/examples/XingExample.java | 2 +- .../com/github/scribejava/apis/examples/YahooExample.java | 2 +- 56 files changed, 61 insertions(+), 61 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index f79dfa4ef..ed7c20b96 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -50,7 +50,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index eaf26af17..062753217 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -69,7 +69,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java index 00b75c26d..f11b4e72c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java @@ -62,7 +62,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index 3985a7b83..a27dd895c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -53,7 +53,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java index a3bc12d40..21800310d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java @@ -47,7 +47,7 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java index 461576775..e5773f934 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java @@ -66,7 +66,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code).get(); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index 292d1b9f2..d5ea5438c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -74,7 +74,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code).get(); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index c0721835d..f7a156ddc 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -63,7 +63,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index 81d47b10c..25f858565 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -51,7 +51,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index 0dd9d1a31..ad78fe6ae 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -47,7 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index 9a30e6c10..2eaf4fcae 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -45,7 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java index 16fe60528..b23792184 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java @@ -49,7 +49,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index 696860bce..d8a9afa3f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -37,7 +37,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Fetching the Request Token..."); final OAuth1RequestToken requestToken = service.getRequestToken(); System.out.println("Got the Request Token!"); - System.out.println("(if your curious the raw answer looks like this: " + requestToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + requestToken.getRawResponse() + "')"); System.out.println(); System.out.println("Now go and authorize ScribeJava here:"); @@ -51,7 +51,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java index 06e81e5dd..57d618db5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java @@ -66,7 +66,7 @@ public static void main(String... args) throws IOException, ExecutionException, System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index 392a0c494..3227f8fc9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -62,7 +62,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index c5e9dc5d0..54bb06696 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -83,13 +83,13 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println("Trading the Request Token for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println("Refreshing the Access Token..."); accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); System.out.println("Refreshed the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 02c8ff680..0cce9f250 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -71,12 +71,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println("Refreshing the Access Token..."); accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); System.out.println("Refreshed the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java index 89d36be2c..f65b07c39 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java @@ -71,7 +71,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java index 5a5668147..eb4594e98 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java @@ -75,12 +75,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code, authUrlWithPKCE.getPkce().getCodeVerifier()); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println("Refreshing the Access Token..."); accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); System.out.println("Refreshed the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index d273974d6..9f2c4e560 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -49,7 +49,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); System.out.println("Now we're going to access a protected resource..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index 104b4cb61..fcce7ec81 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -47,7 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java index 43d5fe583..de1e491cd 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -47,7 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java index 69a65ebc7..9ff9fe0cd 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java @@ -49,7 +49,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index 4d1c998fe..7270b6a11 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -46,7 +46,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index f09d322d5..e94a687a0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -50,7 +50,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index b6231a744..1dc9c26df 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -47,7 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index 181ab1b82..9814bcfbe 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -60,7 +60,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index 8a02df6fd..01ff29cd9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -49,7 +49,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); System.out.println("Now we're going to access a protected resource..."); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index 50d3a894b..dc182ae05 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -45,7 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java index 86c2fc4a6..51efc5cf8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java @@ -50,7 +50,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java index 4c8cbddf1..057099500 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java @@ -50,7 +50,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java index 21ff0fa92..33e647f5c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java @@ -64,7 +64,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java index 63a7891c9..324b8709c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java @@ -53,7 +53,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index 4ecd3779c..ee7b46549 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -52,13 +52,13 @@ public static void main(String... args) throws IOException, InterruptedException OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); System.out.println("Refreshing the Access Token..."); accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); System.out.println("Refreshed the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index def416167..1100373cb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -48,7 +48,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index fbbad7874..35fba3e8d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -45,7 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 9f31e0af3..1f0ff3908 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -58,7 +58,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java index d9c9ff819..866718bea 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -76,7 +76,7 @@ public static void main(String... args) throws IOException, NoSuchAlgorithmExcep } System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); System.out.println("instance_url is: " + salesforceAccessToken.getInstanceUrl()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java index 9a55bd575..19e530de1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java @@ -77,7 +77,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx } System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); System.out.println("Instance is: " + salesforceAccessToken.getInstanceUrl()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java index e314a82d7..9233e1b32 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -47,7 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index 324e02201..e8622952c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -53,7 +53,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index 578ef88a3..07c010961 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -45,7 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java index 53d20aa9f..2ae6d3ffd 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java @@ -53,7 +53,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index e9af948d9..b9e699b5b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -67,7 +67,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java index 7264194a3..08279d535 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java @@ -69,7 +69,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java index 943a2529a..08c7eb888 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java @@ -66,7 +66,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index 309d4a9b3..62281a62f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -47,7 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index 1e6bdac15..f202a4540 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -47,7 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index ef3f1c924..5ce2d2e2c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -48,7 +48,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index 235c0c2e6..24af2acc8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -45,7 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java index 34a7a4b98..dcf6e1fd5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java @@ -40,7 +40,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index 9605b1c49..6e59af8db 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -47,7 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java index 9954116cc..b8f1fd2fc 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java @@ -48,7 +48,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java index 4a89fd4d4..1be173c64 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java @@ -65,7 +65,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index fce6c9aea..09ee75878 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -45,7 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index af3fa635a..b75b8a447 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -46,7 +46,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); - System.out.println("(if your curious the raw answer looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); // Now let's go and ask for a protected resource! From f77e05c27dde248c380bf7f1c5042bfa8650c2dc Mon Sep 17 00:00:00 2001 From: Eric Hochendoner Date: Sat, 10 Feb 2018 10:46:59 -0500 Subject: [PATCH 049/481] Convert Tumblr api request urls to https --- .../src/main/java/com/github/scribejava/apis/TumblrApi.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java index 1d7a9e93f..0d735ae27 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java @@ -6,8 +6,8 @@ public class TumblrApi extends DefaultApi10a { private static final String AUTHORIZE_URL = "https://www.tumblr.com/oauth/authorize?oauth_token=%s"; - private static final String REQUEST_TOKEN_RESOURCE = "http://www.tumblr.com/oauth/request_token"; - private static final String ACCESS_TOKEN_RESOURCE = "http://www.tumblr.com/oauth/access_token"; + private static final String REQUEST_TOKEN_RESOURCE = "https://www.tumblr.com/oauth/request_token"; + private static final String ACCESS_TOKEN_RESOURCE = "https://www.tumblr.com/oauth/access_token"; protected TumblrApi() { } From 881200ed29fe74770ad7047a7160e949471a15c5 Mon Sep 17 00:00:00 2001 From: Stephan Date: Sat, 17 Feb 2018 12:09:13 +1100 Subject: [PATCH 050/481] Sets client authentication type to 'request body' for Pinterest --- .../main/java/com/github/scribejava/apis/PinterestApi.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java index d93404b5e..d5bf603a9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java @@ -1,5 +1,6 @@ package com.github.scribejava.apis; +import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.builder.api.OAuth2SignatureType; @@ -30,4 +31,9 @@ protected String getAuthorizationBaseUrl() { public OAuth2SignatureType getSignatureType() { return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; } + + @Override + public ClientAuthenticationType getClientAuthenticationType() { + return ClientAuthenticationType.REQUEST_BODY; + } } From eafc4ae2a37ead224aaf86196524786932e321a1 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 26 Feb 2018 13:00:08 +0300 Subject: [PATCH 051/481] fix Salesforce API (thanks to https://github.com/jhorowitz-firedrum) --- changelog | 3 +++ .../com/github/scribejava/apis/SalesforceApi.java | 6 ++++++ .../scribejava/apis/examples/SalesforceExample.java | 1 + .../extractors/OAuth2AccessTokenJsonExtractor.java | 11 +++++++++-- .../core/model/OAuth2AccessTokenErrorResponse.java | 3 --- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/changelog b/changelog index 7e2a30ff2..09f2c4c39 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * fix Salesforce API (thanks to https://github.com/jhorowitz-firedrum) + [5.2.0-java7again] * allow 'null' as callback. It's an optional parameter. Remove "oob" as default (thanks to https://github.com/massongit) * java7 compatible again! diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java index 95e5e2816..0b1c3c11f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java @@ -3,6 +3,7 @@ import javax.net.ssl.SSLContext; import com.github.scribejava.apis.salesforce.SalesforceJsonTokenExtractor; +import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; @@ -129,4 +130,9 @@ public static void initTLSv11orUpper() throws NoSuchAlgorithmException, KeyManag context.init(null, null, null); SSLContext.setDefault(context); } + + @Override + public ClientAuthenticationType getClientAuthenticationType() { + return ClientAuthenticationType.REQUEST_BODY; + } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java index 866718bea..39cbbc2fe 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -94,6 +94,7 @@ public static void main(String... args) throws IOException, NoSuchAlgorithmExcep System.out.println("Full URL: " + url); final OAuthRequest request = new OAuthRequest(Verb.GET, url); + service.signRequest(salesforceAccessToken, request); final Response response = service.execute(request); System.out.println(); System.out.println(response.getCode()); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index 49c6ec7d8..892b322be 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -64,8 +64,15 @@ public void generateError(String response) { errorUri = null; } - throw new OAuth2AccessTokenErrorResponse(OAuth2AccessTokenErrorResponse.ErrorCode.valueOf(errorInString), - errorDescription, errorUri, response); + OAuth2AccessTokenErrorResponse.ErrorCode errorCode; + try { + errorCode = OAuth2AccessTokenErrorResponse.ErrorCode.valueOf(errorInString); + } catch (IllegalArgumentException iaE) { + //non oauth standard error code + errorCode = null; + } + + throw new OAuth2AccessTokenErrorResponse(errorCode, errorDescription, errorUri, response); } private OAuth2AccessToken createToken(String response) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java index 6476799e0..86ca38d88 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java @@ -27,9 +27,6 @@ public enum ErrorCode { public OAuth2AccessTokenErrorResponse(ErrorCode errorCode, String errorDescription, URI errorUri, String rawResponse) { super(rawResponse); - if (errorCode == null) { - throw new IllegalArgumentException("errorCode must not be null"); - } this.errorCode = errorCode; this.errorDescription = errorDescription; this.errorUri = errorUri; From 4a361d55bffb9d2b4d69034e38b198f16bf30820 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 26 Feb 2018 13:12:47 +0300 Subject: [PATCH 052/481] remove 'final' from methods in OAuth[10a|20]Service to allow mocking it --- changelog | 1 + .../core/oauth/OAuth10aService.java | 13 ++--- .../scribejava/core/oauth/OAuth20Service.java | 57 +++++++++---------- 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/changelog b/changelog index 09f2c4c39..5a3620da3 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * fix Salesforce API (thanks to https://github.com/jhorowitz-firedrum) + * remove 'final' from methods in OAuth[10a|20]Service to allow mocking it [5.2.0-java7again] * allow 'null' as callback. It's an optional parameter. Remove "oob" as default (thanks to https://github.com/massongit) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index 9c62620ab..09b744b2d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -33,7 +33,7 @@ public OAuth10aService(DefaultApi10a api, OAuthConfig config) { this.api = api; } - public final OAuth1RequestToken getRequestToken() throws IOException, InterruptedException, ExecutionException { + public OAuth1RequestToken getRequestToken() throws IOException, InterruptedException, ExecutionException { final OAuthConfig config = getConfig(); config.log("obtaining request token from " + api.getRequestTokenEndpoint()); final OAuthRequest request = prepareRequestTokenRequest(); @@ -47,12 +47,11 @@ public final OAuth1RequestToken getRequestToken() throws IOException, Interrupte return api.getRequestTokenExtractor().extract(response); } - public final Future getRequestTokenAsync() { + public Future getRequestTokenAsync() { return getRequestTokenAsync(null); } - public final Future getRequestTokenAsync( - OAuthAsyncRequestCallback callback) { + public Future getRequestTokenAsync(OAuthAsyncRequestCallback callback) { final OAuthConfig config = getConfig(); config.log("async obtaining request token from " + api.getRequestTokenEndpoint()); final OAuthRequest request = prepareRequestTokenRequest(); @@ -90,7 +89,7 @@ protected void addOAuthParams(OAuthRequest request, String tokenSecret) { config.log("appended additional OAuth parameters: " + request.getOauthParameters()); } - public final OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, String oauthVerifier) + public OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, String oauthVerifier) throws IOException, InterruptedException, ExecutionException { getConfig().log("obtaining access token from " + api.getAccessTokenEndpoint()); final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier); @@ -98,7 +97,7 @@ public final OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, S return api.getAccessTokenExtractor().extract(response); } - public final Future getAccessTokenAsync(OAuth1RequestToken requestToken, String oauthVerifier) { + public Future getAccessTokenAsync(OAuth1RequestToken requestToken, String oauthVerifier) { return getAccessTokenAsync(requestToken, oauthVerifier, null); } @@ -111,7 +110,7 @@ public final Future getAccessTokenAsync(OAuth1RequestToken re * @param callback optional callback * @return Future */ - public final Future getAccessTokenAsync(OAuth1RequestToken requestToken, String oauthVerifier, + public Future getAccessTokenAsync(OAuth1RequestToken requestToken, String oauthVerifier, OAuthAsyncRequestCallback callback) { final OAuthConfig config = getConfig(); config.log("async obtaining access token from " + api.getAccessTokenEndpoint()); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index ae7233798..0aed00b0b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -60,20 +60,19 @@ public OAuth2AccessToken convert(Response response) throws IOException { }); } - public final Future getAccessTokenAsync(String code) { + public Future getAccessTokenAsync(String code) { return getAccessToken(code, null, null); } - public final Future getAccessTokenAsync(String code, String pkceCodeVerifier) { + public Future getAccessTokenAsync(String code, String pkceCodeVerifier) { return getAccessToken(code, null, pkceCodeVerifier); } - public final OAuth2AccessToken getAccessToken(String code) - throws IOException, InterruptedException, ExecutionException { + public OAuth2AccessToken getAccessToken(String code) throws IOException, InterruptedException, ExecutionException { return getAccessToken(code, (String) null); } - public final OAuth2AccessToken getAccessToken(String code, String pkceCodeVerifier) + public OAuth2AccessToken getAccessToken(String code, String pkceCodeVerifier) throws IOException, InterruptedException, ExecutionException { final OAuthRequest request = createAccessTokenRequest(code, pkceCodeVerifier); @@ -89,14 +88,14 @@ public final OAuth2AccessToken getAccessToken(String code, String pkceCodeVerifi * @param pkceCodeVerifier pkce Code Verifier * @return Future */ - public final Future getAccessToken(String code, - OAuthAsyncRequestCallback callback, String pkceCodeVerifier) { + public Future getAccessToken(String code, OAuthAsyncRequestCallback callback, + String pkceCodeVerifier) { final OAuthRequest request = createAccessTokenRequest(code, pkceCodeVerifier); return sendAccessTokenRequestAsync(request, callback); } - public final Future getAccessToken(String code, + public Future getAccessToken(String code, OAuthAsyncRequestCallback callback) { return getAccessToken(code, callback, null); @@ -126,18 +125,18 @@ protected OAuthRequest createAccessTokenRequest(String code, String pkceCodeVeri return request; } - public final Future refreshAccessTokenAsync(String refreshToken) { + public Future refreshAccessTokenAsync(String refreshToken) { return refreshAccessToken(refreshToken, null); } - public final OAuth2AccessToken refreshAccessToken(String refreshToken) + public OAuth2AccessToken refreshAccessToken(String refreshToken) throws IOException, InterruptedException, ExecutionException { final OAuthRequest request = createRefreshTokenRequest(refreshToken); return sendAccessTokenRequestSync(request); } - public final Future refreshAccessToken(String refreshToken, + public Future refreshAccessToken(String refreshToken, OAuthAsyncRequestCallback callback) { final OAuthRequest request = createRefreshTokenRequest(refreshToken); @@ -157,14 +156,14 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken) { return request; } - public final OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String password) + public OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String password) throws IOException, InterruptedException, ExecutionException { final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password); return sendAccessTokenRequestSync(request); } - public final Future getAccessTokenPasswordGrantAsync(String uname, String password) { + public Future getAccessTokenPasswordGrantAsync(String uname, String password) { return getAccessTokenPasswordGrantAsync(uname, password, null); } @@ -176,7 +175,7 @@ public final Future getAccessTokenPasswordGrantAsync(String u * @param callback Optional callback * @return Future */ - public final Future getAccessTokenPasswordGrantAsync(String uname, String password, + public Future getAccessTokenPasswordGrantAsync(String uname, String password, OAuthAsyncRequestCallback callback) { final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password); @@ -201,11 +200,11 @@ protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, St return request; } - public final Future getAccessTokenClientCredentialsGrantAsync() { + public Future getAccessTokenClientCredentialsGrantAsync() { return getAccessTokenClientCredentialsGrant(null); } - public final OAuth2AccessToken getAccessTokenClientCredentialsGrant() + public OAuth2AccessToken getAccessTokenClientCredentialsGrant() throws IOException, InterruptedException, ExecutionException { final OAuthRequest request = createAccessTokenClientCredentialsGrantRequest(); @@ -219,7 +218,7 @@ public final OAuth2AccessToken getAccessTokenClientCredentialsGrant() * @param callback optional callback * @return Future */ - public final Future getAccessTokenClientCredentialsGrant( + public Future getAccessTokenClientCredentialsGrant( OAuthAsyncRequestCallback callback) { final OAuthRequest request = createAccessTokenClientCredentialsGrantRequest(); @@ -252,15 +251,15 @@ public void signRequest(String accessToken, OAuthRequest request) { api.getSignatureType().signRequest(accessToken, request); } - public final void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { + public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { signRequest(accessToken == null ? null : accessToken.getAccessToken(), request); } - public final AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE() { + public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE() { return getAuthorizationUrlWithPKCE(null); } - public final AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(Map additionalParams) { + public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(Map additionalParams) { final PKCE pkce = PKCE_SERVICE.generatePKCE(); return new AuthorizationUrlWithPKCE(pkce, getAuthorizationUrl(additionalParams, pkce)); } @@ -270,7 +269,7 @@ public final AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(Map additionalParams) { + public String getAuthorizationUrl(Map additionalParams) { return getAuthorizationUrl(additionalParams, null); } - public final String getAuthorizationUrl(PKCE pkce) { + public String getAuthorizationUrl(PKCE pkce) { return getAuthorizationUrl(null, pkce); } @@ -315,30 +314,30 @@ protected OAuthRequest createRevokeTokenRequest(String tokenToRevoke, TokenTypeH return request; } - public final Future revokeTokenAsync(String tokenToRevoke) { + public Future revokeTokenAsync(String tokenToRevoke) { return revokeTokenAsync(tokenToRevoke, null); } - public final Future revokeTokenAsync(String tokenToRevoke, TokenTypeHint tokenTypeHint) { + public Future revokeTokenAsync(String tokenToRevoke, TokenTypeHint tokenTypeHint) { return revokeToken(tokenToRevoke, null, tokenTypeHint); } - public final void revokeToken(String tokenToRevoke) throws IOException, InterruptedException, ExecutionException { + public void revokeToken(String tokenToRevoke) throws IOException, InterruptedException, ExecutionException { revokeToken(tokenToRevoke, (TokenTypeHint) null); } - public final void revokeToken(String tokenToRevoke, TokenTypeHint tokenTypeHint) + public void revokeToken(String tokenToRevoke, TokenTypeHint tokenTypeHint) throws IOException, InterruptedException, ExecutionException { final OAuthRequest request = createRevokeTokenRequest(tokenToRevoke, tokenTypeHint); checkForErrorRevokeToken(execute(request)); } - public final Future revokeToken(String tokenToRevoke, OAuthAsyncRequestCallback callback) { + public Future revokeToken(String tokenToRevoke, OAuthAsyncRequestCallback callback) { return revokeToken(tokenToRevoke, callback, null); } - public final Future revokeToken(String tokenToRevoke, OAuthAsyncRequestCallback callback, + public Future revokeToken(String tokenToRevoke, OAuthAsyncRequestCallback callback, TokenTypeHint tokenTypeHint) { final OAuthRequest request = createRevokeTokenRequest(tokenToRevoke, tokenTypeHint); From 6f0d0abc1f2d0112909ff57329a18df10ab2bb86 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 5 Mar 2018 13:53:03 +0300 Subject: [PATCH 053/481] fix Pinterest API (thanks to https://github.com/sschwieb) --- changelog | 1 + .../main/java/com/github/scribejava/apis/PinterestApi.java | 6 ------ .../github/scribejava/apis/examples/PinterestExample.java | 6 +++--- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/changelog b/changelog index 5a3620da3..c3a70d1b4 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * fix Salesforce API (thanks to https://github.com/jhorowitz-firedrum) * remove 'final' from methods in OAuth[10a|20]Service to allow mocking it + * fix Pinterest API (thanks to https://github.com/sschwieb) [5.2.0-java7again] * allow 'null' as callback. It's an optional parameter. Remove "oob" as default (thanks to https://github.com/massongit) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java index d5bf603a9..f915aa605 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java @@ -2,7 +2,6 @@ import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; public class PinterestApi extends DefaultApi20 { @@ -27,11 +26,6 @@ protected String getAuthorizationBaseUrl() { return "https://api.pinterest.com/oauth"; } - @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; - } - @Override public ClientAuthenticationType getClientAuthenticationType() { return ClientAuthenticationType.REQUEST_BODY; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index 1100373cb..6d25b80a2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -14,7 +14,7 @@ public final class PinterestExample { - private static final String PROTECTED_RESOURCE_URL = "https://api.pinterest.com/v1/me/?access_token?access_token="; + private static final String PROTECTED_RESOURCE_URL = "https://api.pinterest.com/v1/me/"; private PinterestExample() { } @@ -26,7 +26,7 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .scope("read_public,write_public,read_relationships,write_relationships") - .callback("https://localhost:9000/") // Add as valid callback in developer portal + .callback("https://localhost/") // Add as valid callback in developer portal .build(PinterestApi.instance()); final Scanner in = new Scanner(System.in); @@ -53,7 +53,7 @@ public static void main(String... args) throws IOException, InterruptedException // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getAccessToken()); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); From cc4b6f00a5259bf32e6b45943c999182a3cdb43a Mon Sep 17 00:00:00 2001 From: Bill Tarr Date: Mon, 19 Feb 2018 17:13:17 -0800 Subject: [PATCH 054/481] Add OAuth2.0 for Yahoo APIs with example. --- .../github/scribejava/apis/YahooApi20.java | 36 +++++++++ .../apis/examples/Yahoo20Example.java | 77 +++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi20.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi20.java new file mode 100644 index 000000000..11c2f3745 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi20.java @@ -0,0 +1,36 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.openid.OpenIdJsonTokenExtractor; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; + +public class YahooApi20 extends DefaultApi20 { + + protected YahooApi20() { + } + + private static class InstanceHolder { + private static final YahooApi20 INSTANCE = new YahooApi20(); + } + + public static YahooApi20 instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://api.login.yahoo.com/oauth2/get_token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://api.login.yahoo.com/oauth2/request_auth"; + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return OpenIdJsonTokenExtractor.instance(); + } + +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java new file mode 100644 index 000000000..653061541 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java @@ -0,0 +1,77 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.YahooApi20; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.*; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.IOException; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +/** + * Flow as documented at https://developer.yahoo.com/oauth2/guide/flows_authcode + *

    + *
  1. Create an application at https://developer.yahoo.com/apps/create/
  2. + *
  3. Make sure the application has the API permission where your protected resource resides (Profiles, Fantasy Sports, etc)
  4. + *
  5. get Client ID and Client Secret after registering your app
  6. + *
+ */ +public class Yahoo20Example { + + // Update PROTECTED_RESOURCE_URL to a secure URL only you could reach = your profile, or private fantasy sports + private static final String PROTECTED_RESOURCE_URL + = "https://baseball.fantasysports.yahoo.com/b1/ ADD TEAM HERE!!!!"; + + private Yahoo20Example() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + + // Add your personal information here + final String clientId = "ADD CLIENT ID HERE!!!!"; + final String clientSecret = "ADD SECRET HERE!!!!"; + + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .callback("oob") + .build(YahooApi20.instance()); + final Scanner in = new Scanner(System.in); + + System.out.println("=== Yahoo's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(service.getAuthorizationUrl()); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + final String oauthVerifier = in.nextLine(); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(oauthVerifier); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + + } +} From bb8deb19b708aa0c09aefe5d323fee11ca812d79 Mon Sep 17 00:00:00 2001 From: Bill Tarr Date: Mon, 19 Feb 2018 17:35:34 -0800 Subject: [PATCH 055/481] fix formatting issues identified by CI. --- .../apis/examples/Yahoo20Example.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java index 653061541..c385ddc44 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java @@ -2,7 +2,10 @@ import com.github.scribejava.apis.YahooApi20; import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.core.model.*; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; @@ -12,14 +15,14 @@ /** * Flow as documented at https://developer.yahoo.com/oauth2/guide/flows_authcode *
    - *
  1. Create an application at https://developer.yahoo.com/apps/create/
  2. - *
  3. Make sure the application has the API permission where your protected resource resides (Profiles, Fantasy Sports, etc)
  4. - *
  5. get Client ID and Client Secret after registering your app
  6. + *
  7. Create an application at https://developer.yahoo.com/apps/create/
  8. + *
  9. Make sure application has permission to API resource (Profiles, Fantasy Sports, etc)
  10. + *
  11. get Client ID and Client Secret after registering your app
  12. *
*/ public class Yahoo20Example { - // Update PROTECTED_RESOURCE_URL to a secure URL only you could reach = your profile, or private fantasy sports + // Update PROTECTED_RESOURCE_URL to a secure URL only you could reach = your profile, or private fantasy sports private static final String PROTECTED_RESOURCE_URL = "https://baseball.fantasysports.yahoo.com/b1/ ADD TEAM HERE!!!!"; @@ -27,9 +30,8 @@ private Yahoo20Example() { } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - - // Add your personal information here - final String clientId = "ADD CLIENT ID HERE!!!!"; + // Add your personal information here + final String clientId = "ADD CLIENT ID HERE!!!!"; final String clientSecret = "ADD SECRET HERE!!!!"; final OAuth20Service service = new ServiceBuilder(clientId) @@ -74,4 +76,4 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } -} +} \ No newline at end of file From dfe04a08dcc8b65ceef36f17f6a400d58336804e Mon Sep 17 00:00:00 2001 From: Bill Tarr Date: Mon, 19 Feb 2018 17:40:20 -0800 Subject: [PATCH 056/481] newline... --- .../com/github/scribejava/apis/examples/Yahoo20Example.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java index c385ddc44..cefd55cce 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java @@ -76,4 +76,4 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } -} \ No newline at end of file +} From e7883ae01c7c7c1691260a5bd9db056854271e27 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 6 Mar 2018 13:42:19 +0300 Subject: [PATCH 057/481] add Yahoo2 API (thanks to https://github.com/javatestcase) --- changelog | 1 + .../main/java/com/github/scribejava/apis/YahooApi20.java | 9 --------- .../github/scribejava/apis/examples/Yahoo20Example.java | 3 +-- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/changelog b/changelog index c3a70d1b4..801b51715 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * fix Salesforce API (thanks to https://github.com/jhorowitz-firedrum) * remove 'final' from methods in OAuth[10a|20]Service to allow mocking it * fix Pinterest API (thanks to https://github.com/sschwieb) + * add Yahoo2 API (thanks to https://github.com/javatestcase) [5.2.0-java7again] * allow 'null' as callback. It's an optional parameter. Remove "oob" as default (thanks to https://github.com/massongit) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi20.java index 11c2f3745..bc50f6779 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi20.java @@ -1,9 +1,6 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.openid.OpenIdJsonTokenExtractor; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; public class YahooApi20 extends DefaultApi20 { @@ -27,10 +24,4 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://api.login.yahoo.com/oauth2/request_auth"; } - - @Override - public TokenExtractor getAccessTokenExtractor() { - return OpenIdJsonTokenExtractor.instance(); - } - } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java index cefd55cce..c2e003876 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java @@ -22,9 +22,8 @@ */ public class Yahoo20Example { - // Update PROTECTED_RESOURCE_URL to a secure URL only you could reach = your profile, or private fantasy sports private static final String PROTECTED_RESOURCE_URL - = "https://baseball.fantasysports.yahoo.com/b1/ ADD TEAM HERE!!!!"; + = "https://fantasysports.yahooapis.com/fantasy/v2/users;use_login=1/games/teams"; private Yahoo20Example() { } From ba7f6f900ac33b92294dd215326bb449c9594272 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 6 Mar 2018 14:25:33 +0300 Subject: [PATCH 058/481] fix Tumblr urls, convert to https (thanks to https://github.com/highthunder) --- changelog | 1 + .../java/com/github/scribejava/apis/AWeberApi.java | 7 +++---- .../java/com/github/scribejava/apis/DiggApi.java | 8 +++----- .../java/com/github/scribejava/apis/EtsyApi.java | 7 +++---- .../java/com/github/scribejava/apis/FlickrApi.java | 11 +++-------- .../com/github/scribejava/apis/FoursquareApi.java | 7 +++---- .../com/github/scribejava/apis/FreelancerApi.java | 11 +++++------ .../com/github/scribejava/apis/LinkedInApi.java | 7 +++---- .../java/com/github/scribejava/apis/MeetupApi.java | 7 +++---- .../github/scribejava/apis/NeteaseWeibooApi.java | 7 +++---- .../java/com/github/scribejava/apis/Px500Api.java | 7 +++---- .../com/github/scribejava/apis/SinaWeiboApi.java | 7 +++---- .../java/com/github/scribejava/apis/SkyrockApi.java | 7 +++---- .../com/github/scribejava/apis/SohuWeiboApi.java | 7 +++---- .../java/com/github/scribejava/apis/TrelloApi.java | 7 +++---- .../java/com/github/scribejava/apis/TumblrApi.java | 7 +++---- .../java/com/github/scribejava/apis/TwitterApi.java | 13 ++++++------- .../java/com/github/scribejava/apis/UcozApi.java | 6 +++--- .../java/com/github/scribejava/apis/XingApi.java | 7 +++---- .../java/com/github/scribejava/apis/YahooApi.java | 7 +++---- .../scribejava/core/builder/api/DefaultApi10a.java | 10 +++++++++- 21 files changed, 72 insertions(+), 86 deletions(-) diff --git a/changelog b/changelog index 801b51715..2bfabdf62 100644 --- a/changelog +++ b/changelog @@ -3,6 +3,7 @@ * remove 'final' from methods in OAuth[10a|20]Service to allow mocking it * fix Pinterest API (thanks to https://github.com/sschwieb) * add Yahoo2 API (thanks to https://github.com/javatestcase) + * fix Tumblr urls, convert to https (thanks to https://github.com/highthunder) [5.2.0-java7again] * allow 'null' as callback. It's an optional parameter. Remove "oob" as default (thanks to https://github.com/massongit) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java index fe5d86691..84e5117df 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class AWeberApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "https://auth.aweber.com/1.0/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZE_URL = "https://auth.aweber.com/1.0/oauth/authorize"; private static final String REQUEST_TOKEN_ENDPOINT = "https://auth.aweber.com/1.0/oauth/request_token"; private static final String ACCESS_TOKEN_ENDPOINT = "https://auth.aweber.com/1.0/oauth/access_token"; @@ -31,7 +30,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java index 047537d8a..c7e8e1bd1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiggApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class DiggApi extends DefaultApi10a { - private static final String AUTHORIZATION_URL = "http://digg.com/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZATION_URL = "http://digg.com/oauth/authorize"; private static final String BASE_URL = "http://services.digg.com/oauth/"; protected DiggApi() { @@ -30,8 +29,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZATION_URL; } - } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java index bd8a660ba..289f83588 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class EtsyApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "https://www.etsy.com/oauth/signin?oauth_token=%s"; + private static final String AUTHORIZE_URL = "https://www.etsy.com/oauth/signin"; private static final String ACCESS_TOKEN_URL = "https://openapi.etsy.com/v2/oauth/access_token"; private static final String REQUEST_TOKEN_URL = "https://openapi.etsy.com/v2/oauth/request_token"; @@ -46,7 +45,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java index aafc6bbd8..33432f2bb 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java @@ -1,7 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; /** * OAuth API for Flickr. @@ -10,7 +9,7 @@ */ public class FlickrApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "https://www.flickr.com/services/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZE_URL = "https://www.flickr.com/services/oauth/authorize"; public enum FlickrPerm { READ, WRITE, DELETE @@ -49,13 +48,9 @@ public String getAccessTokenEndpoint() { return "https://www.flickr.com/services/oauth/access_token"; } - /** - * {@inheritDoc} - */ @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - final String authUrl = String.format(AUTHORIZE_URL, requestToken.getToken()); - return permString == null ? authUrl : authUrl + "&perms=" + permString; + public String getAuthorizationBaseUrl() { + return permString == null ? AUTHORIZE_URL : AUTHORIZE_URL + "?perms=" + permString; } /** diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java index 69111d235..d10a184db 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FoursquareApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class FoursquareApi extends DefaultApi10a { - private static final String AUTHORIZATION_URL = "http://foursquare.com/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZATION_URL = "http://foursquare.com/oauth/authorize"; protected FoursquareApi() { } @@ -29,7 +28,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZATION_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java index 65b64c04f..b5c302ffc 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java @@ -2,12 +2,11 @@ import com.github.scribejava.core.builder.api.DefaultApi10a; import com.github.scribejava.core.builder.api.OAuth1SignatureType; -import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.Verb; public class FreelancerApi extends DefaultApi10a { - private static final String AUTHORIZATION_URL = "http://www.freelancer.com/users/api-token/auth.php?oauth_token=%s"; + private static final String AUTHORIZATION_URL = "http://www.freelancer.com/users/api-token/auth.php"; protected FreelancerApi() { } @@ -46,8 +45,8 @@ public Verb getRequestTokenVerb() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZATION_URL; } public static class Sandbox extends FreelancerApi { @@ -77,8 +76,8 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(SANDBOX_AUTHORIZATION_URL + "?oauth_token=%s", requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return SANDBOX_AUTHORIZATION_URL; } } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java index f30b44d17..62258bbec 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class LinkedInApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "https://api.linkedin.com/uas/oauth/authenticate?oauth_token=%s"; + private static final String AUTHORIZE_URL = "https://api.linkedin.com/uas/oauth/authenticate"; private static final String REQUEST_TOKEN_URL = "https://api.linkedin.com/uas/oauth/requestToken"; private final String scopesAsString; @@ -46,7 +45,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java index b00db6159..b2acc5680 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi.java @@ -1,14 +1,13 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; /** * OAuth access to the Meetup.com API. For more information visit http://www.meetup.com/api */ public class MeetupApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "http://www.meetup.com/authenticate?oauth_token=%s"; + private static final String AUTHORIZE_URL = "http://www.meetup.com/authenticate"; protected MeetupApi() { } @@ -32,7 +31,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java index 91edb38ca..2446b5f58 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java @@ -1,14 +1,13 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuth1Token; public class NeteaseWeibooApi extends DefaultApi10a { private static final String REQUEST_TOKEN_URL = "http://api.t.163.com/oauth/request_token"; private static final String ACCESS_TOKEN_URL = "http://api.t.163.com/oauth/access_token"; - private static final String AUTHORIZE_URL = "http://api.t.163.com/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZE_URL = "http://api.t.163.com/oauth/authorize"; private static final String AUTHENTICATE_URL = "http://api.t.163.com/oauth/authenticate?oauth_token=%s"; protected NeteaseWeibooApi() { @@ -41,8 +40,8 @@ public String getAccessTokenEndpoint() { * @return url to redirect user to (to get code) */ @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } /** diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java index 2c4e6de3c..91e34a449 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Px500Api.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class Px500Api extends DefaultApi10a { - private static final String AUTHORIZATION_URL = "https://api.500px.com/v1/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZATION_URL = "https://api.500px.com/v1/oauth/authorize"; protected Px500Api() { } @@ -29,7 +28,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZATION_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZATION_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java index b91108c18..9d69a9afc 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi.java @@ -1,13 +1,12 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class SinaWeiboApi extends DefaultApi10a { private static final String REQUEST_TOKEN_URL = "http://api.t.sina.com.cn/oauth/request_token"; private static final String ACCESS_TOKEN_URL = "http://api.t.sina.com.cn/oauth/access_token"; - private static final String AUTHORIZE_URL = "http://api.t.sina.com.cn/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZE_URL = "http://api.t.sina.com.cn/oauth/authorize"; protected SinaWeiboApi() { } @@ -31,7 +30,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java index 02c0eb533..beb956a4a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SkyrockApi.java @@ -1,7 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; /** * OAuth API for Skyrock. @@ -12,7 +11,7 @@ public class SkyrockApi extends DefaultApi10a { private static final String API_ENDPOINT = "https://api.skyrock.com/v2"; private static final String REQUEST_TOKEN_RESOURCE = "/oauth/initiate"; - private static final String AUTHORIZE_URL = "/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZE_URL = "/oauth/authorize"; private static final String ACCESS_TOKEN_RESOURCE = "/oauth/token"; protected SkyrockApi() { @@ -37,7 +36,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(API_ENDPOINT + AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return API_ENDPOINT + AUTHORIZE_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java index 6ef769c6a..a8447efd0 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java @@ -1,13 +1,12 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class SohuWeiboApi extends DefaultApi10a { private static final String REQUEST_TOKEN_URL = "http://api.t.sohu.com/oauth/request_token"; private static final String ACCESS_TOKEN_URL = "http://api.t.sohu.com/oauth/access_token"; - private static final String AUTHORIZE_URL = "http://api.t.sohu.com/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZE_URL = "http://api.t.sohu.com/oauth/authorize"; protected SohuWeiboApi() { } @@ -31,7 +30,7 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java index 8fd95f7a2..438f57402 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TrelloApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class TrelloApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "https://trello.com/1/OAuthAuthorizeToken?oauth_token=%s"; + private static final String AUTHORIZE_URL = "https://trello.com/1/OAuthAuthorizeToken"; protected TrelloApi() { } @@ -29,8 +28,8 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java index 0d735ae27..111bf3342 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TumblrApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class TumblrApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "https://www.tumblr.com/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZE_URL = "https://www.tumblr.com/oauth/authorize"; private static final String REQUEST_TOKEN_RESOURCE = "https://www.tumblr.com/oauth/request_token"; private static final String ACCESS_TOKEN_RESOURCE = "https://www.tumblr.com/oauth/access_token"; @@ -31,7 +30,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java index 3d8a2aba7..d18c22b16 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TwitterApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class TwitterApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize?oauth_token=%s"; + private static final String AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize"; private static final String REQUEST_TOKEN_RESOURCE = "api.twitter.com/oauth/request_token"; private static final String ACCESS_TOKEN_RESOURCE = "api.twitter.com/oauth/access_token"; @@ -31,8 +30,8 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } /** @@ -42,7 +41,7 @@ public String getAuthorizationUrl(OAuth1RequestToken requestToken) { */ public static class Authenticate extends TwitterApi { - private static final String AUTHENTICATE_URL = "https://api.twitter.com/oauth/authenticate?oauth_token=%s"; + private static final String AUTHENTICATE_URL = "https://api.twitter.com/oauth/authenticate"; private Authenticate() { } @@ -56,8 +55,8 @@ public static Authenticate instance() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHENTICATE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHENTICATE_URL; } } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java index 208eddc38..1a8992704 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/UcozApi.java @@ -8,7 +8,7 @@ import com.github.scribejava.core.model.OAuth1RequestToken; public class UcozApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "http://uapi.ucoz.com/accounts/oauthauthorizetoken?oauth_token=%s"; + private static final String AUTHORIZE_URL = "http://uapi.ucoz.com/accounts/oauthauthorizetoken"; protected UcozApi() { } @@ -32,8 +32,8 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java index 5bef0670b..b83da3679 100755 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/XingApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class XingApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "https://api.xing.com/v1/authorize?oauth_token=%s"; + private static final String AUTHORIZE_URL = "https://api.xing.com/v1/authorize"; protected XingApi() { } @@ -29,8 +28,8 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java index 18352fdb0..6f3be2038 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/YahooApi.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1RequestToken; public class YahooApi extends DefaultApi10a { - private static final String AUTHORIZE_URL = "https://api.login.yahoo.com/oauth/v2/request_auth?oauth_token=%s"; + private static final String AUTHORIZE_URL = "https://api.login.yahoo.com/oauth/v2/request_auth"; protected YahooApi() { } @@ -29,7 +28,7 @@ public String getRequestTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuth1RequestToken requestToken) { - return String.format(AUTHORIZE_URL, requestToken.getToken()); + public String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index b7167a86e..a9db2c031 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -16,6 +16,8 @@ import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth1AccessToken; import com.github.scribejava.core.model.OAuth1RequestToken; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.ParameterList; /** * Default implementation of the OAuth protocol, version 1.0a @@ -125,13 +127,19 @@ public Verb getRequestTokenVerb() { */ public abstract String getAccessTokenEndpoint(); + protected abstract String getAuthorizationBaseUrl(); + /** * Returns the URL where you should redirect your users to authenticate your application. * * @param requestToken the request token you need to authorize * @return the URL where you should redirect your users */ - public abstract String getAuthorizationUrl(OAuth1RequestToken requestToken); + public String getAuthorizationUrl(OAuth1RequestToken requestToken) { + final ParameterList parameters = new ParameterList(); + parameters.add(OAuthConstants.TOKEN, requestToken.getToken()); + return parameters.appendTo(getAuthorizationBaseUrl()); + } @Override public OAuth10aService createService(OAuthConfig config) { From 255a8e622a343b3b7401916af6cf92baa538bf16 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 7 Mar 2018 12:57:07 +0300 Subject: [PATCH 059/481] fix: allow spaces in scope param in OAuth2Accesstoken response --- changelog | 1 + .../OAuth2AccessTokenJsonExtractor.java | 2 +- .../OAuth2AccessTokenJsonExtractorTest.java | 29 +++++++++++++++++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/changelog b/changelog index 2bfabdf62..ddf57c5fa 100644 --- a/changelog +++ b/changelog @@ -4,6 +4,7 @@ * fix Pinterest API (thanks to https://github.com/sschwieb) * add Yahoo2 API (thanks to https://github.com/javatestcase) * fix Tumblr urls, convert to https (thanks to https://github.com/highthunder) + * fix: allow spaces in scope param in OAuth2Accesstoken response [5.2.0-java7again] * allow 'null' as callback. It's an optional parameter. Remove "oob" as default (thanks to https://github.com/massongit) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index 892b322be..e49831daf 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -19,7 +19,7 @@ public class OAuth2AccessTokenJsonExtractor implements TokenExtractor Date: Wed, 7 Mar 2018 13:13:30 +0300 Subject: [PATCH 060/481] =?UTF-8?q?add=20required=20param=20version=20to?= =?UTF-8?q?=20VK=20=D0=92=D0=9A=D0=BE=D0=BD=D1=82=D0=B0=D0=BA=D1=82=D0=B5?= =?UTF-8?q?=20(http://vk.com/)=20urls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog | 1 + .../main/java/com/github/scribejava/apis/VkontakteApi.java | 4 +++- .../com/github/scribejava/apis/examples/VkontakteExample.java | 3 ++- .../apis/examples/VkontakteExternalHttpExample.java | 3 ++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/changelog b/changelog index ddf57c5fa..6d764ca89 100644 --- a/changelog +++ b/changelog @@ -5,6 +5,7 @@ * add Yahoo2 API (thanks to https://github.com/javatestcase) * fix Tumblr urls, convert to https (thanks to https://github.com/highthunder) * fix: allow spaces in scope param in OAuth2Accesstoken response + * add required param version to VK ВКонтакте (http://vk.com/) urls [5.2.0-java7again] * allow 'null' as callback. It's an optional parameter. Remove "oob" as default (thanks to https://github.com/massongit) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index 7472dba2e..d5c6e48e8 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -7,6 +7,8 @@ public class VkontakteApi extends DefaultApi20 { + public static final String VERSION = "5.73"; + protected VkontakteApi() { } @@ -30,7 +32,7 @@ public String getAccessTokenEndpoint() { @Override protected String getAuthorizationBaseUrl() { - return "https://oauth.vk.com/authorize"; + return "https://oauth.vk.com/authorize?v=" + VERSION; } @Override diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java index b8f1fd2fc..e24261831 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java @@ -14,7 +14,8 @@ public final class VkontakteExample { private static final String NETWORK_NAME = "Vkontakte.ru"; - private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/users.get"; + private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/users.get?v=" + + VkontakteApi.VERSION; private VkontakteExample() { } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java index 1be173c64..eb0958491 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java @@ -17,7 +17,8 @@ public class VkontakteExternalHttpExample { private static final String NETWORK_NAME = "Vkontakte.ru"; - private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/users.get"; + private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/users.get?v=" + + VkontakteApi.VERSION; private VkontakteExternalHttpExample() { } From 48f5f159eb081ac0a8c5e45b0164414eed82fa17 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 7 Mar 2018 13:27:56 +0300 Subject: [PATCH 061/481] update deps --- pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 9fec9cbbb..664d9efa1 100644 --- a/pom.xml +++ b/pom.xml @@ -71,7 +71,7 @@ com.squareup.okhttp3 mockwebserver - 3.9.1 + 3.10.0 test diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index c158ba42f..c8d9ff1d7 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.1.2 + 2.4.3 com.github.scribejava diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 7fc9b7b62..285898fc2 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -23,7 +23,7 @@ org.apache.httpcomponents httpclient - 4.5.4 + 4.5.5 org.apache.httpcomponents diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 6c7d94c39..b627d31b6 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 3.9.1 + 3.10.0 com.github.scribejava From 78dffc5c98b3221abb60593109b1b82224862aff Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 7 Mar 2018 13:36:00 +0300 Subject: [PATCH 062/481] prepare release 5.3.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7359b47da..f56e24a64 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 5.2.0-java7again + 5.3.0 ``` @@ -118,7 +118,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 5.2.0-java7again + 5.3.0 ``` diff --git a/changelog b/changelog index 6d764ca89..272b2b416 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[5.3.0] * fix Salesforce API (thanks to https://github.com/jhorowitz-firedrum) * remove 'final' from methods in OAuth[10a|20]Service to allow mocking it * fix Pinterest API (thanks to https://github.com/sschwieb) From 02b12a661af6c5ce5e0f4a289bd16ee8337293e3 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 7 Mar 2018 13:37:12 +0300 Subject: [PATCH 063/481] [maven-release-plugin] prepare release scribejava-5.3.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 664d9efa1..fedc439d1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.2.1-SNAPSHOT + 5.3.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-5.3.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index b2f8f67a5..8a1b38954 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.2.1-SNAPSHOT + 5.3.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index b4bccf1c3..012f293f1 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.2.1-SNAPSHOT + 5.3.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index c8d9ff1d7..16f664e81 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.2.1-SNAPSHOT + 5.3.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 285898fc2..fc1495b2a 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.2.1-SNAPSHOT + 5.3.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index f688e597d..86236ef2a 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.2.1-SNAPSHOT + 5.3.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index b627d31b6..1423f32e0 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.2.1-SNAPSHOT + 5.3.0 ../pom.xml From dc54b59032f1c53c4366b998695da8a1b253fe33 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 7 Mar 2018 13:37:22 +0300 Subject: [PATCH 064/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index fedc439d1..95d3f3d46 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.3.0 + 5.3.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-5.3.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 8a1b38954..f6e826693 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.0 + 5.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 012f293f1..d9ddaeb76 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.0 + 5.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 16f664e81..49ac5ad69 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.0 + 5.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index fc1495b2a..0bd9b04ec 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.0 + 5.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 86236ef2a..7b5e1b0e4 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.0 + 5.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 1423f32e0..674113b2f 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.0 + 5.3.1-SNAPSHOT ../pom.xml From 7228206ba015454f29f3574ad1c6078ffdc3a889 Mon Sep 17 00:00:00 2001 From: Sriram Date: Fri, 9 Mar 2018 11:35:14 -0800 Subject: [PATCH 065/481] Added Automatic OAuth2 API Signed-off-by: Sriram --- README.md | 1 + .../github/scribejava/apis/AutomaticAPI.java | 58 +++++++++++++ .../apis/examples/AutomaticExample.java | 83 +++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java diff --git a/README.md b/README.md index f56e24a64..e321a9547 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ ScribeJava support out-of-box several HTTP clients: ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box +* Automatic (http://www.automatic.com/) * AWeber (http://www.aweber.com/) * Box (https://www.box.com/) * Dataporten (https://docs.dataporten.no/) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java new file mode 100644 index 000000000..66f8b391a --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java @@ -0,0 +1,58 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.ClientAuthenticationType; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.OAuth2AccessTokenExtractor; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.Verb; + +public class AutomaticAPI extends DefaultApi20 { + + private static final String AUTHORIZE_URL = "https://accounts.automatic.com/oauth/authorize"; + private static final String REFRESH_TOKEN_ENDPOINT = "https://accounts.automatic.com/oauth/refresh_token"; + private static final String ACCESS_TOKEN_ENDPOINT = "https://accounts.automatic.com/oauth/access_token"; + + protected AutomaticAPI() { + } + + private static class InstanceHolder { + private static final AutomaticAPI INSTANCE = new AutomaticAPI(); + } + + public static AutomaticAPI instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public String getAccessTokenEndpoint() { + return ACCESS_TOKEN_ENDPOINT; + } + + @Override + public String getRefreshTokenEndpoint() { + return REFRESH_TOKEN_ENDPOINT; + } + + @Override + protected String getAuthorizationBaseUrl() { + return AUTHORIZE_URL; + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return OAuth2AccessTokenJsonExtractor.instance(); + } + + @Override + public ClientAuthenticationType getClientAuthenticationType() { + return ClientAuthenticationType.REQUEST_BODY; + } + +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java new file mode 100644 index 000000000..e1cb6b809 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java @@ -0,0 +1,83 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.AutomaticAPI; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.IOException; +import java.util.Random; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public final class AutomaticExample { + + private static final String NETWORK_NAME = "Automatic"; + private static final String PROTECTED_RESOURCE_URL = "https://api.automatic.com/user/me/"; + + private AutomaticExample() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .state(secretState) + .callback("http://www.example.com/oauth_callback/") + .scope("scope:user:profile").debug() + .build(AutomaticAPI.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Authorization Code for the Access Token + System.out.println("Trading the Authorization Code for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} From b4fb7f816ef849edc6c75431f65d3aac6de5ef4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tellef=20M=C3=B8llerup=20=C3=85mdal?= Date: Wed, 7 Mar 2018 14:01:20 +0100 Subject: [PATCH 066/481] Fixed missing support for scope for refresh_token grant. https://tools.ietf.org/html/rfc6749#section-6 --- .../com/github/scribejava/core/oauth/OAuth20Service.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 0aed00b0b..2d78ec555 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -148,8 +148,14 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken) { throw new IllegalArgumentException("The refreshToken cannot be null or empty"); } final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint()); + final OAuthConfig config = getConfig(); - api.getClientAuthenticationType().addClientAuthentication(request, getConfig()); + api.getClientAuthenticationType().addClientAuthentication(request, config); + + final String scope = config.getScope(); + if (scope != null) { + request.addParameter(OAuthConstants.SCOPE, scope); + } request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); From 787668d196220bbc951bbb6eeacd7f263b37bc11 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 22 Mar 2018 10:51:47 +0300 Subject: [PATCH 067/481] fix missing support for scope for refresh_token grant_type [thanks to https://github.com/tlxtellef] --- changelog | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changelog b/changelog index 272b2b416..8db2521eb 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * fix missing support for scope for refresh_token grant_type [thanks to https://github.com/tlxtellef] + [5.3.0] * fix Salesforce API (thanks to https://github.com/jhorowitz-firedrum) * remove 'final' from methods in OAuth[10a|20]Service to allow mocking it From 71f8539df1b5bfb758151d1ebc1d15def12afc0f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 22 Mar 2018 12:21:30 +0300 Subject: [PATCH 068/481] add email field to VKOAuth2AccessToken (thanks to https://github.com/grouzen) --- changelog | 3 +- .../github/scribejava/apis/VkontakteApi.java | 9 ++++ .../apis/vk/VKJsonTokenExtractor.java | 31 ++++++++++++ .../apis/vk/VKOAuth2AccessToken.java | 50 +++++++++++++++++++ .../apis/examples/VkontakteExample.java | 7 ++- .../core/model/OAuth2AccessToken.java | 1 - 6 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKOAuth2AccessToken.java diff --git a/changelog b/changelog index 8db2521eb..1251ce824 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] - * fix missing support for scope for refresh_token grant_type [thanks to https://github.com/tlxtellef] + * fix missing support for scope for refresh_token grant_type (thanks to https://github.com/tlxtellef) + * add email field to VKOAuth2AccessToken (thanks to https://github.com/grouzen) [5.3.0] * fix Salesforce API (thanks to https://github.com/jhorowitz-firedrum) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index d5c6e48e8..1654ff34a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -1,8 +1,11 @@ package com.github.scribejava.apis; +import com.github.scribejava.apis.vk.VKJsonTokenExtractor; import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.builder.api.OAuth2SignatureType; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.Verb; public class VkontakteApi extends DefaultApi20 { @@ -13,6 +16,7 @@ protected VkontakteApi() { } private static class InstanceHolder { + private static final VkontakteApi INSTANCE = new VkontakteApi(); } @@ -44,4 +48,9 @@ public OAuth2SignatureType getSignatureType() { public ClientAuthenticationType getClientAuthenticationType() { return ClientAuthenticationType.REQUEST_BODY; } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return VKJsonTokenExtractor.instance(); + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java new file mode 100644 index 000000000..4e658b061 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java @@ -0,0 +1,31 @@ +package com.github.scribejava.apis.vk; + +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import java.util.regex.Pattern; + +/** + * additionally parses email + */ +public class VKJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { + + private static final Pattern EMAIL_REGEX_PATTERN = Pattern.compile("\"email\"\\s*:\\s*\"(\\S*?)\""); + + protected VKJsonTokenExtractor() { + } + + private static class InstanceHolder { + + private static final VKJsonTokenExtractor INSTANCE = new VKJsonTokenExtractor(); + } + + public static VKJsonTokenExtractor instance() { + return InstanceHolder.INSTANCE; + } + + @Override + protected VKOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, + String refreshToken, String scope, String response) { + return new VKOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, + extractParameter(response, EMAIL_REGEX_PATTERN, false), response); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKOAuth2AccessToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKOAuth2AccessToken.java new file mode 100644 index 000000000..a8e75992b --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKOAuth2AccessToken.java @@ -0,0 +1,50 @@ +package com.github.scribejava.apis.vk; + +import com.github.scribejava.core.model.OAuth2AccessToken; +import java.util.Objects; + +public class VKOAuth2AccessToken extends OAuth2AccessToken { + + private static final long serialVersionUID = -3539517142527580499L; + + private final String email; + + public VKOAuth2AccessToken(String accessToken, String email, String rawResponse) { + this(accessToken, null, null, null, null, email, rawResponse); + } + + public VKOAuth2AccessToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, + String scope, String email, String rawResponse) { + super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); + this.email = email; + } + + public String getEmail() { + return email; + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 37 * hash + Objects.hashCode(email); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + if (!super.equals(obj)) { + return false; + } + + return Objects.equals(email, ((VKOAuth2AccessToken) obj).getEmail()); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java index e24261831..5c18980b2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java @@ -3,6 +3,7 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.VkontakteApi; +import com.github.scribejava.apis.vk.VKOAuth2AccessToken; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; @@ -26,7 +27,7 @@ public static void main(String... args) throws IOException, InterruptedException final String clientSecret = "your client secret"; final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .scope("wall,offline") // replace with desired scope + .scope("wall,offline,email") // replace with desired scope .callback("http://your.site.com/callback") .build(VkontakteApi.instance()); final Scanner in = new Scanner(System.in); @@ -50,6 +51,10 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + if (accessToken instanceof VKOAuth2AccessToken) { + System.out.println("it's a VKOAuth2AccessToken, it has email field = '" + + ((VKOAuth2AccessToken) accessToken).getEmail() + "'."); + } System.out.println(); // Now let's go and ask for a protected resource! diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java index 2b30f2031..37b951f13 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java @@ -73,7 +73,6 @@ public OAuth2AccessToken(String accessToken, String tokenType, Integer expiresIn this.scope = scope; } - public String getAccessToken() { return accessToken; } From f399f7152feafbd723299248f42fc3e7830d749b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 26 Mar 2018 12:44:10 +0300 Subject: [PATCH 069/481] add RFC urls to javadocs --- .../scribejava/core/extractors/BaseStringExtractorImpl.java | 4 ++++ .../scribejava/core/services/HMACSha1SignatureService.java | 1 + .../com/github/scribejava/core/services/SignatureService.java | 1 + 3 files changed, 6 insertions(+) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java index 879dac9ae..acda30254 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java @@ -8,6 +8,7 @@ /** * Default implementation of {@link BaseStringExtractor}. Conforms to OAuth 1.0a + * https://tools.ietf.org/html/rfc5849#section-3.4.1.1 */ public class BaseStringExtractorImpl implements BaseStringExtractor { @@ -29,6 +30,9 @@ protected String getVerb(OAuthRequest request) { return request.getVerb().name(); } + /** + * https://tools.ietf.org/html/rfc5849#section-3.4.1.2 + */ protected String getUrl(OAuthRequest request) { return request.getSanitizedUrl(); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java index 3d942fbd0..82d1135be 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java @@ -11,6 +11,7 @@ /** * HMAC-SHA1 implementation of {@link SignatureService} + * https://tools.ietf.org/html/rfc5849#section-3.4.2 */ public class HMACSha1SignatureService implements SignatureService { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java index 2248643c5..8cd4f2372 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java @@ -4,6 +4,7 @@ /** * Signs a base string, returning the OAuth signature + * https://tools.ietf.org/html/rfc5849#section-3.4 */ public interface SignatureService { Base64.Encoder BASE_64_ENCODER = Base64.getEncoder(); From 09364b69afa30e059ceb2276384cb97e465e42c4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 4 Apr 2018 14:32:38 +0300 Subject: [PATCH 070/481] add new API - Automatic (https://www.automatic.com/) (thanks to https://github.com/ramsrib) --- README.md | 2 +- changelog | 1 + .../com/github/scribejava/apis/AutomaticAPI.java | 16 +--------------- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index e321a9547..939ff5343 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ ScribeJava support out-of-box several HTTP clients: ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box -* Automatic (http://www.automatic.com/) +* Automatic (https://www.automatic.com/) * AWeber (http://www.aweber.com/) * Box (https://www.box.com/) * Dataporten (https://docs.dataporten.no/) diff --git a/changelog b/changelog index 1251ce824..f117ca857 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * fix missing support for scope for refresh_token grant_type (thanks to https://github.com/tlxtellef) * add email field to VKOAuth2AccessToken (thanks to https://github.com/grouzen) + * add new API - Automatic (https://www.automatic.com/) (thanks to https://github.com/ramsrib) [5.3.0] * fix Salesforce API (thanks to https://github.com/jhorowitz-firedrum) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java index 66f8b391a..479fc5d59 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java @@ -2,11 +2,6 @@ import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.OAuth2AccessTokenExtractor; -import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.Verb; public class AutomaticAPI extends DefaultApi20 { @@ -18,6 +13,7 @@ protected AutomaticAPI() { } private static class InstanceHolder { + private static final AutomaticAPI INSTANCE = new AutomaticAPI(); } @@ -25,11 +21,6 @@ public static AutomaticAPI instance() { return InstanceHolder.INSTANCE; } - @Override - public Verb getAccessTokenVerb() { - return Verb.POST; - } - @Override public String getAccessTokenEndpoint() { return ACCESS_TOKEN_ENDPOINT; @@ -45,11 +36,6 @@ protected String getAuthorizationBaseUrl() { return AUTHORIZE_URL; } - @Override - public TokenExtractor getAccessTokenExtractor() { - return OAuth2AccessTokenJsonExtractor.instance(); - } - @Override public ClientAuthenticationType getClientAuthenticationType() { return ClientAuthenticationType.REQUEST_BODY; From 4e6d8c5c90c4eaf358cc327109fba331767ce7e8 Mon Sep 17 00:00:00 2001 From: Justin Lawler Date: Tue, 10 Apr 2018 16:58:32 +0100 Subject: [PATCH 071/481] adding fitbit API --- README.md | 1 + .../github/scribejava/apis/FitbitApi20.java | 43 +++++++++ .../apis/service/Fitbit20ServiceImpl.java | 91 +++++++++++++++++++ .../apis/examples/FitbitApi20Example.java | 79 ++++++++++++++++ 4 files changed, 214 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/FitbitApi20.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/Fitbit20ServiceImpl.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java diff --git a/README.md b/README.md index 939ff5343..07f185d5d 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ ScribeJava support out-of-box several HTTP clients: * Доктор на работе (https://www.doktornarabote.ru/) * Etsy (https://www.etsy.com/) * Facebook (https://www.facebook.com/) +* Fitbit (https://www.fitbit.com/) * Flickr (https://www.flickr.com/) * Foursquare (https://foursquare.com/) * Frappe (https://github.com/frappe/frappe) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FitbitApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FitbitApi20.java new file mode 100644 index 000000000..7d4fa85b2 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FitbitApi20.java @@ -0,0 +1,43 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.service.Fitbit20ServiceImpl; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.oauth.OAuth20Service; + + +/** + * Fitbit's OAuth2 client's implementation + * source: https://dev.fitbit.com/docs/oauth2/ + * + * Note - this is an updated version of this library for Scribe v5.3.0. Original code here: + * - https://github.com/alexthered/fitbitAPI20-scribe-java + */ +public class FitbitApi20 extends DefaultApi20 { + + protected FitbitApi20() { + } + + private static class InstanceHolder { + private static final FitbitApi20 INSTANCE = new FitbitApi20(); + } + + public static FitbitApi20 instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://api.fitbit.com/oauth2/token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://www.fitbit.com/oauth2/authorize"; + } + + @Override + public OAuth20Service createService(OAuthConfig config) { + return new Fitbit20ServiceImpl(this, config); + } +} \ No newline at end of file diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/Fitbit20ServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/Fitbit20ServiceImpl.java new file mode 100644 index 000000000..7884d846d --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/Fitbit20ServiceImpl.java @@ -0,0 +1,91 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.java8.Base64; +import com.github.scribejava.core.model.OAuthConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.nio.charset.Charset; + +/** + * Created by hd on 10/09/16. + * + * Note - this is an updated version of this library for Scribe v5.3.0. Original code here: + * - https://github.com/alexthered/fitbitAPI20-scribe-java + */ +public class Fitbit20ServiceImpl extends OAuth20Service { + + public Fitbit20ServiceImpl(DefaultApi20 api, OAuthConfig config) { + super(api, config); + } + + /** + * ref: https://dev.fitbit.com/docs/oauth2/#access-token-request + * @param code + * @param request + * @param + * @return + */ + @Override + protected OAuthRequest createAccessTokenRequest(String code) + { + final DefaultApi20 api = getApi(); + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); + final OAuthConfig config = getConfig(); + request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); + request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); + request.addParameter(OAuthConstants.CODE, code); + request.addParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); + String scope = config.getScope(); + if (scope != null) { + request.addParameter(OAuthConstants.SCOPE, scope); + } + + //this is non-OAuth2 standard, but Fitbit requires it + request.addHeader("Authorization", "Basic " + getKeyBytesForFitbitAuth()); + + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); + return request; + } + + /** + * ref: https://dev.fitbit.com/docs/oauth2/#refreshing-tokens + * @param refreshToken + * @param request + * @param + * @return + */ + @Override + protected OAuthRequest createRefreshTokenRequest(String refreshToken) + { + if (refreshToken != null && !refreshToken.isEmpty()) { + final DefaultApi20 api = getApi(); + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); + final OAuthConfig config = this.getConfig(); + request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); + request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); + request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); + + //this is non-OAuth2 standard, but Fitbit requires it + request.addHeader("Authorization", "Basic " + getKeyBytesForFitbitAuth()); + + return request; + } else { + throw new IllegalArgumentException("The refreshToken cannot be null or empty"); + } + } + + /** + */ + private String getKeyBytesForFitbitAuth() + { + final OAuthConfig config = getConfig(); + String keyAndSecret = String.format("%s:%s", new Object[] {config.getApiKey(), config.getApiSecret()}); + byte[] keyBytes = Base64.getEncoder().encode(keyAndSecret.getBytes(Charset.forName("UTF-8"))); + + return new String(keyBytes); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java new file mode 100644 index 000000000..760dc165e --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java @@ -0,0 +1,79 @@ +package com.github.scribejava.apis.examples; +import java.util.Scanner; + +import com.github.scribejava.apis.FitbitApi20; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +/** + * Created by hd on 10/09/16. + */ +public class FitbitApi20Example { + + private static final String NETWORK_NAME = "Fitbit"; + + // Replace with user ID to test API against + private static final String USER_ID = "your user id"; + private static final String PROTECTED_RESOURCE_URL = "https://api.fitbit.com/1/user/" + USER_ID + "/profile.json"; + + + private FitbitApi20Example() { + } + + public static void main(String... args) throws Exception { + + // Replace these with your client id and secret fron your app + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .scope("activity profile") // replace with desired scope + .callback("http://www.example.com/oauth_callback/") //your callback URL to store and handle the authorization code sent by Fitbit + .state("some_params") + .build(FitbitApi20.instance()); + final Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + // This will get the profile for this user + System.out.println("Now we're going to access a protected resource..."); + + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + request.addHeader("x-li-format", "json"); + + //add header for authentication (why make it so complicated, Fitbit?) + request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); + + final Response response = service.execute(request); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + } +} From 875db910f593276cacf50aa8d38f650bdffbbfb8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 11 Apr 2018 14:56:20 +0300 Subject: [PATCH 072/481] add new API - Fitbit (https://www.fitbit.com/) (thanks to https://github.com/JustinLawler and https://github.com/alexthered) --- changelog | 1 + .../github/scribejava/apis/FitbitApi20.java | 13 +-- .../apis/fitbit/FitBitJsonTokenExtractor.java | 28 ++++++ .../apis/fitbit/FitBitOAuth2AccessToken.java | 50 ++++++++++ .../apis/service/Fitbit20ServiceImpl.java | 91 ------------------- .../apis/examples/FitbitApi20Example.java | 35 +++---- 6 files changed, 102 insertions(+), 116 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitOAuth2AccessToken.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/Fitbit20ServiceImpl.java diff --git a/changelog b/changelog index f117ca857..09db0ac72 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * fix missing support for scope for refresh_token grant_type (thanks to https://github.com/tlxtellef) * add email field to VKOAuth2AccessToken (thanks to https://github.com/grouzen) * add new API - Automatic (https://www.automatic.com/) (thanks to https://github.com/ramsrib) + * add new API - Fitbit (https://www.fitbit.com/) (thanks to https://github.com/JustinLawler and https://github.com/alexthered) [5.3.0] * fix Salesforce API (thanks to https://github.com/jhorowitz-firedrum) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FitbitApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FitbitApi20.java index 7d4fa85b2..f6e163978 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FitbitApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FitbitApi20.java @@ -1,17 +1,12 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.service.Fitbit20ServiceImpl; +import com.github.scribejava.apis.fitbit.FitBitJsonTokenExtractor; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.oauth.OAuth20Service; /** * Fitbit's OAuth2 client's implementation * source: https://dev.fitbit.com/docs/oauth2/ - * - * Note - this is an updated version of this library for Scribe v5.3.0. Original code here: - * - https://github.com/alexthered/fitbitAPI20-scribe-java */ public class FitbitApi20 extends DefaultApi20 { @@ -37,7 +32,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth20Service createService(OAuthConfig config) { - return new Fitbit20ServiceImpl(this, config); + public FitBitJsonTokenExtractor getAccessTokenExtractor() { + return FitBitJsonTokenExtractor.instance(); } -} \ No newline at end of file +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java new file mode 100644 index 000000000..affed2f6d --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java @@ -0,0 +1,28 @@ +package com.github.scribejava.apis.fitbit; + +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import java.util.regex.Pattern; + +public class FitBitJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { + + private static final Pattern USER_ID_REGEX_PATTERN = Pattern.compile("\"user_id\"\\s*:\\s*\"(\\S*?)\""); + + protected FitBitJsonTokenExtractor() { + } + + private static class InstanceHolder { + + private static final FitBitJsonTokenExtractor INSTANCE = new FitBitJsonTokenExtractor(); + } + + public static FitBitJsonTokenExtractor instance() { + return InstanceHolder.INSTANCE; + } + + @Override + protected FitBitOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, + String refreshToken, String scope, String response) { + return new FitBitOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, + extractParameter(response, USER_ID_REGEX_PATTERN, false), response); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitOAuth2AccessToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitOAuth2AccessToken.java new file mode 100644 index 000000000..018128bde --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitOAuth2AccessToken.java @@ -0,0 +1,50 @@ +package com.github.scribejava.apis.fitbit; + +import com.github.scribejava.core.model.OAuth2AccessToken; +import java.util.Objects; + +public class FitBitOAuth2AccessToken extends OAuth2AccessToken { + + private static final long serialVersionUID = -6374486860742407411L; + + private final String userId; + + public FitBitOAuth2AccessToken(String accessToken, String openIdToken, String rawResponse) { + this(accessToken, null, null, null, null, openIdToken, rawResponse); + } + + public FitBitOAuth2AccessToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, + String scope, String userId, String rawResponse) { + super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); + this.userId = userId; + } + + public String getUserId() { + return userId; + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 37 * hash + Objects.hashCode(userId); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + if (!super.equals(obj)) { + return false; + } + + return Objects.equals(userId, ((FitBitOAuth2AccessToken) obj).getUserId()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/Fitbit20ServiceImpl.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/Fitbit20ServiceImpl.java deleted file mode 100644 index 7884d846d..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/Fitbit20ServiceImpl.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.java8.Base64; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; - -import java.nio.charset.Charset; - -/** - * Created by hd on 10/09/16. - * - * Note - this is an updated version of this library for Scribe v5.3.0. Original code here: - * - https://github.com/alexthered/fitbitAPI20-scribe-java - */ -public class Fitbit20ServiceImpl extends OAuth20Service { - - public Fitbit20ServiceImpl(DefaultApi20 api, OAuthConfig config) { - super(api, config); - } - - /** - * ref: https://dev.fitbit.com/docs/oauth2/#access-token-request - * @param code - * @param request - * @param - * @return - */ - @Override - protected OAuthRequest createAccessTokenRequest(String code) - { - final DefaultApi20 api = getApi(); - final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - final OAuthConfig config = getConfig(); - request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); - request.addParameter(OAuthConstants.CODE, code); - request.addParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); - String scope = config.getScope(); - if (scope != null) { - request.addParameter(OAuthConstants.SCOPE, scope); - } - - //this is non-OAuth2 standard, but Fitbit requires it - request.addHeader("Authorization", "Basic " + getKeyBytesForFitbitAuth()); - - request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); - return request; - } - - /** - * ref: https://dev.fitbit.com/docs/oauth2/#refreshing-tokens - * @param refreshToken - * @param request - * @param - * @return - */ - @Override - protected OAuthRequest createRefreshTokenRequest(String refreshToken) - { - if (refreshToken != null && !refreshToken.isEmpty()) { - final DefaultApi20 api = getApi(); - final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - final OAuthConfig config = this.getConfig(); - request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); - request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); - request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); - - //this is non-OAuth2 standard, but Fitbit requires it - request.addHeader("Authorization", "Basic " + getKeyBytesForFitbitAuth()); - - return request; - } else { - throw new IllegalArgumentException("The refreshToken cannot be null or empty"); - } - } - - /** - */ - private String getKeyBytesForFitbitAuth() - { - final OAuthConfig config = getConfig(); - String keyAndSecret = String.format("%s:%s", new Object[] {config.getApiKey(), config.getApiSecret()}); - byte[] keyBytes = Base64.getEncoder().encode(keyAndSecret.getBytes(Charset.forName("UTF-8"))); - - return new String(keyBytes); - } -} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java index 760dc165e..72750de6b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java @@ -1,7 +1,9 @@ package com.github.scribejava.apis.examples; + import java.util.Scanner; import com.github.scribejava.apis.FitbitApi20; +import com.github.scribejava.apis.fitbit.FitBitOAuth2AccessToken; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; @@ -9,30 +11,25 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; -/** - * Created by hd on 10/09/16. - */ public class FitbitApi20Example { private static final String NETWORK_NAME = "Fitbit"; - - // Replace with user ID to test API against - private static final String USER_ID = "your user id"; - private static final String PROTECTED_RESOURCE_URL = "https://api.fitbit.com/1/user/" + USER_ID + "/profile.json"; - + private static final String PROTECTED_RESOURCE_URL = "https://api.fitbit.com/1/user/%s/profile.json"; + private FitbitApi20Example() { } public static void main(String... args) throws Exception { - + // Replace these with your client id and secret fron your app final String clientId = "your client id"; final String clientSecret = "your client secret"; final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("activity profile") // replace with desired scope - .callback("http://www.example.com/oauth_callback/") //your callback URL to store and handle the authorization code sent by Fitbit + //your callback URL to store and handle the authorization code sent by Fitbit + .callback("http://www.example.com/oauth_callback/") .state("some_params") .build(FitbitApi20.instance()); final Scanner in = new Scanner(System.in); @@ -53,21 +50,27 @@ public static void main(String... args) throws Exception { // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(code); + final OAuth2AccessToken oauth2AccessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); - System.out.println("(if your curious it looks like this: " + accessToken - + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println("(if your curious it looks like this: " + oauth2AccessToken + + ", 'rawResponse'='" + oauth2AccessToken.getRawResponse() + "')"); System.out.println(); + if (!(oauth2AccessToken instanceof FitBitOAuth2AccessToken)) { + System.out.println("oauth2AccessToken is not instance of FitBitOAuth2AccessToken. Strange enough. exit."); + System.exit(0); + } + + final FitBitOAuth2AccessToken accessToken = (FitBitOAuth2AccessToken) oauth2AccessToken; // Now let's go and ask for a protected resource! // This will get the profile for this user System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + final OAuthRequest request = new OAuthRequest(Verb.GET, + String.format(PROTECTED_RESOURCE_URL, accessToken.getUserId())); request.addHeader("x-li-format", "json"); - //add header for authentication (why make it so complicated, Fitbit?) - request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken()); + service.signRequest(accessToken, request); final Response response = service.execute(request); System.out.println(); From aec994745985ef4b8e2fa2db7f2f20f3d5349186 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 18 Apr 2018 13:43:55 +0300 Subject: [PATCH 073/481] deprecate OAuthConfig --- changelog | 1 + .../github/scribejava/apis/FacebookApi.java | 21 ++++- .../com/github/scribejava/apis/ImgurApi.java | 35 +++++-- .../com/github/scribejava/apis/MailruApi.java | 21 ++++- .../MicrosoftAzureActiveDirectoryApi.java | 21 ++++- .../scribejava/apis/OdnoklassnikiApi.java | 21 ++++- .../com/github/scribejava/apis/TutByApi.java | 21 ++++- .../apis/service/FacebookService.java | 23 ++++- .../apis/service/ImgurOAuthService.java | 31 +++++-- .../apis/service/MailruOAuthService.java | 26 +++++- .../MicrosoftAzureActiveDirectoryService.java | 21 ++++- .../service/OdnoklassnikiOAuthService.java | 23 ++++- .../apis/service/TutByOAuthService.java | 21 ++++- .../apis/examples/Yahoo20Example.java | 3 +- .../core/builder/ServiceBuilder.java | 8 +- .../scribejava/core/builder/api/BaseApi.java | 13 +++ .../builder/api/ClientAuthenticationType.java | 20 ++-- .../core/builder/api/DefaultApi10a.java | 21 ++++- .../core/builder/api/DefaultApi20.java | 41 +++++++-- .../scribejava/core/model/OAuthConfig.java | 13 ++- .../scribejava/core/model/OAuthConstants.java | 3 + .../core/oauth/OAuth10aService.java | 88 +++++++++++------- .../scribejava/core/oauth/OAuth20Service.java | 59 ++++++++---- .../scribejava/core/oauth/OAuthService.java | 92 ++++++++++++++----- .../scribejava/core/AbstractClientTest.java | 5 +- .../core/builder/ServiceBuilderTest.java | 84 ----------------- .../scribejava/core/oauth/OAuth20ApiUnit.java | 21 ++++- .../core/oauth/OAuth20ServiceTest.java | 6 +- .../core/oauth/OAuth20ServiceUnit.java | 11 ++- 29 files changed, 552 insertions(+), 222 deletions(-) delete mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java diff --git a/changelog b/changelog index 09db0ac72..21b5817a4 100644 --- a/changelog +++ b/changelog @@ -3,6 +3,7 @@ * add email field to VKOAuth2AccessToken (thanks to https://github.com/grouzen) * add new API - Automatic (https://www.automatic.com/) (thanks to https://github.com/ramsrib) * add new API - Fitbit (https://www.fitbit.com/) (thanks to https://github.com/JustinLawler and https://github.com/alexthered) + * deprecate OAuthConfig [5.3.0] * fix Salesforce API (thanks to https://github.com/jhorowitz-firedrum) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index 949304dfb..a2114760b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -5,9 +5,12 @@ import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; +import java.io.OutputStream; /** * Facebook API @@ -67,8 +70,24 @@ public ClientAuthenticationType getClientAuthenticationType() { return ClientAuthenticationType.REQUEST_BODY; } + @Override + public FacebookService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new FacebookService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, + userAgent, httpClientConfig, httpClient); + } + + /** + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override public FacebookService createService(OAuthConfig config) { - return new FacebookService(this, config); + return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index 477fb5e0f..720b62fd2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -2,9 +2,12 @@ import com.github.scribejava.apis.service.ImgurOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.ParameterList; +import java.io.OutputStream; import java.util.Map; public class ImgurApi extends DefaultApi20 { @@ -26,22 +29,20 @@ public String getAccessTokenEndpoint() { } @Override - public String getAuthorizationUrl(OAuthConfig config, Map additionalParams) { + public String getAuthorizationUrl(String responseType, String apiKey, String callback, String scope, String state, + Map additionalParams) { final ParameterList parameters = new ParameterList(additionalParams); - parameters.add(OAuthConstants.RESPONSE_TYPE, isOob(config) ? "pin" : "code"); - parameters.add(OAuthConstants.CLIENT_ID, config.getApiKey()); + parameters.add(OAuthConstants.RESPONSE_TYPE, isOob(callback) ? "pin" : "code"); + parameters.add(OAuthConstants.CLIENT_ID, apiKey); - final String callback = config.getCallback(); if (callback != null) { parameters.add(OAuthConstants.REDIRECT_URI, callback); } - final String scope = config.getScope(); if (scope != null) { parameters.add(OAuthConstants.SCOPE, scope); } - final String state = config.getState(); if (state != null) { parameters.add(OAuthConstants.STATE, state); } @@ -54,12 +55,28 @@ protected String getAuthorizationBaseUrl() { throw new UnsupportedOperationException("use getAuthorizationUrl instead"); } + @Override + public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new ImgurOAuthService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, + userAgent, httpClientConfig, httpClient); + } + + /** + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override public ImgurOAuthService createService(OAuthConfig config) { - return new ImgurOAuthService(this, config); + return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); } - public static boolean isOob(OAuthConfig config) { - return "oob".equals(config.getCallback()); + public static boolean isOob(String callback) { + return OAuthConstants.OOB.equals(callback); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index cf9ae9903..318ab2bf2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -3,6 +3,9 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.apis.service.MailruOAuthService; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import java.io.OutputStream; public class MailruApi extends DefaultApi20 { @@ -27,8 +30,24 @@ protected String getAuthorizationBaseUrl() { return "https://connect.mail.ru/oauth/authorize"; } + @Override + public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new MailruOAuthService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, + userAgent, httpClientConfig, httpClient); + } + + /** + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override public MailruOAuthService createService(OAuthConfig config) { - return new MailruOAuthService(this, config); + return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java index 44ea915e5..c2059d55b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java @@ -3,7 +3,10 @@ import com.github.scribejava.apis.service.MicrosoftAzureActiveDirectoryService; import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; +import java.io.OutputStream; /** * Microsoft Azure Active Directory Api @@ -46,9 +49,25 @@ protected String getAuthorizationBaseUrl() { return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI; } + @Override + public MicrosoftAzureActiveDirectoryService createService(String apiKey, String apiSecret, String callback, + String scope, OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new MicrosoftAzureActiveDirectoryService(this, apiKey, apiSecret, callback, scope, debugStream, state, + responseType, userAgent, httpClientConfig, httpClient); + } + + /** + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override public MicrosoftAzureActiveDirectoryService createService(OAuthConfig config) { - return new MicrosoftAzureActiveDirectoryService(this, config); + return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index 4582d1ac9..a65f9b692 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -4,7 +4,10 @@ import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.builder.api.OAuth2SignatureType; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; +import java.io.OutputStream; public class OdnoklassnikiApi extends DefaultApi20 { @@ -29,9 +32,25 @@ protected String getAuthorizationBaseUrl() { return "https://connect.ok.ru/oauth/authorize"; } + @Override + public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new OdnoklassnikiOAuthService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, + userAgent, httpClientConfig, httpClient); + } + + /** + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override public OdnoklassnikiOAuthService createService(OAuthConfig config) { - return new OdnoklassnikiOAuthService(this, config); + return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java index 0e7359f08..a6b864fb7 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java @@ -2,7 +2,10 @@ import com.github.scribejava.apis.service.TutByOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; +import java.io.OutputStream; public class TutByApi extends DefaultApi20 { @@ -27,8 +30,24 @@ protected String getAuthorizationBaseUrl() { return "http://profile.tut.by/auth"; } + @Override + public TutByOAuthService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new TutByOAuthService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, + userAgent, httpClientConfig, httpClient); + } + + /** + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override public TutByOAuthService createService(OAuthConfig config) { - return new TutByOAuthService(this, config); + return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java index c506ce852..925d20f15 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java @@ -1,9 +1,12 @@ package com.github.scribejava.apis.service; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.OutputStream; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.Formatter; @@ -12,8 +15,24 @@ public class FacebookService extends OAuth20Service { + /** + * @deprecated use {@link #FacebookService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, + * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated public FacebookService(DefaultApi20 api, OAuthConfig config) { - super(api, config); + this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); + } + + public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, + httpClient); } @Override @@ -23,7 +42,7 @@ public void signRequest(String accessToken, OAuthRequest request) { final Mac mac; try { mac = Mac.getInstance("HmacSHA256"); - final SecretKeySpec secretKey = new SecretKeySpec(getConfig().getApiSecret().getBytes(), "HmacSHA256"); + final SecretKeySpec secretKey = new SecretKeySpec(getApiSecret().getBytes(), "HmacSHA256"); mac.init(secretKey); final Formatter appsecretProof = new Formatter(); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java index 89edf0198..980deb102 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java @@ -2,26 +2,44 @@ import com.github.scribejava.apis.ImgurApi; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.OutputStream; public class ImgurOAuthService extends OAuth20Service { + /** + * @deprecated use {@link #ImgurOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, + * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated public ImgurOAuthService(DefaultApi20 api, OAuthConfig config) { - super(api, config); + this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); + } + + public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, + httpClient); } @Override protected OAuthRequest createAccessTokenRequest(String oauthVerifier) { final DefaultApi20 api = getApi(); final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - final OAuthConfig config = getConfig(); - request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); + request.addBodyParameter(OAuthConstants.CLIENT_ID, getApiKey()); + request.addBodyParameter(OAuthConstants.CLIENT_SECRET, getApiSecret()); - if (ImgurApi.isOob(config)) { + if (ImgurApi.isOob(getCallback())) { request.addBodyParameter(OAuthConstants.GRANT_TYPE, "pin"); request.addBodyParameter("pin", oauthVerifier); } else { @@ -33,7 +51,6 @@ protected OAuthRequest createAccessTokenRequest(String oauthVerifier) { @Override public void signRequest(String accessToken, OAuthRequest request) { - request.addHeader("Authorization", - accessToken == null ? "Client-ID " + getConfig().getApiKey() : "Bearer " + accessToken); + request.addHeader("Authorization", accessToken == null ? "Client-ID " + getApiKey() : "Bearer " + accessToken); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java index f31503098..70a96d211 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java @@ -4,9 +4,12 @@ import java.util.Map; import java.util.TreeMap; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.security.MessageDigest; @@ -15,19 +18,36 @@ public class MailruOAuthService extends OAuth20Service { + /** + * @deprecated use {@link #MailruOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, + * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated public MailruOAuthService(DefaultApi20 api, OAuthConfig config) { - super(api, config); + this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); } + public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, + httpClient); + } + + @Override public void signRequest(String accessToken, OAuthRequest request) { // sig = md5(params + secret_key) request.addQuerystringParameter("session_key", accessToken); - request.addQuerystringParameter("app_id", getConfig().getApiKey()); + request.addQuerystringParameter("app_id", getApiKey()); final String completeUrl = request.getCompleteUrl(); try { - final String clientSecret = getConfig().getApiSecret(); + final String clientSecret = getApiSecret(); final int queryIndex = completeUrl.indexOf('?'); if (queryIndex != -1) { final String urlPart = completeUrl.substring(queryIndex + 1); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java index 703257eac..afe2ad065 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java @@ -1,17 +1,36 @@ package com.github.scribejava.apis.service; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.OutputStream; public class MicrosoftAzureActiveDirectoryService extends OAuth20Service { private static final String ACCEPTED_FORMAT = "application/json; odata=minimalmetadata; streaming=true; charset=utf-8"; + /** + * @deprecated use {@link #MicrosoftAzureActiveDirectoryService(com.github.scribejava.core.builder.api.DefaultApi20, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, + * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated public MicrosoftAzureActiveDirectoryService(DefaultApi20 api, OAuthConfig config) { - super(api, config); + this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); + } + + public MicrosoftAzureActiveDirectoryService(DefaultApi20 api, String apiKey, String apiSecret, String callback, + String scope, OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, + httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java index 517d097ab..82618313f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java @@ -1,11 +1,14 @@ package com.github.scribejava.apis.service; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Parameter; import com.github.scribejava.core.model.ParameterList; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; @@ -18,15 +21,31 @@ public class OdnoklassnikiOAuthService extends OAuth20Service { + /** + * @deprecated use {@link #OdnoklassnikiOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, + * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated public OdnoklassnikiOAuthService(DefaultApi20 api, OAuthConfig config) { - super(api, config); + this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); + } + + public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, + httpClient); } @Override public void signRequest(String accessToken, OAuthRequest request) { //sig = lower(md5( sorted_request_params_composed_string + md5(access_token + application_secret_key))) try { - final String tokenDigest = md5(accessToken + getConfig().getApiSecret()); + final String tokenDigest = md5(accessToken + getApiSecret()); final ParameterList queryParams = request.getQueryStringParams(); queryParams.addAll(request.getBodyParams()); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java index ea9f8aa7b..c2d191e35 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java @@ -1,15 +1,34 @@ package com.github.scribejava.apis.service; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.OutputStream; public class TutByOAuthService extends OAuth20Service { + /** + * @deprecated use {@link #TutByOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, + * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated public TutByOAuthService(DefaultApi20 api, OAuthConfig config) { - super(api, config); + this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); + } + + public TutByOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, + httpClient); } @Override diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java index c2e003876..8102b4ea3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java @@ -3,6 +3,7 @@ import com.github.scribejava.apis.YahooApi20; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; @@ -35,7 +36,7 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .callback("oob") + .callback(OAuthConstants.OOB) .build(YahooApi20.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index 2ec6b1b22..8c70c4319 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -3,7 +3,6 @@ import com.github.scribejava.core.builder.api.BaseApi; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.core.utils.Preconditions; @@ -33,7 +32,8 @@ public ServiceBuilder(String apiKey) { /** * Adds an OAuth callback url * - * @param callback callback url. Must be a valid url or 'oob' for out of band OAuth + * @param callback callback url. Must be a valid url or 'oob' + * ({@link com.github.scribejava.core.model.OAuthConstants#OOB} for out of band OAuth * @return the {@link ServiceBuilder} instance for method chaining */ public ServiceBuilder callback(String callback) { @@ -136,7 +136,7 @@ public ServiceBuilder debug() { * @return fully configured {@link OAuthService} */ public S build(BaseApi api) { - return api.createService(new OAuthConfig(apiKey, apiSecret, callback, scope, debugStream, state, responseType, - userAgent, httpClientConfig, httpClient)); + return api.createService(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, + httpClientConfig, httpClient); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java index a42fe35fa..bac1cd7b7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java @@ -1,9 +1,22 @@ package com.github.scribejava.core.builder.api; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.oauth.OAuthService; +import java.io.OutputStream; public interface BaseApi { + /** + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated T createService(OAuthConfig config); + + T createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java index 21c7f3793..e466e2159 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java @@ -18,9 +18,7 @@ public enum ClientAuthenticationType { private final Base64.Encoder base64Encoder = Base64.getEncoder(); @Override - public void addClientAuthentication(OAuthRequest request, OAuthConfig config) { - final String apiKey = config.getApiKey(); - final String apiSecret = config.getApiSecret(); + public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) { if (apiKey != null && apiSecret != null) { request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + ' ' + base64Encoder.encodeToString( @@ -30,14 +28,22 @@ public void addClientAuthentication(OAuthRequest request, OAuthConfig config) { }, REQUEST_BODY { @Override - public void addClientAuthentication(OAuthRequest request, OAuthConfig config) { - request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); - final String apiSecret = config.getApiSecret(); + public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) { + request.addParameter(OAuthConstants.CLIENT_ID, apiKey); if (apiSecret != null) { request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); } } }; - public abstract void addClientAuthentication(OAuthRequest request, OAuthConfig config); + public abstract void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret); + + /** + * @deprecated use {@link #addClientAuthentication(com.github.scribejava.core.model.OAuthRequest, java.lang.String, + * java.lang.String)} + */ + @Deprecated + public void addClientAuthentication(OAuthRequest request, OAuthConfig config) { + addClientAuthentication(request, config.getApiKey(), config.getApiSecret()); + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index a9db2c031..aabb00028 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -14,10 +14,13 @@ import com.github.scribejava.core.services.TimestampService; import com.github.scribejava.core.services.TimestampServiceImpl; import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth1AccessToken; import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.ParameterList; +import java.io.OutputStream; /** * Default implementation of the OAuth protocol, version 1.0a @@ -141,9 +144,25 @@ public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return parameters.appendTo(getAuthorizationBaseUrl()); } + /** + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override public OAuth10aService createService(OAuthConfig config) { - return new OAuth10aService(this, config); + return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); + } + + @Override + public OAuth10aService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new OAuth10aService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, + userAgent, httpClientConfig, httpClient); } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index e0caa4637..0b916bce6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -2,12 +2,15 @@ import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.ParameterList; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.OutputStream; import java.util.Map; /** @@ -68,6 +71,16 @@ public String getRevokeTokenEndpoint() { protected abstract String getAuthorizationBaseUrl(); + /** + * @deprecated use {@link #getAuthorizationUrl(java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.lang.String, java.util.Map)} + */ + @Deprecated + public String getAuthorizationUrl(OAuthConfig config, Map additionalParams) { + return getAuthorizationUrl(config.getResponseType(), config.getApiKey(), config.getCallback(), + config.getScope(), config.getState(), additionalParams); + } + /** * Returns the URL where you should redirect your users to authenticate your application. * @@ -75,22 +88,20 @@ public String getRevokeTokenEndpoint() { * @param additionalParams any additional GET params to add to the URL * @return the URL where you should redirect your users */ - public String getAuthorizationUrl(OAuthConfig config, Map additionalParams) { + public String getAuthorizationUrl(String responseType, String apiKey, String callback, String scope, String state, + Map additionalParams) { final ParameterList parameters = new ParameterList(additionalParams); - parameters.add(OAuthConstants.RESPONSE_TYPE, config.getResponseType()); - parameters.add(OAuthConstants.CLIENT_ID, config.getApiKey()); + parameters.add(OAuthConstants.RESPONSE_TYPE, responseType); + parameters.add(OAuthConstants.CLIENT_ID, apiKey); - final String callback = config.getCallback(); if (callback != null) { parameters.add(OAuthConstants.REDIRECT_URI, callback); } - final String scope = config.getScope(); if (scope != null) { parameters.add(OAuthConstants.SCOPE, scope); } - final String state = config.getState(); if (state != null) { parameters.add(OAuthConstants.STATE, state); } @@ -98,9 +109,25 @@ public String getAuthorizationUrl(OAuthConfig config, Map additi return parameters.appendTo(getAuthorizationBaseUrl()); } + /** + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override public OAuth20Service createService(OAuthConfig config) { - return new OAuth20Service(this, config); + return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); + } + + @Override + public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new OAuth20Service(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, + httpClientConfig, httpClient); } public OAuth2SignatureType getSignatureType() { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java index 244ca6731..a31593879 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java @@ -7,7 +7,11 @@ /** * Parameter object that groups OAuth config values + * + * @deprecated use service.getXXX() instead of service.getConfigXXX() and service.method(...) instead of + * service.method(config) */ +@Deprecated public class OAuthConfig { private final String apiKey; @@ -18,9 +22,8 @@ public class OAuthConfig { private final String state; private final String responseType; private final String userAgent; - - private HttpClientConfig httpClientConfig; - private HttpClient httpClient; + private final HttpClientConfig httpClientConfig; + private final HttpClient httpClient; public OAuthConfig(String key, String secret) { this(key, secret, null, null, null, null, null, null, null, null); @@ -87,4 +90,8 @@ public HttpClientConfig getHttpClientConfig() { public HttpClient getHttpClient() { return httpClient; } + + public OutputStream getDebugStream() { + return debugStream; + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java index 93d936291..1a38cb36b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java @@ -22,6 +22,9 @@ public interface OAuthConstants { String SCOPE = "scope"; String BASIC = "Basic"; + // OAuth 1.0 + String OOB = "oob"; + // OAuth 2.0 String ACCESS_TOKEN = "access_token"; String CLIENT_ID = "client_id"; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index 09b744b2d..5d77af8a3 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -4,6 +4,8 @@ import java.util.concurrent.Future; import com.github.scribejava.core.builder.api.DefaultApi10a; import com.github.scribejava.core.builder.api.OAuth1SignatureType; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth1AccessToken; import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; @@ -11,6 +13,7 @@ import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; +import java.io.OutputStream; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -20,30 +23,41 @@ public class OAuth10aService extends OAuthService { private static final String VERSION = "1.0"; + private final OutputStream debugStream; private final DefaultApi10a api; /** - * Default constructor - * - * @param api OAuth1.0a api information - * @param config OAuth 1.0a configuration param object + * @deprecated use {@link #OAuth10aService(com.github.scribejava.core.builder.api.DefaultApi10a, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, + * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} */ + @Deprecated public OAuth10aService(DefaultApi10a api, OAuthConfig config) { - super(config); + this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); + } + + public OAuth10aService(DefaultApi10a api, String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, + httpClient); + this.debugStream = debugStream; this.api = api; } public OAuth1RequestToken getRequestToken() throws IOException, InterruptedException, ExecutionException { - final OAuthConfig config = getConfig(); - config.log("obtaining request token from " + api.getRequestTokenEndpoint()); + log("obtaining request token from " + api.getRequestTokenEndpoint()); final OAuthRequest request = prepareRequestTokenRequest(); - config.log("sending request..."); + log("sending request..."); final Response response = execute(request); final String body = response.getBody(); - config.log("response status code: " + response.getCode()); - config.log("response body: " + body); + log("response status code: " + response.getCode()); + log("response body: " + body); return api.getRequestTokenExtractor().extract(response); } @@ -52,8 +66,7 @@ public Future getRequestTokenAsync() { } public Future getRequestTokenAsync(OAuthAsyncRequestCallback callback) { - final OAuthConfig config = getConfig(); - config.log("async obtaining request token from " + api.getRequestTokenEndpoint()); + log("async obtaining request token from " + api.getRequestTokenEndpoint()); final OAuthRequest request = prepareRequestTokenRequest(); return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override @@ -65,33 +78,32 @@ public OAuth1RequestToken convert(Response response) throws IOException { protected OAuthRequest prepareRequestTokenRequest() { final OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint()); - final OAuthConfig config = getConfig(); - config.log("setting oauth_callback to " + config.getCallback()); - request.addOAuthParameter(OAuthConstants.CALLBACK, config.getCallback()); + final String callback = getCallback(); + log("setting oauth_callback to " + callback); + request.addOAuthParameter(OAuthConstants.CALLBACK, callback); addOAuthParams(request, ""); appendSignature(request); return request; } protected void addOAuthParams(OAuthRequest request, String tokenSecret) { - final OAuthConfig config = getConfig(); request.addOAuthParameter(OAuthConstants.TIMESTAMP, api.getTimestampService().getTimestampInSeconds()); request.addOAuthParameter(OAuthConstants.NONCE, api.getTimestampService().getNonce()); - request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, config.getApiKey()); + request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, getApiKey()); request.addOAuthParameter(OAuthConstants.SIGN_METHOD, api.getSignatureService().getSignatureMethod()); request.addOAuthParameter(OAuthConstants.VERSION, getVersion()); - final String scope = config.getScope(); + final String scope = getScope(); if (scope != null) { request.addOAuthParameter(OAuthConstants.SCOPE, scope); } request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, tokenSecret)); - config.log("appended additional OAuth parameters: " + request.getOauthParameters()); + log("appended additional OAuth parameters: " + request.getOauthParameters()); } public OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, String oauthVerifier) throws IOException, InterruptedException, ExecutionException { - getConfig().log("obtaining access token from " + api.getAccessTokenEndpoint()); + log("obtaining access token from " + api.getAccessTokenEndpoint()); final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier); final Response response = execute(request); return api.getAccessTokenExtractor().extract(response); @@ -112,8 +124,7 @@ public Future getAccessTokenAsync(OAuth1RequestToken requestT */ public Future getAccessTokenAsync(OAuth1RequestToken requestToken, String oauthVerifier, OAuthAsyncRequestCallback callback) { - final OAuthConfig config = getConfig(); - config.log("async obtaining access token from " + api.getAccessTokenEndpoint()); + log("async obtaining access token from " + api.getAccessTokenEndpoint()); final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier); return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override @@ -125,23 +136,21 @@ public OAuth1AccessToken convert(Response response) throws IOException { protected OAuthRequest prepareAccessTokenRequest(OAuth1RequestToken requestToken, String oauthVerifier) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - final OAuthConfig config = getConfig(); request.addOAuthParameter(OAuthConstants.TOKEN, requestToken.getToken()); request.addOAuthParameter(OAuthConstants.VERIFIER, oauthVerifier); - config.log("setting token to: " + requestToken + " and verifier to: " + oauthVerifier); + log("setting token to: " + requestToken + " and verifier to: " + oauthVerifier); addOAuthParams(request, requestToken.getTokenSecret()); appendSignature(request); return request; } public void signRequest(OAuth1AccessToken token, OAuthRequest request) { - final OAuthConfig config = getConfig(); - config.log("signing request: " + request.getCompleteUrl()); + log("signing request: " + request.getCompleteUrl()); if (!token.isEmpty() || api.isEmptyOAuthTokenParamIsRequired()) { request.addOAuthParameter(OAuthConstants.TOKEN, token.getToken()); } - config.log("setting token to: " + token); + log("setting token to: " + token); addOAuthParams(request, token.getTokenSecret()); appendSignature(request); } @@ -163,28 +172,26 @@ public String getAuthorizationUrl(OAuth1RequestToken requestToken) { } private String getSignature(OAuthRequest request, String tokenSecret) { - final OAuthConfig config = getConfig(); - config.log("generating signature..."); + log("generating signature..."); final String baseString = api.getBaseStringExtractor().extract(request); - final String signature = api.getSignatureService().getSignature(baseString, config.getApiSecret(), tokenSecret); + final String signature = api.getSignatureService().getSignature(baseString, getApiSecret(), tokenSecret); - config.log("base string is: " + baseString); - config.log("signature is: " + signature); + log("base string is: " + baseString); + log("signature is: " + signature); return signature; } protected void appendSignature(OAuthRequest request) { - final OAuthConfig config = getConfig(); final OAuth1SignatureType signatureType = api.getSignatureType(); switch (signatureType) { case Header: - config.log("using Http Header signature"); + log("using Http Header signature"); final String oauthHeader = api.getHeaderExtractor().extract(request); request.addHeader(OAuthConstants.HEADER, oauthHeader); break; case QueryString: - config.log("using Querystring signature"); + log("using Querystring signature"); for (Map.Entry oauthParameter : request.getOauthParameters().entrySet()) { request.addQuerystringParameter(oauthParameter.getKey(), oauthParameter.getValue()); @@ -198,4 +205,15 @@ protected void appendSignature(OAuthRequest request) { public DefaultApi10a getApi() { return api; } + + public void log(String message) { + if (debugStream != null) { + message += '\n'; + try { + debugStream.write(message.getBytes("UTF8")); + } catch (IOException | RuntimeException e) { + throw new RuntimeException("there were problems while writting to the debug stream", e); + } + } + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 2d78ec555..1e38793f9 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -4,6 +4,8 @@ import java.util.concurrent.Future; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2Authorization; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; @@ -19,21 +21,38 @@ import java.util.Map; import java.util.concurrent.ExecutionException; import com.github.scribejava.core.revoke.TokenTypeHint; +import java.io.OutputStream; public class OAuth20Service extends OAuthService { private static final String VERSION = "2.0"; private static final PKCEService PKCE_SERVICE = new PKCEService(); private final DefaultApi20 api; + private final String responseType; + private final String state; /** - * Default constructor - * * @param api OAuth2.0 api information * @param config OAuth 2.0 configuration param object + * @deprecated use {@link #OAuth20Service(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, + * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} */ + @Deprecated public OAuth20Service(DefaultApi20 api, OAuthConfig config) { - super(config); + this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); + } + + public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, + httpClient); + this.responseType = responseType; + this.state = state; this.api = api; } @@ -103,13 +122,12 @@ public Future getAccessToken(String code, protected OAuthRequest createAccessTokenRequest(String code) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - final OAuthConfig config = getConfig(); - api.getClientAuthenticationType().addClientAuthentication(request, config); + api.getClientAuthenticationType().addClientAuthentication(request, getApiKey(), getApiSecret()); request.addParameter(OAuthConstants.CODE, code); - request.addParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); - final String scope = config.getScope(); + request.addParameter(OAuthConstants.REDIRECT_URI, getCallback()); + final String scope = getScope(); if (scope != null) { request.addParameter(OAuthConstants.SCOPE, scope); } @@ -148,11 +166,10 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken) { throw new IllegalArgumentException("The refreshToken cannot be null or empty"); } final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint()); - final OAuthConfig config = getConfig(); - api.getClientAuthenticationType().addClientAuthentication(request, config); + api.getClientAuthenticationType().addClientAuthentication(request, getApiKey(), getApiSecret()); - final String scope = config.getScope(); + final String scope = getScope(); if (scope != null) { request.addParameter(OAuthConstants.SCOPE, scope); } @@ -190,18 +207,17 @@ public Future getAccessTokenPasswordGrantAsync(String uname, protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, String password) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - final OAuthConfig config = getConfig(); request.addParameter(OAuthConstants.USERNAME, username); request.addParameter(OAuthConstants.PASSWORD, password); - final String scope = config.getScope(); + final String scope = getScope(); if (scope != null) { request.addParameter(OAuthConstants.SCOPE, scope); } request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.PASSWORD); - api.getClientAuthenticationType().addClientAuthentication(request, config); + api.getClientAuthenticationType().addClientAuthentication(request, getApiKey(), getApiSecret()); return request; } @@ -233,11 +249,10 @@ public Future getAccessTokenClientCredentialsGrant( protected OAuthRequest createAccessTokenClientCredentialsGrantRequest() { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - final OAuthConfig config = getConfig(); - api.getClientAuthenticationType().addClientAuthentication(request, config); + api.getClientAuthenticationType().addClientAuthentication(request, getApiKey(), getApiSecret()); - final String scope = config.getScope(); + final String scope = getScope(); if (scope != null) { request.addParameter(OAuthConstants.SCOPE, scope); } @@ -301,7 +316,7 @@ public String getAuthorizationUrl(Map additionalParams, PKCE pkc params = additionalParams == null ? new HashMap() : new HashMap<>(additionalParams); params.putAll(pkce.getAuthorizationUrlParams()); } - return api.getAuthorizationUrl(getConfig(), params); + return api.getAuthorizationUrl(getResponseType(), getApiKey(), getCallback(), getScope(), getState(), params); } public DefaultApi20 getApi() { @@ -311,7 +326,7 @@ public DefaultApi20 getApi() { protected OAuthRequest createRevokeTokenRequest(String tokenToRevoke, TokenTypeHint tokenTypeHint) { final OAuthRequest request = new OAuthRequest(Verb.POST, api.getRevokeTokenEndpoint()); - api.getClientAuthenticationType().addClientAuthentication(request, getConfig()); + api.getClientAuthenticationType().addClientAuthentication(request, getApiKey(), getApiSecret()); request.addParameter("token", tokenToRevoke); if (tokenTypeHint != null) { @@ -384,4 +399,12 @@ public OAuth2Authorization extractAuthorization(String redirectLocation) { } return authorization; } + + public String getResponseType() { + return responseType; + } + + public String getState() { + return state; + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 710f1bb68..1f53f37a0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -13,25 +13,55 @@ import java.io.File; import java.io.IOException; +import java.io.OutputStream; import java.util.ServiceLoader; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; public abstract class OAuthService implements Closeable { - private final OAuthConfig config; + private final String apiKey; + private final String apiSecret; + private final String callback; + private final String scope; + private final String userAgent; private final HttpClient httpClient; - public OAuthService(OAuthConfig config) { - this.config = config; - final HttpClientConfig httpClientConfig = config.getHttpClientConfig(); - final HttpClient externalHttpClient = config.getHttpClient(); + /** + * + * @deprecated use all members directly from this class + */ + @Deprecated + private final OAuthConfig oAuthConfig; + + public OAuthService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + this.apiKey = apiKey; + this.apiSecret = apiSecret; + this.callback = callback; + this.scope = scope; + this.userAgent = userAgent; - if (httpClientConfig == null && externalHttpClient == null) { - httpClient = new JDKHttpClient(JDKHttpClientConfig.defaultConfig()); + if (httpClientConfig == null && httpClient == null) { + this.httpClient = new JDKHttpClient(JDKHttpClientConfig.defaultConfig()); } else { - httpClient = externalHttpClient == null ? getClient(httpClientConfig) : externalHttpClient; + this.httpClient = httpClient == null ? getClient(httpClientConfig) : httpClient; } + oAuthConfig = new OAuthConfig(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, + httpClientConfig, httpClient); + } + + /** + * @deprecated use {@link #OAuthService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated + public OAuthService(OAuthConfig config) { + this(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); } private static HttpClient getClient(HttpClientConfig config) { @@ -49,8 +79,28 @@ public void close() throws IOException { httpClient.close(); } + /** + * @deprecated use direct getXXX() instead of getConfig().getXXX() + */ + @Deprecated public OAuthConfig getConfig() { - return config; + return oAuthConfig; + } + + public String getApiKey() { + return apiKey; + } + + public String getApiSecret() { + return apiSecret; + } + + public String getCallback() { + return callback; + } + + public String getScope() { + return scope; } /** @@ -73,28 +123,28 @@ public Future execute(OAuthRequest request, OAuthAsyncRequestCallback final File filePayload = request.getFilePayload(); if (filePayload != null) { - return httpClient.executeAsync(config.getUserAgent(), request.getHeaders(), request.getVerb(), - request.getCompleteUrl(), filePayload, callback, converter); + return httpClient.executeAsync(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), + filePayload, callback, converter); } else if (request.getStringPayload() != null) { - return httpClient.executeAsync(config.getUserAgent(), request.getHeaders(), request.getVerb(), - request.getCompleteUrl(), request.getStringPayload(), callback, converter); + return httpClient.executeAsync(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), + request.getStringPayload(), callback, converter); } else { - return httpClient.executeAsync(config.getUserAgent(), request.getHeaders(), request.getVerb(), - request.getCompleteUrl(), request.getByteArrayPayload(), callback, converter); + return httpClient.executeAsync(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), + request.getByteArrayPayload(), callback, converter); } } public Response execute(OAuthRequest request) throws InterruptedException, ExecutionException, IOException { final File filePayload = request.getFilePayload(); if (filePayload != null) { - return httpClient.execute(config.getUserAgent(), request.getHeaders(), request.getVerb(), - request.getCompleteUrl(), filePayload); + return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), + filePayload); } else if (request.getStringPayload() != null) { - return httpClient.execute(config.getUserAgent(), request.getHeaders(), request.getVerb(), - request.getCompleteUrl(), request.getStringPayload()); + return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), + request.getStringPayload()); } else { - return httpClient.execute(config.getUserAgent(), request.getHeaders(), request.getVerb(), - request.getCompleteUrl(), request.getByteArrayPayload()); + return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), + request.getByteArrayPayload()); } } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java index 56780f80c..089071494 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java @@ -2,7 +2,6 @@ import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; @@ -45,8 +44,8 @@ public Response getResponse() { @Before public void setUp() { - oAuthService = new OAuth20Service(null, - new OAuthConfig("test", "test", null, null, null, null, null, null, null, createNewClient())); + oAuthService = new OAuth20Service(null, "test", "test", null, null, null, null, null, null, null, + createNewClient()); } @After diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java deleted file mode 100644 index b2480af45..000000000 --- a/scribejava-core/src/test/java/com/github/scribejava/core/builder/ServiceBuilderTest.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.github.scribejava.core.builder; - -import static org.junit.Assert.assertEquals; -import org.junit.Before; -import org.junit.Test; -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; -import com.github.scribejava.core.oauth.OAuth20Service; - -public class ServiceBuilderTest { - - private ServiceBuilder builder; - private ApiMock api; - - @Before - public void setUp() { - builder = new ServiceBuilder("will override api_key by another later in test"); - api = ApiMock.instance(); - } - - @Test - public void shouldReturnConfigDefaultValues() { - builder.apiKey("key").apiSecret("secret").build(api); - - final OAuthConfig config = api.getConfig(); - assertEquals(config.getApiKey(), "key"); - assertEquals(config.getApiSecret(), "secret"); - assertEquals(config.getCallback(), null); - } - - @Test - public void shouldAcceptValidCallbackUrl() { - builder.apiKey("key").apiSecret("secret").callback("http://example.com").build(api); - - final OAuthConfig config = api.getConfig(); - assertEquals(config.getApiKey(), "key"); - assertEquals(config.getApiSecret(), "secret"); - assertEquals(config.getCallback(), "http://example.com"); - } - - @Test - public void shouldAcceptNullAsCallback() { - builder.apiKey("key").apiSecret("secret").callback(null).build(api); - } - - @Test - public void shouldAcceptAnScope() { - builder.apiKey("key").apiSecret("secret").scope("rss-api").build(api); - - final OAuthConfig config = api.getConfig(); - assertEquals(config.getApiKey(), "key"); - assertEquals(config.getApiSecret(), "secret"); - assertEquals(config.getScope(), "rss-api"); - } - - private static class ApiMock extends DefaultApi20 { - - private OAuthConfig config; - - private static ApiMock instance() { - return new ApiMock(); - } - - private OAuthConfig getConfig() { - return config; - } - - @Override - public OAuth20Service createService(OAuthConfig config) { - this.config = config; - return null; - } - - @Override - public String getAccessTokenEndpoint() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - protected String getAuthorizationBaseUrl() { - throw new UnsupportedOperationException("Not supported yet."); - } - } -} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java index c6c05e05c..5518d9b22 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java @@ -2,7 +2,10 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.builder.api.OAuth2SignatureType; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConfig; +import java.io.OutputStream; class OAuth20ApiUnit extends DefaultApi20 { @@ -16,9 +19,25 @@ protected String getAuthorizationBaseUrl() { return "http://localhost:8080/authorize"; } + @Override + public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new OAuth20ServiceUnit(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, + userAgent, httpClientConfig, httpClient); + } + + /** + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override public OAuth20Service createService(OAuthConfig config) { - return new OAuth20ServiceUnit(this, config); + return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), + config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), + config.getHttpClientConfig(), config.getHttpClient()); } @Override diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java index b7a0febd0..c74e0ea57 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java @@ -38,8 +38,7 @@ public void shouldProduceCorrectRequestSync() throws IOException, InterruptedExc assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); final String authorize = base64Encoder.encodeToString( - String.format("%s:%s", service.getConfig().getApiKey(), service.getConfig().getApiSecret()) - .getBytes(Charset.forName("UTF-8"))); + String.format("%s:%s", service.getApiKey(), service.getApiSecret()).getBytes(Charset.forName("UTF-8"))); assertEquals(OAuthConstants.BASIC + " " + authorize, map.get(OAuthConstants.HEADER)); @@ -66,8 +65,7 @@ public void shouldProduceCorrectRequestAsync() throws ExecutionException, Interr assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); final String authorize = base64Encoder.encodeToString( - String.format("%s:%s", service.getConfig().getApiKey(), service.getConfig().getApiSecret()) - .getBytes(Charset.forName("UTF-8"))); + String.format("%s:%s", service.getApiKey(), service.getApiSecret()).getBytes(Charset.forName("UTF-8"))); assertEquals(OAuthConstants.BASIC + " " + authorize, map.get(OAuthConstants.HEADER)); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index 7a7db4555..4b81912ae 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -1,13 +1,15 @@ package com.github.scribejava.core.oauth; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Parameter; import com.google.gson.Gson; +import java.io.OutputStream; import java.util.HashMap; import java.util.Map; @@ -19,8 +21,11 @@ class OAuth20ServiceUnit extends OAuth20Service { static final String STATE = "123"; static final String EXPIRES = "3600"; - OAuth20ServiceUnit(DefaultApi20 api, OAuthConfig config) { - super(api, config); + OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, + httpClient); } @Override From 03dd1eafd8bc9bb3861e0195f93d72b93ab272c8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 18 Apr 2018 13:55:23 +0300 Subject: [PATCH 074/481] OAuth1.0: send "oob" instead of null callback while requesting RequestToken (thanks to https://github.com/Rafaelsk) --- changelog | 1 + .../com/github/scribejava/core/oauth/OAuth10aService.java | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/changelog b/changelog index 21b5817a4..c5f2ef4ba 100644 --- a/changelog +++ b/changelog @@ -4,6 +4,7 @@ * add new API - Automatic (https://www.automatic.com/) (thanks to https://github.com/ramsrib) * add new API - Fitbit (https://www.fitbit.com/) (thanks to https://github.com/JustinLawler and https://github.com/alexthered) * deprecate OAuthConfig + * OAuth1.0: send "oob" instead of null callback while requesting RequestToken (thanks to https://github.com/Rafaelsk) [5.3.0] * fix Salesforce API (thanks to https://github.com/jhorowitz-firedrum) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index 5d77af8a3..c016e5e51 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -78,7 +78,10 @@ public OAuth1RequestToken convert(Response response) throws IOException { protected OAuthRequest prepareRequestTokenRequest() { final OAuthRequest request = new OAuthRequest(api.getRequestTokenVerb(), api.getRequestTokenEndpoint()); - final String callback = getCallback(); + String callback = getCallback(); + if (callback == null) { + callback = OAuthConstants.OOB; + } log("setting oauth_callback to " + callback); request.addOAuthParameter(OAuthConstants.CALLBACK, callback); addOAuthParams(request, ""); From 22bf184b5ae690603dbb027333a41904398d3e8f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 18 Apr 2018 14:11:05 +0300 Subject: [PATCH 075/481] small fixes, update deps --- pom.xml | 2 +- .../com/github/scribejava/core/builder/api/DefaultApi20.java | 1 - .../java/com/github/scribejava/core/model/OAuthConstants.java | 4 ++++ scribejava-httpclient-ahc/pom.xml | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 95d3f3d46..2cd298645 100644 --- a/pom.xml +++ b/pom.xml @@ -95,7 +95,7 @@ org.apache.maven.plugins maven-jar-plugin - 3.0.2 + 3.1.0 ${project.build.outputDirectory}/META-INF/MANIFEST.MF diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 0b916bce6..799e92f31 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -84,7 +84,6 @@ public String getAuthorizationUrl(OAuthConfig config, Map additi /** * Returns the URL where you should redirect your users to authenticate your application. * - * @param config OAuth 2.0 configuration param object * @param additionalParams any additional GET params to add to the URL * @return the URL where you should redirect your users */ diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java index 1a38cb36b..268e5f435 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConstants.java @@ -23,6 +23,10 @@ public interface OAuthConstants { String BASIC = "Basic"; // OAuth 1.0 + /** + * to indicate an out-of-band configuration + * @see The OAuth 1.0 Protocol + */ String OOB = "oob"; // OAuth 2.0 diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 49ac5ad69..aa7b5ac51 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.4.3 + 2.4.5 com.github.scribejava From 23e4ed3083d5f2e6fb1a8deb8716ec6eb78f0419 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 18 Apr 2018 14:23:00 +0300 Subject: [PATCH 076/481] prepare release 5.4.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 07f185d5d..7227ce97d 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 5.3.0 + 5.4.0 ``` @@ -120,7 +120,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 5.3.0 + 5.4.0 ``` diff --git a/changelog b/changelog index c5f2ef4ba..cc865a4ed 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[5.4.0] * fix missing support for scope for refresh_token grant_type (thanks to https://github.com/tlxtellef) * add email field to VKOAuth2AccessToken (thanks to https://github.com/grouzen) * add new API - Automatic (https://www.automatic.com/) (thanks to https://github.com/ramsrib) From da982dd5409304e8ba4e6906e97955a6bdb8ba12 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 18 Apr 2018 14:24:27 +0300 Subject: [PATCH 077/481] [maven-release-plugin] prepare release scribejava-5.4.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 2cd298645..866c4c536 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.3.1-SNAPSHOT + 5.4.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-5.4.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index f6e826693..91f3bacc2 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.1-SNAPSHOT + 5.4.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index d9ddaeb76..f9b5b7a9d 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.1-SNAPSHOT + 5.4.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index aa7b5ac51..df457ec85 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.1-SNAPSHOT + 5.4.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 0bd9b04ec..6ef02c328 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.1-SNAPSHOT + 5.4.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 7b5e1b0e4..fedcb5065 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.1-SNAPSHOT + 5.4.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 674113b2f..2e726b426 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.3.1-SNAPSHOT + 5.4.0 ../pom.xml From 4b46ba4043fa6c09af2a3e70b2828cf13deca29c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 18 Apr 2018 14:24:42 +0300 Subject: [PATCH 078/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 866c4c536..e2b89b530 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.4.0 + 5.4.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-5.4.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 91f3bacc2..da6150e43 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.0 + 5.4.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index f9b5b7a9d..60e6da8cf 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.0 + 5.4.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index df457ec85..418fbccfa 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.0 + 5.4.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 6ef02c328..2a3eedc01 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.0 + 5.4.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index fedcb5065..0b13d47a1 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.0 + 5.4.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 2e726b426..e135a6e93 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.0 + 5.4.1-SNAPSHOT ../pom.xml From 47c073250bb3227fd666be0f523e4c6d08c86f8a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 18 Apr 2018 14:55:19 +0300 Subject: [PATCH 079/481] drop OAuthConfig, remove deprecate usaged --- .../github/scribejava/apis/FacebookApi.java | 18 +--- .../com/github/scribejava/apis/ImgurApi.java | 18 +--- .../com/github/scribejava/apis/MailruApi.java | 18 +--- .../MicrosoftAzureActiveDirectoryApi.java | 18 +--- .../scribejava/apis/OdnoklassnikiApi.java | 18 +--- .../com/github/scribejava/apis/TutByApi.java | 18 +--- .../apis/service/FacebookService.java | 21 ++-- .../apis/service/ImgurOAuthService.java | 21 ++-- .../apis/service/MailruOAuthService.java | 21 ++-- .../MicrosoftAzureActiveDirectoryService.java | 20 ++-- .../service/OdnoklassnikiOAuthService.java | 20 ++-- .../apis/service/TutByOAuthService.java | 21 ++-- .../scribejava/core/builder/api/BaseApi.java | 9 -- .../builder/api/ClientAuthenticationType.java | 10 -- .../core/builder/api/DefaultApi10a.java | 18 +--- .../core/builder/api/DefaultApi20.java | 26 +---- .../scribejava/core/model/OAuthConfig.java | 97 ------------------- .../core/oauth/OAuth10aService.java | 20 ++-- .../scribejava/core/oauth/OAuth20Service.java | 23 ++--- .../scribejava/core/oauth/OAuthService.java | 35 ++----- .../scribejava/core/AbstractClientTest.java | 2 +- .../scribejava/core/oauth/OAuth20ApiUnit.java | 18 +--- .../core/oauth/OAuth20ServiceUnit.java | 9 +- 23 files changed, 100 insertions(+), 399 deletions(-) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index a2114760b..463a44d6c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; import java.io.OutputStream; @@ -74,20 +73,7 @@ public ClientAuthenticationType getClientAuthenticationType() { public FacebookService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new FacebookService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, - userAgent, httpClientConfig, httpClient); - } - - /** - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public FacebookService createService(OAuthConfig config) { - return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); + return new FacebookService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, + httpClientConfig, httpClient); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index 720b62fd2..b8c802647 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -4,7 +4,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.ParameterList; import java.io.OutputStream; @@ -59,21 +58,8 @@ protected String getAuthorizationBaseUrl() { public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new ImgurOAuthService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, - userAgent, httpClientConfig, httpClient); - } - - /** - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public ImgurOAuthService createService(OAuthConfig config) { - return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); + return new ImgurOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, + httpClientConfig, httpClient); } public static boolean isOob(String callback) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index 318ab2bf2..05ae5cb8a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -1,7 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.apis.service.MailruOAuthService; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; @@ -34,20 +33,7 @@ protected String getAuthorizationBaseUrl() { public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new MailruOAuthService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, - userAgent, httpClientConfig, httpClient); - } - - /** - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public MailruOAuthService createService(OAuthConfig config) { - return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); + return new MailruOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, + httpClientConfig, httpClient); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java index c2059d55b..223a88b1c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java @@ -5,7 +5,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import java.io.OutputStream; /** @@ -53,21 +52,8 @@ protected String getAuthorizationBaseUrl() { public MicrosoftAzureActiveDirectoryService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new MicrosoftAzureActiveDirectoryService(this, apiKey, apiSecret, callback, scope, debugStream, state, - responseType, userAgent, httpClientConfig, httpClient); - } - - /** - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public MicrosoftAzureActiveDirectoryService createService(OAuthConfig config) { - return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); + return new MicrosoftAzureActiveDirectoryService(this, apiKey, apiSecret, callback, scope, state, responseType, + userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index a65f9b692..c21983fa3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import java.io.OutputStream; public class OdnoklassnikiApi extends DefaultApi20 { @@ -36,21 +35,8 @@ protected String getAuthorizationBaseUrl() { public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OdnoklassnikiOAuthService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, - userAgent, httpClientConfig, httpClient); - } - - /** - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public OdnoklassnikiOAuthService createService(OAuthConfig config) { - return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); + return new OdnoklassnikiOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, + httpClientConfig, httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java index a6b864fb7..377bc9046 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java @@ -4,7 +4,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import java.io.OutputStream; public class TutByApi extends DefaultApi20 { @@ -34,20 +33,7 @@ protected String getAuthorizationBaseUrl() { public TutByOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new TutByOAuthService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, - userAgent, httpClientConfig, httpClient); - } - - /** - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public TutByOAuthService createService(OAuthConfig config) { - return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); + return new TutByOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, + httpClientConfig, httpClient); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java index 925d20f15..565514efe 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java @@ -3,7 +3,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.OutputStream; @@ -17,22 +16,20 @@ public class FacebookService extends OAuth20Service { /** * @deprecated use {@link #FacebookService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, - * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} */ @Deprecated - public FacebookService(DefaultApi20 api, OAuthConfig config) { - this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); - } - public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, - httpClient); + this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java index 980deb102..c5bfb43f6 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java @@ -4,7 +4,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; @@ -14,22 +13,20 @@ public class ImgurOAuthService extends OAuth20Service { /** * @deprecated use {@link #ImgurOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, - * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} */ @Deprecated - public ImgurOAuthService(DefaultApi20 api, OAuthConfig config) { - this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); - } - public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, - httpClient); + this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java index 70a96d211..aadfc58b5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.OutputStream; @@ -20,22 +19,20 @@ public class MailruOAuthService extends OAuth20Service { /** * @deprecated use {@link #MailruOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, - * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} */ @Deprecated - public MailruOAuthService(DefaultApi20 api, OAuthConfig config) { - this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); - } - public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, - httpClient); + this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java index afe2ad065..59fc2f00b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java @@ -3,7 +3,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.OutputStream; @@ -15,22 +14,21 @@ public class MicrosoftAzureActiveDirectoryService extends OAuth20Service { /** * @deprecated use {@link #MicrosoftAzureActiveDirectoryService(com.github.scribejava.core.builder.api.DefaultApi20, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, - * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, * com.github.scribejava.core.httpclient.HttpClient)} */ @Deprecated - public MicrosoftAzureActiveDirectoryService(DefaultApi20 api, OAuthConfig config) { - this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); - } - public MicrosoftAzureActiveDirectoryService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, - httpClient); + this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + public MicrosoftAzureActiveDirectoryService(DefaultApi20 api, String apiKey, String apiSecret, String callback, + String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java index 82618313f..b2aa5cbda 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java @@ -3,7 +3,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Parameter; import com.github.scribejava.core.model.ParameterList; @@ -23,22 +22,21 @@ public class OdnoklassnikiOAuthService extends OAuth20Service { /** * @deprecated use {@link #OdnoklassnikiOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, - * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, * com.github.scribejava.core.httpclient.HttpClient)} */ @Deprecated - public OdnoklassnikiOAuthService(DefaultApi20 api, OAuthConfig config) { - this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); - } - public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, - httpClient); + this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java index c2d191e35..17e64e7b5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java @@ -3,7 +3,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; @@ -13,22 +12,20 @@ public class TutByOAuthService extends OAuth20Service { /** * @deprecated use {@link #TutByOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, - * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} */ @Deprecated - public TutByOAuthService(DefaultApi20 api, OAuthConfig config) { - this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); - } - public TutByOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, - httpClient); + this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + public TutByOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java index bac1cd7b7..bce6192dc 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java @@ -2,20 +2,11 @@ import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.oauth.OAuthService; import java.io.OutputStream; public interface BaseApi { - /** - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - T createService(OAuthConfig config); - T createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java index e466e2159..77212ce95 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java @@ -1,7 +1,6 @@ package com.github.scribejava.core.builder.api; import com.github.scribejava.core.java8.Base64; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import java.nio.charset.Charset; @@ -37,13 +36,4 @@ public void addClientAuthentication(OAuthRequest request, String apiKey, String }; public abstract void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret); - - /** - * @deprecated use {@link #addClientAuthentication(com.github.scribejava.core.model.OAuthRequest, java.lang.String, - * java.lang.String)} - */ - @Deprecated - public void addClientAuthentication(OAuthRequest request, OAuthConfig config) { - addClientAuthentication(request, config.getApiKey(), config.getApiSecret()); - } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index aabb00028..67bbd181e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.extractors.HeaderExtractorImpl; import com.github.scribejava.core.extractors.OAuth1AccessTokenExtractor; import com.github.scribejava.core.extractors.OAuth1RequestTokenExtractor; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import com.github.scribejava.core.services.HMACSha1SignatureService; @@ -144,25 +143,12 @@ public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return parameters.appendTo(getAuthorizationBaseUrl()); } - /** - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public OAuth10aService createService(OAuthConfig config) { - return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); - } - @Override public OAuth10aService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OAuth10aService(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, - userAgent, httpClientConfig, httpClient); + return new OAuth10aService(this, apiKey, apiSecret, callback, scope, debugStream, userAgent, httpClientConfig, + httpClient); } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 799e92f31..5555faac3 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -5,7 +5,6 @@ import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.ParameterList; import com.github.scribejava.core.model.Verb; @@ -71,16 +70,6 @@ public String getRevokeTokenEndpoint() { protected abstract String getAuthorizationBaseUrl(); - /** - * @deprecated use {@link #getAuthorizationUrl(java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.lang.String, java.util.Map)} - */ - @Deprecated - public String getAuthorizationUrl(OAuthConfig config, Map additionalParams) { - return getAuthorizationUrl(config.getResponseType(), config.getApiKey(), config.getCallback(), - config.getScope(), config.getState(), additionalParams); - } - /** * Returns the URL where you should redirect your users to authenticate your application. * @@ -108,24 +97,11 @@ public String getAuthorizationUrl(String responseType, String apiKey, String cal return parameters.appendTo(getAuthorizationBaseUrl()); } - /** - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public OAuth20Service createService(OAuthConfig config) { - return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); - } - @Override public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OAuth20Service(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, + return new OAuth20Service(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java deleted file mode 100644 index a31593879..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthConfig.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.github.scribejava.core.model; - -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; -import java.io.IOException; -import java.io.OutputStream; - -/** - * Parameter object that groups OAuth config values - * - * @deprecated use service.getXXX() instead of service.getConfigXXX() and service.method(...) instead of - * service.method(config) - */ -@Deprecated -public class OAuthConfig { - - private final String apiKey; - private final String apiSecret; - private final String callback; - private final String scope; - private final OutputStream debugStream; - private final String state; - private final String responseType; - private final String userAgent; - private final HttpClientConfig httpClientConfig; - private final HttpClient httpClient; - - public OAuthConfig(String key, String secret) { - this(key, secret, null, null, null, null, null, null, null, null); - } - - public OAuthConfig(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - this.apiKey = apiKey; - this.apiSecret = apiSecret; - this.callback = callback; - this.scope = scope; - this.debugStream = debugStream; - this.state = state; - this.responseType = responseType; - this.userAgent = userAgent; - this.httpClientConfig = httpClientConfig; - this.httpClient = httpClient; - } - - public String getApiKey() { - return apiKey; - } - - public String getApiSecret() { - return apiSecret; - } - - public String getCallback() { - return callback; - } - - public String getScope() { - return scope; - } - - public String getState() { - return state; - } - - public String getResponseType() { - return responseType; - } - - public String getUserAgent() { - return userAgent; - } - - public void log(String message) { - if (debugStream != null) { - message += '\n'; - try { - debugStream.write(message.getBytes("UTF8")); - } catch (IOException | RuntimeException e) { - throw new RuntimeException("there were problems while writting to the debug stream", e); - } - } - } - - public HttpClientConfig getHttpClientConfig() { - return httpClientConfig; - } - - public HttpClient getHttpClient() { - return httpClient; - } - - public OutputStream getDebugStream() { - return debugStream; - } -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index c016e5e51..bf708395e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -9,7 +9,6 @@ import com.github.scribejava.core.model.OAuth1AccessToken; import com.github.scribejava.core.model.OAuth1RequestToken; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; @@ -28,22 +27,19 @@ public class OAuth10aService extends OAuthService { /** * @deprecated use {@link #OAuth10aService(com.github.scribejava.core.builder.api.DefaultApi10a, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, - * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} + * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} */ @Deprecated - public OAuth10aService(DefaultApi10a api, OAuthConfig config) { - this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); - } - public OAuth10aService(DefaultApi10a api, String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, - httpClient); + this(api, apiKey, apiSecret, callback, scope, debugStream, userAgent, httpClientConfig, httpClient); + } + + public OAuth10aService(DefaultApi10a api, String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(apiKey, apiSecret, callback, scope, userAgent, httpClientConfig, httpClient); this.debugStream = debugStream; this.api = api; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 1e38793f9..29df7e94e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -9,7 +9,6 @@ import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2Authorization; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; @@ -32,25 +31,21 @@ public class OAuth20Service extends OAuthService { private final String state; /** - * @param api OAuth2.0 api information - * @param config OAuth 2.0 configuration param object * @deprecated use {@link #OAuth20Service(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, java.lang.String, - * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} */ @Deprecated - public OAuth20Service(DefaultApi20 api, OAuthConfig config) { - this(api, config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); - } - public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, - httpClient); + this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(apiKey, apiSecret, callback, scope, userAgent, httpClientConfig, httpClient); this.responseType = responseType; this.state = state; this.api = api; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 1f53f37a0..60c2d39aa 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.httpclient.jdk.JDKHttpClient; import com.github.scribejava.core.httpclient.jdk.JDKHttpClientConfig; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; -import com.github.scribejava.core.model.OAuthConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import java.io.Closeable; @@ -27,16 +26,8 @@ public abstract class OAuthService implements Closeable { private final String userAgent; private final HttpClient httpClient; - /** - * - * @deprecated use all members directly from this class - */ - @Deprecated - private final OAuthConfig oAuthConfig; - - public OAuthService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { + public OAuthService(String apiKey, String apiSecret, String callback, String scope, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { this.apiKey = apiKey; this.apiSecret = apiSecret; this.callback = callback; @@ -48,20 +39,18 @@ public OAuthService(String apiKey, String apiSecret, String callback, String sco } else { this.httpClient = httpClient == null ? getClient(httpClientConfig) : httpClient; } - oAuthConfig = new OAuthConfig(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, - httpClientConfig, httpClient); } /** * @deprecated use {@link #OAuthService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} */ @Deprecated - public OAuthService(OAuthConfig config) { - this(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); + public OAuthService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + this(apiKey, apiSecret, callback, scope, userAgent, httpClientConfig, httpClient); } private static HttpClient getClient(HttpClientConfig config) { @@ -79,14 +68,6 @@ public void close() throws IOException { httpClient.close(); } - /** - * @deprecated use direct getXXX() instead of getConfig().getXXX() - */ - @Deprecated - public OAuthConfig getConfig() { - return oAuthConfig; - } - public String getApiKey() { return apiKey; } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java index 089071494..58c4664de 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java @@ -44,7 +44,7 @@ public Response getResponse() { @Before public void setUp() { - oAuthService = new OAuth20Service(null, "test", "test", null, null, null, null, null, null, null, + oAuthService = new OAuth20Service(null, "test", "test", null, null, null, null, null, null, createNewClient()); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java index 5518d9b22..a3187957e 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java @@ -4,7 +4,6 @@ import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConfig; import java.io.OutputStream; class OAuth20ApiUnit extends DefaultApi20 { @@ -23,21 +22,8 @@ protected String getAuthorizationBaseUrl() { public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OAuth20ServiceUnit(this, apiKey, apiSecret, callback, scope, debugStream, state, responseType, - userAgent, httpClientConfig, httpClient); - } - - /** - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public OAuth20Service createService(OAuthConfig config) { - return createService(config.getApiKey(), config.getApiSecret(), config.getCallback(), config.getScope(), - config.getDebugStream(), config.getState(), config.getResponseType(), config.getUserAgent(), - config.getHttpClientConfig(), config.getHttpClient()); + return new OAuth20ServiceUnit(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, + httpClientConfig, httpClient); } @Override diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index 4b81912ae..a5cbf9763 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -9,7 +9,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Parameter; import com.google.gson.Gson; -import java.io.OutputStream; import java.util.HashMap; import java.util.Map; @@ -21,11 +20,9 @@ class OAuth20ServiceUnit extends OAuth20Service { static final String STATE = "123"; static final String EXPIRES = "3600"; - OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, httpClientConfig, - httpClient); + OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } @Override From 16de05a34c1c9bf63bbb48f8f2ddfbf1de0422f7 Mon Sep 17 00:00:00 2001 From: eos1d3 Date: Sun, 29 Apr 2018 05:48:53 +0800 Subject: [PATCH 080/481] Add multipart form-data request to JDK Http Client Changes to be committed: modified: scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java modified: scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java modified: scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java modified: scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java modified: scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java modified: scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java --- .../AbstractAsyncOnlyHttpClient.java | 6 + .../core/httpclient/HttpClient.java | 3 + .../core/httpclient/jdk/JDKHttpClient.java | 43 ++++++- .../scribejava/core/model/OAuthRequest.java | 110 +++++++++++++++++- .../scribejava/core/oauth/OAuthService.java | 6 +- .../httpclient/okhttp/OkHttpHttpClient.java | 11 +- 6 files changed, 171 insertions(+), 8 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java index 091a95849..b8d6dead9 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java @@ -30,4 +30,10 @@ public Response execute(String userAgent, Map headers, Verb http return executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, null, (OAuthRequest.ResponseConverter) null).get(); } + + @Override + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + OAuthRequest.MultipartPayloads multipartPayloads) throws InterruptedException, ExecutionException, IOException { + throw new UnsupportedOperationException("This HttpClient does not support Multipart payload for the moment"); + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java index a3bc0b5c5..41c5df134 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java @@ -27,6 +27,9 @@ Future executeAsync(String userAgent, Map headers, Verb h Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents) throws InterruptedException, ExecutionException, IOException; + + Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + OAuthRequest.MultipartPayloads multipartPayloads) throws InterruptedException, ExecutionException, IOException; Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents) throws InterruptedException, ExecutionException, IOException; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 6e970bb07..3b4245671 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -9,6 +9,7 @@ import com.github.scribejava.core.model.Verb; import java.io.File; import java.io.IOException; +import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.UnknownHostException; @@ -73,7 +74,7 @@ public Future executeAsync(String userAgent, Map headers, @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - throw new UnsupportedOperationException("JDKHttpClient do not support File payload for the moment"); + throw new UnsupportedOperationException("JDKHttpClient does not support File payload for the moment"); } @Override @@ -94,6 +95,12 @@ public Response execute(String userAgent, Map headers, Verb http throw new UnsupportedOperationException("JDKHttpClient do not support File payload for the moment"); } + @Override + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + OAuthRequest.MultipartPayloads multipartPayloads) throws InterruptedException, ExecutionException, IOException { + return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.MULTIPART, multipartPayloads); + } + private Response doExecute(String userAgent, Map headers, Verb httpVerb, String completeUrl, BodyType bodyType, Object bodyContents) throws IOException { final HttpURLConnection connection = (HttpURLConnection) new URL(completeUrl).openConnection(); @@ -128,6 +135,12 @@ void setBody(HttpURLConnection connection, Object bodyContents, boolean requires addBody(connection, (byte[]) bodyContents, requiresBody); } }, + MULTIPART { + @Override + void setBody(HttpURLConnection connection, Object bodyContents, boolean requiresBody) throws IOException { + addBody(connection, (OAuthRequest.MultipartPayloads) bodyContents, requiresBody); + } + }, STRING { @Override void setBody(HttpURLConnection connection, Object bodyContents, boolean requiresBody) throws IOException { @@ -137,6 +150,7 @@ void setBody(HttpURLConnection connection, Object bodyContents, boolean requires abstract void setBody(HttpURLConnection connection, Object bodyContents, boolean requiresBody) throws IOException; + } private static Map parseHeaders(HttpURLConnection conn) { @@ -164,11 +178,35 @@ private static void addHeaders(HttpURLConnection connection, Map } } + /* + * Multipart implementation supporting more than one payload + * + */ + private static void addBody(HttpURLConnection connection, OAuthRequest.MultipartPayloads multipartPayloads, boolean requiresBody) throws IOException { + int contentLength = multipartPayloads.getContentLength(); + System.out.println("length: " + contentLength); + if (requiresBody || contentLength > 0) { + connection.setRequestProperty(CONTENT_LENGTH, String.valueOf(contentLength)); + if (connection.getRequestProperty(CONTENT_TYPE) == null) { + connection.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + } + System.out.println("content-length: " + connection.getRequestProperty(CONTENT_TYPE)); + connection.setDoOutput(true); + OutputStream os = connection.getOutputStream(); + + int totalParts = multipartPayloads.getMultipartPayloadList().size(); + for (int i = 0; i < totalParts; i++) { + os.write(multipartPayloads.getStartBoundary(i)); + os.write(multipartPayloads.getMultipartPayloadList().get(i).getPayload(), 0, multipartPayloads.getMultipartPayloadList().get(i).getLength()); + os.write(multipartPayloads.getEndBoundary(i)); + } + } + } + private static void addBody(HttpURLConnection connection, byte[] content, boolean requiresBody) throws IOException { final int contentLength = content.length; if (requiresBody || contentLength > 0) { connection.setRequestProperty(CONTENT_LENGTH, String.valueOf(contentLength)); - if (connection.getRequestProperty(CONTENT_TYPE) == null) { connection.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } @@ -176,4 +214,5 @@ private static void addBody(HttpURLConnection connection, byte[] content, boolea connection.getOutputStream().write(content); } } + } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index 3f50440eb..39b3dd73f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -7,15 +7,79 @@ import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.Charset; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; + /** * The representation of an OAuth HttpRequest. */ public class OAuthRequest { - - private static final String OAUTH_PREFIX = "oauth_"; + /* + * The class containing more than one payload of multipart/form-data request + */ + public class MultipartPayloads { + private String boundary; + private int contentLength; + private List multipartPayloadList; + + public MultipartPayloads(String boundary) { + this.boundary = boundary; + this.multipartPayloadList = new ArrayList<>(); + } + + public byte[] getStartBoundary(int index) { + MultipartPayload multipartPaayLoad = multipartPayloadList.get(index); + byte[] bytes = ("--" + boundary +"\r\n" + + "Content-Disposition: " + multipartPaayLoad.contentDisposition + "\r\n" + + (multipartPaayLoad == null ? "" : "Content-Type: " + multipartPaayLoad.contentType + "\r\n") + + "\r\n").getBytes(); + return bytes; + } + + public byte[] getEndBoundary(int index) { + return ("\r\n" + + "--" + boundary + "--\r\n").getBytes(); + } + + public int getContentLength() { + return contentLength; + } + + public void addContentLength(int length) { + this.contentLength += length; + } + + public List getMultipartPayloadList() { + return multipartPayloadList; + } + } + + public class MultipartPayload { + private String contentDisposition; + private String contentType; + private byte[] payload; + private int length; + + public MultipartPayload(String contentDisposition, String contentType, byte[] payload, int length) { + this.contentDisposition = contentDisposition; + this.contentType = contentType; + this.payload = payload; + this.length = length; + } + + public byte[] getPayload() { + return payload; + } + + public int getLength() { + return length; + } + } + + private static final String OAUTH_PREFIX = "oauth_"; private final String url; private final Verb verb; @@ -28,6 +92,7 @@ public class OAuthRequest { private String stringPayload; private byte[] byteArrayPayload; private File filePayload; + private MultipartPayloads multipartPayloads; private final Map oauthParameters = new HashMap<>(); @@ -123,7 +188,43 @@ public void addParameter(String key, String value) { querystringParams.add(key, value); } } + + /* + * Set boundary of multipart request + * + * @param boundary can be any string + */ + public void setMultipartBoundary(String boundary) { + multipartPayloads = new MultipartPayloads(boundary); + } + + + /* + * Add one multipart form-data payload to the request & increase the current Content-Length + * + * @param contentDisposition value of Content-Disposition header + * @param contentType value of Content-Type header + * @param payload data array containing the data to send + * @param length the max no of bytes to send + * + * Remarks: + * 57 and 37 are the length of constant portions of contentDisposition and/or contentType headers + * refer getStartBoundary and getEndBoundary for the constant + * + * Must be called after setMultipartBoundary method + */ + public void addMultipartPayload(String contentDisposition, String contentType, byte[] payload, int length) { + int contentLenght; + if (contentType == null) + contentLenght = 37 + multipartPayloads.boundary.length() * 2 + contentDisposition.length() + payload.length; + else + contentLenght = 53 + multipartPayloads.boundary.length() * 2 + contentDisposition.length() + + contentType.length() + payload.length; + multipartPayloads.addContentLength(contentLenght); + + multipartPayloads.getMultipartPayloadList().add(new MultipartPayload(contentDisposition, contentType, payload, length)); + } + /** * Set body payload. This method is used when the HTTP body is not a form-url-encoded string, but another thing. * Like for example XML. Note: The contents are not part of the OAuth signature @@ -159,6 +260,7 @@ private void resetPayload() { stringPayload = null; byteArrayPayload = null; filePayload = null; + multipartPayloads = null; } /** @@ -237,6 +339,10 @@ public byte[] getByteArrayPayload() { } } + public MultipartPayloads getMultipartPayloads() { + return multipartPayloads; + } + public File getFilePayload() { return filePayload; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 60c2d39aa..8b92e51dc 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -123,7 +123,11 @@ public Response execute(OAuthRequest request) throws InterruptedException, Execu } else if (request.getStringPayload() != null) { return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), request.getStringPayload()); - } else { + } else if (request.getMultipartPayloads() != null) { + return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), + request.getMultipartPayloads()); + } + else { return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), request.getByteArrayPayload()); } diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 123c943ba..2582eab17 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -4,6 +4,7 @@ import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.OAuthRequest.MultipartPayloads; import com.github.scribejava.core.model.Verb; import okhttp3.Call; import okhttp3.MediaType; @@ -11,11 +12,9 @@ import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.internal.http.HttpMethod; - import java.io.IOException; import java.util.Map; import java.util.concurrent.Future; - import com.github.scribejava.core.model.Response; import java.io.File; import java.util.HashMap; @@ -101,6 +100,12 @@ public Response execute(String userAgent, Map headers, Verb http return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.FILE, bodyContents); } + @Override + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + MultipartPayloads multipartPayloads) throws InterruptedException, ExecutionException, IOException { + throw new UnsupportedOperationException("OKHttpClient does not support Multipart payload for the moment"); + } + private Response doExecute(String userAgent, Map headers, Verb httpVerb, String completeUrl, BodyType bodyType, Object bodyContents) throws IOException { final Call call = createCall(userAgent, headers, httpVerb, completeUrl, bodyType, bodyContents); @@ -174,6 +179,6 @@ static Response convertResponse(okhttp3.Response okHttpResponse) { final ResponseBody body = okHttpResponse.body(); return new Response(okHttpResponse.code(), okHttpResponse.message(), headersMap, body == null ? null : body.byteStream()); - } + } From a8b06d1d81e68dbd6cfbeaa43f605f7ae253ce92 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 18 May 2018 18:32:47 +0300 Subject: [PATCH 081/481] small changes --- .../com/github/scribejava/apis/examples/AWeberExample.java | 2 +- .../com/github/scribejava/apis/examples/AutomaticExample.java | 2 +- .../com/github/scribejava/apis/examples/Box20Example.java | 2 +- .../github/scribejava/apis/examples/DataportenExample.java | 2 +- .../java/com/github/scribejava/apis/examples/DiggExample.java | 2 +- .../java/com/github/scribejava/apis/examples/EtsyExample.java | 2 +- .../scribejava/apis/examples/FacebookAsyncApacheExample.java | 2 +- .../scribejava/apis/examples/FacebookAsyncNingExample.java | 2 +- .../com/github/scribejava/apis/examples/FacebookExample.java | 2 +- .../com/github/scribejava/apis/examples/FlickrExample.java | 2 +- .../github/scribejava/apis/examples/Foursquare2Example.java | 2 +- .../github/scribejava/apis/examples/FoursquareExample.java | 2 +- .../com/github/scribejava/apis/examples/FrappeExample.java | 2 +- .../github/scribejava/apis/examples/FreelancerExample.java | 2 +- .../com/github/scribejava/apis/examples/GeniusExample.java | 2 +- .../scribejava/apis/examples/GitHubAsyncOkHttpExample.java | 2 +- .../com/github/scribejava/apis/examples/GitHubExample.java | 2 +- .../scribejava/apis/examples/Google20AsyncAHCExample.java | 2 +- .../scribejava/apis/examples/Google20WithPKCEExample.java | 2 +- .../java/com/github/scribejava/apis/examples/HHExample.java | 2 +- .../com/github/scribejava/apis/examples/ImgurExample.java | 2 +- .../com/github/scribejava/apis/examples/Kaixin20Example.java | 2 +- .../github/scribejava/apis/examples/LinkedIn20Example.java | 2 +- .../com/github/scribejava/apis/examples/LinkedInExample.java | 2 +- .../scribejava/apis/examples/LinkedInExampleWithScopes.java | 2 +- .../java/com/github/scribejava/apis/examples/LiveExample.java | 2 +- .../github/scribejava/apis/examples/MailruAsyncExample.java | 2 +- .../com/github/scribejava/apis/examples/MailruExample.java | 2 +- .../com/github/scribejava/apis/examples/MeetupExample.java | 2 +- .../com/github/scribejava/apis/examples/MisfitExample.java | 2 +- .../com/github/scribejava/apis/examples/NaverExample.java | 2 +- .../github/scribejava/apis/examples/NeteaseWeiboExample.java | 2 +- .../github/scribejava/apis/examples/OdnoklassnikiExample.java | 2 +- .../com/github/scribejava/apis/examples/PinterestExample.java | 2 +- .../com/github/scribejava/apis/examples/Px500Example.java | 2 +- .../com/github/scribejava/apis/examples/RenrenExample.java | 2 +- .../github/scribejava/apis/examples/SalesforceExample.java | 2 +- .../scribejava/apis/examples/SalesforceNingAsyncExample.java | 2 +- .../github/scribejava/apis/examples/SinaWeibo2Example.java | 2 +- .../com/github/scribejava/apis/examples/SinaWeiboExample.java | 2 +- .../com/github/scribejava/apis/examples/SkyrockExample.java | 2 +- .../com/github/scribejava/apis/examples/SohuWeiboExample.java | 2 +- .../github/scribejava/apis/examples/StackExchangeExample.java | 2 +- .../apis/examples/TheThingsNetworkV1StagingExample.java | 2 +- .../apis/examples/TheThingsNetworkV2PreviewExample.java | 2 +- .../com/github/scribejava/apis/examples/TrelloExample.java | 2 +- .../com/github/scribejava/apis/examples/TumblrExample.java | 2 +- .../com/github/scribejava/apis/examples/TutByExample.java | 2 +- .../com/github/scribejava/apis/examples/TwitterExample.java | 2 +- .../com/github/scribejava/apis/examples/ViadeoExample.java | 2 +- .../apis/examples/VkontakteClientCredentialsGrantExample.java | 2 +- .../com/github/scribejava/apis/examples/VkontakteExample.java | 2 +- .../java/com/github/scribejava/apis/examples/XingExample.java | 2 +- .../main/java/com/github/scribejava/core/model/Response.java | 4 ++-- 54 files changed, 55 insertions(+), 55 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index ed7c20b96..6a35e469b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class AWeberExample { +public class AWeberExample { //To get your consumer key/secret, and view API docs, see https://labs.aweber.com/docs private static final String ACCOUNT_RESOURCE_URL = "https://api.aweber.com/1.0/accounts/"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java index e1cb6b809..665a5552f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java @@ -13,7 +13,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class AutomaticExample { +public class AutomaticExample { private static final String NETWORK_NAME = "Automatic"; private static final String PROTECTED_RESOURCE_URL = "https://api.automatic.com/user/me/"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index 062753217..7f82c9222 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -14,7 +14,7 @@ import java.util.Map; import java.util.concurrent.ExecutionException; -public final class Box20Example { +public class Box20Example { private static final String NETWORK_NAME = "Box"; private static final String PROTECTED_RESOURCE_URL = "https://api.box.com/2.0/users/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java index f11b4e72c..fc0f4d3e2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class DataportenExample { +public class DataportenExample { private static final String NETWORK_NAME = "Dataporten"; private static final String PROTECTED_RESOURCE_URL = "https://auth.dataporten.no/userinfo"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index a27dd895c..a1f11b196 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class DiggExample { +public class DiggExample { private static final String NETWORK_NAME = "Digg"; private static final String PROTECTED_RESOURCE_URL = "http://services.digg.com/2.0/comment.digg"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java index 21800310d..d26adb59a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java @@ -13,7 +13,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class EtsyExample { +public class EtsyExample { private static final String PROTECTED_RESOURCE_URL = "https://openapi.etsy.com/v2/users/__SELF__"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java index e5773f934..bf7c6f2ee 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java @@ -13,7 +13,7 @@ import com.github.scribejava.httpclient.apache.ApacheHttpClientConfig; import java.io.IOException; -public final class FacebookAsyncApacheExample { +public class FacebookAsyncApacheExample { private static final String NETWORK_NAME = "Facebook"; private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.11/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index d5ea5438c..81d1dd53a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -14,7 +14,7 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public final class FacebookAsyncNingExample { +public class FacebookAsyncNingExample { private static final String NETWORK_NAME = "Facebook"; private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.11/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index f7a156ddc..7a0ba726a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class FacebookExample { +public class FacebookExample { private static final String NETWORK_NAME = "Facebook"; private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.11/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index 25f858565..66ddf3fd2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -13,7 +13,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class FlickrExample { +public class FlickrExample { private static final String PROTECTED_RESOURCE_URL = "http://api.flickr.com/services/rest/"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index ad78fe6ae..aae4fe7f8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -11,7 +11,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class Foursquare2Example { +public class Foursquare2Example { private static final String PROTECTED_RESOURCE_URL = "https://api.foursquare.com/v2/users/self/friends?oauth_token="; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index 2eaf4fcae..d9ec56652 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class FoursquareExample { +public class FoursquareExample { private static final String PROTECTED_RESOURCE_URL = "http://api.foursquare.com/v1/user"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java index b23792184..ce9012b1c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java @@ -11,7 +11,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class FrappeExample { +public class FrappeExample { private static final String NETWORK_NAME = "Frappe"; private static final String PROTECTED_RESOURCE_PATH = "/api/method/frappe.integrations.oauth2.openid_profile"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index d8a9afa3f..80640d989 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class FreelancerExample { +public class FreelancerExample { private static final String NETWORK_NAME = "Freelancer"; private static final String AUTHORIZE_URL diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java index af515b79c..8f269657e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class GeniusExample { +public class GeniusExample { private static final String NETWORK_NAME = "Genius"; private static final String PROTECTED_RESOURCE_URL = "https://api.genius.com/songs/378195"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java index 57d618db5..bc05042bf 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java @@ -14,7 +14,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class GitHubAsyncOkHttpExample { +public class GitHubAsyncOkHttpExample { private static final String NETWORK_NAME = "GitHub"; private static final String PROTECTED_RESOURCE_URL = "https://api.github.com/user"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index 3227f8fc9..6d60957a3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class GitHubExample { +public class GitHubExample { private static final String NETWORK_NAME = "GitHub"; private static final String PROTECTED_RESOURCE_URL = "https://api.github.com/user"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index 54bb06696..d815edce3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -17,7 +17,7 @@ import java.util.concurrent.ExecutionException; import org.asynchttpclient.DefaultAsyncHttpClientConfig; -public final class Google20AsyncAHCExample { +public class Google20AsyncAHCExample { private static final String NETWORK_NAME = "G+ Async"; private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java index eb4594e98..54a359291 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java @@ -15,7 +15,7 @@ import java.util.Map; import java.util.concurrent.ExecutionException; -public final class Google20WithPKCEExample { +public class Google20WithPKCEExample { private static final String NETWORK_NAME = "G+"; private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index 9f2c4e560..0c1d24b9b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -13,7 +13,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class HHExample { +public class HHExample { private static final String NETWORK_NAME = "hh.ru"; private static final String PROTECTED_RESOURCE_URL = "https://api.hh.ru/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index fcce7ec81..ddc67c107 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -12,7 +12,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class ImgurExample { +public class ImgurExample { private static final String NETWORK_NAME = "Imgur"; private static final String PROTECTED_RESOURCE_URL = "https://api.imgur.com/3/account/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java index de1e491cd..dad494e49 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -11,7 +11,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class Kaixin20Example { +public class Kaixin20Example { private static final String NETWORK_NAME = "Kaixin"; private static final String PROTECTED_RESOURCE_URL = "https://api.kaixin001.com/users/me.json"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java index 9ff9fe0cd..d76acb856 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java @@ -11,7 +11,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class LinkedIn20Example { +public class LinkedIn20Example { private static final String NETWORK_NAME = "LinkedIn"; private static final String PROTECTED_RESOURCE_URL = "https://api.linkedin.com/v1/people/~:(%s)"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index 7270b6a11..48f9fdcb5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class LinkedInExample { +public class LinkedInExample { private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index e94a687a0..f90f91ce0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class LinkedInExampleWithScopes { +public class LinkedInExampleWithScopes { private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~/connections:(id,last-name)"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index 1dc9c26df..119c5aca1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -11,7 +11,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class LiveExample { +public class LiveExample { private static final String PROTECTED_RESOURCE_URL = "https://apis.live.net/v5.0/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index 9814bcfbe..95673747d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -13,7 +13,7 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public final class MailruAsyncExample { +public class MailruAsyncExample { private static final String NETWORK_NAME = "Mail.ru"; private static final String PROTECTED_RESOURCE_URL diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index 01ff29cd9..372bedd1a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -11,7 +11,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class MailruExample { +public class MailruExample { private static final String NETWORK_NAME = "Mail.ru"; private static final String PROTECTED_RESOURCE_URL diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index dc182ae05..ff97a734a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class MeetupExample { +public class MeetupExample { private static final String PROTECTED_RESOURCE_URL = "http://api.meetup.com/2/member/self"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java index 057099500..60d5a903c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java @@ -12,7 +12,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class MisfitExample { +public class MisfitExample { private static final String NETWORK_NAME = "Misfit"; private static final String PROTECTED_RESOURCE_URL diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java index 33e647f5c..bf359c547 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java @@ -13,7 +13,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class NaverExample { +public class NaverExample { private static final String NETWORK_NAME = "Naver"; private static final String PROTECTED_RESOURCE_URL = "https://openapi.naver.com/v1/nid/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java index 324b8709c..e56a05a0c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class NeteaseWeiboExample { +public class NeteaseWeiboExample { private static final String NETWORK_NAME = "NetEase(163.com) Weibo"; private static final String PROTECTED_RESOURCE_URL = "http://api.t.163.com/account/verify_credentials.json"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index ee7b46549..4ff6a4933 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -11,7 +11,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class OdnoklassnikiExample { +public class OdnoklassnikiExample { private static final String NETWORK_NAME = "Odnoklassniki.ru"; private static final String PROTECTED_RESOURCE_URL diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index 6d25b80a2..03b3a428a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -12,7 +12,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class PinterestExample { +public class PinterestExample { private static final String PROTECTED_RESOURCE_URL = "https://api.pinterest.com/v1/me/"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index 35fba3e8d..962faaa3d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class Px500Example { +public class Px500Example { private static final String PROTECTED_RESOURCE_URL = "https://api.500px.com/v1/"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 1f0ff3908..4d9b3bd76 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -21,7 +21,7 @@ import java.util.List; import java.util.concurrent.ExecutionException; -public final class RenrenExample { +public class RenrenExample { private static final String NETWORK_NAME = "Renren"; private static final String PROTECTED_RESOURCE_URL = "http://api.renren.com/restserver.do"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java index 39cbbc2fe..7d4aa6b10 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -17,7 +17,7 @@ import java.security.NoSuchAlgorithmException; import java.util.concurrent.ExecutionException; -public final class SalesforceExample { +public class SalesforceExample { private static final String NETWORK_NAME = "Salesforce"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java index 19e530de1..f5a524026 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java @@ -20,7 +20,7 @@ import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; -public final class SalesforceNingAsyncExample { +public class SalesforceNingAsyncExample { private static final String NETWORK_NAME = "Salesforce"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java index 9233e1b32..d4ff865de 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -11,7 +11,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class SinaWeibo2Example { +public class SinaWeibo2Example { private static final String NETWORK_NAME = "SinaWeibo"; private static final String PROTECTED_RESOURCE_URL = "https://api.weibo.com/2/account/get_uid.json"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index e8622952c..618e8c881 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class SinaWeiboExample { +public class SinaWeiboExample { private static final String NETWORK_NAME = "SinaWeibo"; private static final String PROTECTED_RESOURCE_URL = "http://api.t.sina.com.cn/account/verify_credentials.json"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index 07c010961..5751538ef 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class SkyrockExample { +public class SkyrockExample { private static final String PROTECTED_RESOURCE_URL = "https://api.skyrock.com/v2/user/get.json"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java index 2ae6d3ffd..690efa9a8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class SohuWeiboExample { +public class SohuWeiboExample { private static final String NETWORK_NAME = "SohuWeibo"; private static final String PROTECTED_RESOURCE_URL = "http://api.t.sohu.com/account/verify_credentials.json"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index b9e699b5b..39350cd14 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -13,7 +13,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class StackExchangeExample { +public class StackExchangeExample { private static final String NETWORK_NAME = "Stack Exchange"; private static final String PROTECTED_RESOURCE_URL = "https://api.stackexchange.com/2.2/me"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java index 08279d535..427b83f2c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java @@ -14,7 +14,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class TheThingsNetworkV1StagingExample { +public class TheThingsNetworkV1StagingExample { private static final String NETWORK_NAME = "TTNv1staging"; private static final String PROTECTED_RESOURCE_URL = "https://account.thethingsnetwork.org/applications"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java index 08c7eb888..19cc96331 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java @@ -13,7 +13,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class TheThingsNetworkV2PreviewExample { +public class TheThingsNetworkV2PreviewExample { private static final String NETWORK_NAME = "TTNv2preview"; private static final String PROTECTED_RESOURCE_URL = diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index 62281a62f..a73826a34 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class TrelloExample { +public class TrelloExample { private static final String API_KEY = "your_api_key"; private static final String API_SECRET = "your_api_secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index f202a4540..6d16ef54f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class TumblrExample { +public class TumblrExample { private static final String PROTECTED_RESOURCE_URL = "http://api.tumblr.com/v2/user/info"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index 5ce2d2e2c..70f05e5b2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -13,7 +13,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class TutByExample { +public class TutByExample { private static final String NETWORK_NAME = "Tut.by"; private static final String PROTECTED_RESOURCE_URL = "http://profile.tut.by/getInfo"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index 24af2acc8..20b95531d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class TwitterExample { +public class TwitterExample { private static final String PROTECTED_RESOURCE_URL = "https://api.twitter.com/1.1/account/verify_credentials.json"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index 6e59af8db..134faf3cc 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -11,7 +11,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class ViadeoExample { +public class ViadeoExample { private static final String NETWORK_NAME = "Viadeo"; private static final String PROTECTED_RESOURCE_URL = "https://api.viadeo.com/me?user_detail=full"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java index 0ffc2fc13..ed2fd0fba 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java @@ -7,7 +7,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class VkontakteClientCredentialsGrantExample { +public class VkontakteClientCredentialsGrantExample { private static final String NETWORK_NAME = "Vkontakte.ru"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java index 5c18980b2..bbab9db62 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class VkontakteExample { +public class VkontakteExample { private static final String NETWORK_NAME = "Vkontakte.ru"; private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/users.get?v=" diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index 09ee75878..5cfd1d89d 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class XingExample { +public class XingExample { private static final String PROTECTED_RESOURCE_URL = "https://api.xing.com/v1/users/me"; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java index 8a4807677..4a84c76ef 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java @@ -41,7 +41,7 @@ private String parseBodyContents() throws IOException { return body; } - public final boolean isSuccessful() { + public boolean isSuccessful() { return code >= 200 && code < 400; } @@ -64,7 +64,7 @@ public InputStream getStream() { * * @return the status code */ - public final int getCode() { + public int getCode() { return code; } From 0084b13bdd5c396a6210a4536d75cd0c1bbd1d95 Mon Sep 17 00:00:00 2001 From: Dan Manastireanu Date: Wed, 16 May 2018 17:14:37 +0300 Subject: [PATCH 082/481] Fix Fitbit token error extraction --- .../apis/fitbit/FitBitJsonTokenExtractor.java | 23 ++++++- .../fitbit/FitBitJsonTokenExtractorTest.java | 62 +++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java index affed2f6d..9cc8f1167 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java @@ -1,12 +1,16 @@ package com.github.scribejava.apis.fitbit; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; + +import java.net.URI; import java.util.regex.Pattern; public class FitBitJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { private static final Pattern USER_ID_REGEX_PATTERN = Pattern.compile("\"user_id\"\\s*:\\s*\"(\\S*?)\""); - + private static final Pattern ERROR_REGEX_PATTERN = Pattern.compile("\"errorType\"\\s*:\\s*\"(\\S*?)\""); + private static final Pattern ERROR_DESCRIPTION_REGEX_PATTERN = Pattern.compile("\"message\"\\s*:\\s*\"([^\"]*?)\""); protected FitBitJsonTokenExtractor() { } @@ -25,4 +29,21 @@ protected FitBitOAuth2AccessToken createToken(String accessToken, String tokenTy return new FitBitOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, extractParameter(response, USER_ID_REGEX_PATTERN, false), response); } + + @Override + public void generateError(String response) { + final String errorInString = extractParameter(response, ERROR_REGEX_PATTERN, true); + final String errorDescription = extractParameter(response, ERROR_DESCRIPTION_REGEX_PATTERN, false); + final URI errorUri = URI.create("https://dev.fitbit.com/build/reference/web-api/oauth2/"); + + OAuth2AccessTokenErrorResponse.ErrorCode errorCode; + try { + errorCode = OAuth2AccessTokenErrorResponse.ErrorCode.valueOf(errorInString); + } catch (IllegalArgumentException iaE) { + //non oauth standard error code + errorCode = null; + } + + throw new OAuth2AccessTokenErrorResponse(errorCode, errorDescription, errorUri, response); + } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java new file mode 100644 index 000000000..49b94d46e --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java @@ -0,0 +1,62 @@ +package com.github.scribejava.apis.fitbit; + +import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; +import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse.ErrorCode; + +import org.hamcrest.FeatureMatcher; +import org.hamcrest.Matcher; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import static org.hamcrest.CoreMatchers.equalTo; + +public class FitBitJsonTokenExtractorTest { + + private static final String ERROR_DESCRIPTION = "Authorization code invalid: " + + "cbb1c11b23209011e89be71201fa6381464dc0af " + + "Visit https://dev.fitbit.com/docs/oauth2 for more information " + + "on the Fitbit Web API authorization process."; + private static final String ERROR_JSON = "{\"errors\":[{\"errorType\":\"invalid_grant\",\"message\":\"" + + ERROR_DESCRIPTION + "\"}],\"success\":false}"; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void testErrorExtraction() { + + final FitBitJsonTokenExtractor extractor = new FitBitJsonTokenExtractor(); + + thrown.expect(OAuth2AccessTokenErrorResponse.class); + thrown.expect(errorCode(ErrorCode.invalid_grant)); + thrown.expect(errorDescription(ERROR_DESCRIPTION)); + + extractor.generateError(ERROR_JSON); + + } + + private Matcher errorCode(ErrorCode expected) { + return new FeatureMatcher( + equalTo(expected), + "a response with errorCode", + "errorCode") { + @Override + protected ErrorCode featureValueOf(OAuth2AccessTokenErrorResponse actual) { + return actual.getErrorCode(); + } + }; + } + + private Matcher errorDescription(String expected) { + return new FeatureMatcher( + equalTo(expected), + "a response with errorDescription", + "errorDescription") { + @Override + protected String featureValueOf(OAuth2AccessTokenErrorResponse actual) { + return actual.getErrorDescription(); + } + }; + } +} From e719d25d40d3ddf3fbc64a3c241261eabb04bd9b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 18 May 2018 18:58:20 +0300 Subject: [PATCH 083/481] fix error parsing for Fitbit (thanks to https://github.com/danmana) --- changelog | 3 ++ .../apis/fitbit/FitBitJsonTokenExtractor.java | 7 +-- .../apis/examples/FitbitApi20Example.java | 2 +- .../fitbit/FitBitJsonTokenExtractorTest.java | 46 +++++++++---------- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/changelog b/changelog index cc865a4ed..b68d3d070 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * fix error parsing for Fitbit (thanks to https://github.com/danmana) + [5.4.0] * fix missing support for scope for refresh_token grant_type (thanks to https://github.com/tlxtellef) * add email field to VKOAuth2AccessToken (thanks to https://github.com/grouzen) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java index 9cc8f1167..fad86fc53 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java @@ -3,7 +3,6 @@ import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; -import java.net.URI; import java.util.regex.Pattern; public class FitBitJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { @@ -30,11 +29,13 @@ protected FitBitOAuth2AccessToken createToken(String accessToken, String tokenTy extractParameter(response, USER_ID_REGEX_PATTERN, false), response); } + /** + * Related documentation: https://dev.fitbit.com/build/reference/web-api/oauth2/ + */ @Override public void generateError(String response) { final String errorInString = extractParameter(response, ERROR_REGEX_PATTERN, true); final String errorDescription = extractParameter(response, ERROR_DESCRIPTION_REGEX_PATTERN, false); - final URI errorUri = URI.create("https://dev.fitbit.com/build/reference/web-api/oauth2/"); OAuth2AccessTokenErrorResponse.ErrorCode errorCode; try { @@ -44,6 +45,6 @@ public void generateError(String response) { errorCode = null; } - throw new OAuth2AccessTokenErrorResponse(errorCode, errorDescription, errorUri, response); + throw new OAuth2AccessTokenErrorResponse(errorCode, errorDescription, null, response); } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java index 72750de6b..9c17e9054 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java @@ -58,7 +58,7 @@ public static void main(String... args) throws Exception { if (!(oauth2AccessToken instanceof FitBitOAuth2AccessToken)) { System.out.println("oauth2AccessToken is not instance of FitBitOAuth2AccessToken. Strange enough. exit."); - System.exit(0); + return; } final FitBitOAuth2AccessToken accessToken = (FitBitOAuth2AccessToken) oauth2AccessToken; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java index 49b94d46e..a0f5b53a3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java @@ -4,7 +4,6 @@ import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse.ErrorCode; import org.hamcrest.FeatureMatcher; -import org.hamcrest.Matcher; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -29,34 +28,33 @@ public void testErrorExtraction() { final FitBitJsonTokenExtractor extractor = new FitBitJsonTokenExtractor(); thrown.expect(OAuth2AccessTokenErrorResponse.class); - thrown.expect(errorCode(ErrorCode.invalid_grant)); - thrown.expect(errorDescription(ERROR_DESCRIPTION)); + thrown.expect(new ErrorCodeFeatureMatcher(ErrorCode.invalid_grant)); + thrown.expect(new ErrorDescriptionFeatureMatcher(ERROR_DESCRIPTION)); extractor.generateError(ERROR_JSON); - } - private Matcher errorCode(ErrorCode expected) { - return new FeatureMatcher( - equalTo(expected), - "a response with errorCode", - "errorCode") { - @Override - protected ErrorCode featureValueOf(OAuth2AccessTokenErrorResponse actual) { - return actual.getErrorCode(); - } - }; + private static class ErrorCodeFeatureMatcher extends FeatureMatcher { + + private ErrorCodeFeatureMatcher(ErrorCode expected) { + super(equalTo(expected), "a response with errorCode", "errorCode"); + } + + @Override + protected ErrorCode featureValueOf(OAuth2AccessTokenErrorResponse actual) { + return actual.getErrorCode(); + } } - private Matcher errorDescription(String expected) { - return new FeatureMatcher( - equalTo(expected), - "a response with errorDescription", - "errorDescription") { - @Override - protected String featureValueOf(OAuth2AccessTokenErrorResponse actual) { - return actual.getErrorDescription(); - } - }; + private static class ErrorDescriptionFeatureMatcher extends FeatureMatcher { + + private ErrorDescriptionFeatureMatcher(String expected) { + super(equalTo(expected), "a response with errorDescription", "errorDescription"); + } + + @Override + protected String featureValueOf(OAuth2AccessTokenErrorResponse actual) { + return actual.getErrorDescription(); + } } } From ae143539daa079cac123e8c69a2fdc237fa77e14 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 18 May 2018 19:40:29 +0300 Subject: [PATCH 084/481] optimize debug log performance impact on prod in OAuth1 and fix NoClassDefFoundError on Android device with SDK 18 and lower (thanks to https://github.com/arcao) --- changelog | 2 + .../core/oauth/OAuth10aService.java | 37 +++++++++---------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/changelog b/changelog index b68d3d070..3599d3d18 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,7 @@ [SNAPSHOT] * fix error parsing for Fitbit (thanks to https://github.com/danmana) + * optimize debug log performance impact on prod in OAuth1 and fix + NoClassDefFoundError on Android device with SDK 18 and lower (thanks to https://github.com/arcao) [5.4.0] * fix missing support for scope for refresh_token grant_type (thanks to https://github.com/tlxtellef) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index bf708395e..3986f45d5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -45,15 +45,15 @@ public OAuth10aService(DefaultApi10a api, String apiKey, String apiSecret, Strin } public OAuth1RequestToken getRequestToken() throws IOException, InterruptedException, ExecutionException { - log("obtaining request token from " + api.getRequestTokenEndpoint()); + log("obtaining request token from %s", api.getRequestTokenEndpoint()); final OAuthRequest request = prepareRequestTokenRequest(); log("sending request..."); final Response response = execute(request); final String body = response.getBody(); - log("response status code: " + response.getCode()); - log("response body: " + body); + log("response status code: %s", response.getCode()); + log("response body: %s", body); return api.getRequestTokenExtractor().extract(response); } @@ -62,7 +62,7 @@ public Future getRequestTokenAsync() { } public Future getRequestTokenAsync(OAuthAsyncRequestCallback callback) { - log("async obtaining request token from " + api.getRequestTokenEndpoint()); + log("async obtaining request token from %s", api.getRequestTokenEndpoint()); final OAuthRequest request = prepareRequestTokenRequest(); return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override @@ -78,7 +78,7 @@ protected OAuthRequest prepareRequestTokenRequest() { if (callback == null) { callback = OAuthConstants.OOB; } - log("setting oauth_callback to " + callback); + log("setting oauth_callback to %s", callback); request.addOAuthParameter(OAuthConstants.CALLBACK, callback); addOAuthParams(request, ""); appendSignature(request); @@ -97,12 +97,12 @@ protected void addOAuthParams(OAuthRequest request, String tokenSecret) { } request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, tokenSecret)); - log("appended additional OAuth parameters: " + request.getOauthParameters()); + log("appended additional OAuth parameters: %s", request.getOauthParameters()); } public OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, String oauthVerifier) throws IOException, InterruptedException, ExecutionException { - log("obtaining access token from " + api.getAccessTokenEndpoint()); + log("obtaining access token from %s", api.getAccessTokenEndpoint()); final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier); final Response response = execute(request); return api.getAccessTokenExtractor().extract(response); @@ -113,8 +113,8 @@ public Future getAccessTokenAsync(OAuth1RequestToken requestT } /** - * Start the request to retrieve the access token. The optionally provided - * callback will be called with the Token when it is available. + * Start the request to retrieve the access token. The optionally provided callback will be called with the Token + * when it is available. * * @param requestToken request token (obtained previously or null) * @param oauthVerifier oauth_verifier @@ -123,7 +123,7 @@ public Future getAccessTokenAsync(OAuth1RequestToken requestT */ public Future getAccessTokenAsync(OAuth1RequestToken requestToken, String oauthVerifier, OAuthAsyncRequestCallback callback) { - log("async obtaining access token from " + api.getAccessTokenEndpoint()); + log("async obtaining access token from %s", api.getAccessTokenEndpoint()); final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier); return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override @@ -137,19 +137,19 @@ protected OAuthRequest prepareAccessTokenRequest(OAuth1RequestToken requestToken final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); request.addOAuthParameter(OAuthConstants.TOKEN, requestToken.getToken()); request.addOAuthParameter(OAuthConstants.VERIFIER, oauthVerifier); - log("setting token to: " + requestToken + " and verifier to: " + oauthVerifier); + log("setting token to: %s and verifier to: %s", requestToken, oauthVerifier); addOAuthParams(request, requestToken.getTokenSecret()); appendSignature(request); return request; } public void signRequest(OAuth1AccessToken token, OAuthRequest request) { - log("signing request: " + request.getCompleteUrl()); + log("signing request: %s", request.getCompleteUrl()); if (!token.isEmpty() || api.isEmptyOAuthTokenParamIsRequired()) { request.addOAuthParameter(OAuthConstants.TOKEN, token.getToken()); } - log("setting token to: " + token); + log("setting token to: %s", token); addOAuthParams(request, token.getTokenSecret()); appendSignature(request); } @@ -160,8 +160,7 @@ public String getVersion() { } /** - * Returns the URL where you should redirect your users to authenticate your - * application. + * Returns the URL where you should redirect your users to authenticate your application. * * @param requestToken the request token you need to authorize * @return the URL where you should redirect your users @@ -175,8 +174,8 @@ private String getSignature(OAuthRequest request, String tokenSecret) { final String baseString = api.getBaseStringExtractor().extract(request); final String signature = api.getSignatureService().getSignature(baseString, getApiSecret(), tokenSecret); - log("base string is: " + baseString); - log("signature is: " + signature); + log("base string is: %s", baseString); + log("signature is: %s", signature); return signature; } @@ -205,9 +204,9 @@ public DefaultApi10a getApi() { return api; } - public void log(String message) { + public void log(String messagePattern, Object... params) { if (debugStream != null) { - message += '\n'; + final String message = String.format(messagePattern, params) + '\n'; try { debugStream.write(message.getBytes("UTF8")); } catch (IOException | RuntimeException e) { From 60d37feead4a652c59f1a8a9bb2499cbf3c98881 Mon Sep 17 00:00:00 2001 From: Lucas Werkmeister Date: Thu, 17 May 2018 23:01:50 +0200 Subject: [PATCH 085/481] Add MediaWiki API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This API can be used for any MediaWiki installation that has the OAuth extension [1] installed. Two default instances are provided for convenience: one for wikis hosted by the Wikimedia Foundation (including Wikipedia), which is the one most users will be interested in, and one for the Wikimedia Foundation’s Beta Cluster, which is more appropriate for testing purposes. The example is copied and slightly adapted from AWeberExample.java. [1]: https://www.mediawiki.org/wiki/Extension:OAuth --- README.md | 1 + .../github/scribejava/apis/MediaWikiApi.java | 70 +++++++++++++++++++ .../apis/examples/MediaWikiExample.java | 70 +++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java diff --git a/README.md b/README.md index 7227ce97d..554c8e1fc 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ ScribeJava support out-of-box several HTTP clients: * Microsoft Azure Active Directory (Azure AD) (http://azure.microsoft.com/) * Microsoft Live (https://login.live.com/) * Mail.Ru (https://mail.ru/) +* MediaWiki (https://www.mediawiki.org/) * Meetup (http://www.meetup.com/) * NAVER (http://www.naver.com/) * NetEase (http://www.163.com/) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java new file mode 100644 index 000000000..de86d4407 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java @@ -0,0 +1,70 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi10a; + +public class MediaWikiApi extends DefaultApi10a { + + private static final MediaWikiApi WIKIMEDIA_INSTANCE = new MediaWikiApi( + "https://meta.wikimedia.org/w/index.php", + "https://meta.wikimedia.org/wiki/" + ); + + private static final MediaWikiApi WIKIMEDIA_BETA_INSTANCE = new MediaWikiApi( + "https://meta.wikimedia.beta.wmflabs.org/w/index.php", + "https://meta.wikimedia.beta.wmflabs.org/wiki/" + ); + + private final String indexUrl; + private final String niceUrlBase; + + /** + * @param indexUrl The URL to the index.php of the wiki. + * Due to a MediaWiki bug, + * some requests must currently use the non-nice URL. + * @param niceUrlBase The base of nice URLs for the wiki, including the trailing slash. + * Due to another MediaWiki bug, + * some requests must currently use the nice URL. + */ + public MediaWikiApi(final String indexUrl, final String niceUrlBase) { + this.indexUrl = indexUrl; + this.niceUrlBase = niceUrlBase; + } + + /** + * The instance for wikis hosted by the Wikimedia Foundation. + * Consumers are requested on + * + * Special:OAuthConsumerRegistration/propose + * . + */ + public static MediaWikiApi wikimediaInstance() { + return WIKIMEDIA_INSTANCE; + } + + /** + * The instance for wikis in the Wikimedia Foundation’s Beta Cluster. + * Consumers are requested on + * + * Special:OAuthConsumerRegistration/propose + * . + */ + public static MediaWikiApi wikimediaBetaInstance() { + return WIKIMEDIA_BETA_INSTANCE; + } + + @Override + public String getRequestTokenEndpoint() { + return indexUrl + "?title=Special:OAuth/initiate"; + } + + @Override + public String getAuthorizationBaseUrl() { + return niceUrlBase + "Special:OAuth/authorize"; + } + + @Override + public String getAccessTokenEndpoint() { + return indexUrl + "?title=Special:OAuth/token"; + } + +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java new file mode 100644 index 000000000..6d1ca6e17 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java @@ -0,0 +1,70 @@ +package com.github.scribejava.apis.examples; + +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.MediaWikiApi; +import com.github.scribejava.core.model.OAuth1AccessToken; +import com.github.scribejava.core.model.OAuth1RequestToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth10aService; +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +public final class MediaWikiExample { + + // To get your consumer key/secret, see https://meta.wikimedia.org/wiki/Special:OAuthConsumerRegistration/propose + private static final String CONSUMER_KEY = ""; + private static final String CONSUMER_SECRET = ""; + + private static final String API_USERINFO_URL = + "https://meta.wikimedia.org/w/api.php?action=query&format=json&meta=userinfo"; + + private MediaWikiExample() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + final OAuth10aService service = new ServiceBuilder(CONSUMER_KEY) + .apiSecret(CONSUMER_SECRET) + .build(MediaWikiApi.wikimediaInstance()); + + final Scanner in = new Scanner(System.in); + + System.out.println("=== MediaWiki's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Request Token + System.out.println("Fetching the Request Token..."); + final OAuth1RequestToken requestToken = service.getRequestToken(); + System.out.println("Got the Request Token!"); + System.out.println(); + + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(service.getAuthorizationUrl(requestToken)); + System.out.println("And paste the verifier here"); + System.out.print(">>"); + final String oauthVerifier = in.nextLine(); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, API_USERINFO_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with MediaWiki and ScribeJava! :)"); + } + +} From 68c014982490f6a08dc27569fb7dbe3a914b87b9 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 23 May 2018 12:07:27 +0300 Subject: [PATCH 086/481] add new API - MediaWiki (https://www.mediawiki.org/) (thanks to https://github.com/lucaswerkmeister) --- changelog | 1 + .../github/scribejava/apis/MediaWikiApi.java | 49 ++++++++++--------- .../apis/examples/MediaWikiExample.java | 8 +-- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/changelog b/changelog index 3599d3d18..6b3c5a577 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * fix error parsing for Fitbit (thanks to https://github.com/danmana) * optimize debug log performance impact on prod in OAuth1 and fix NoClassDefFoundError on Android device with SDK 18 and lower (thanks to https://github.com/arcao) + * add new API - MediaWiki (https://www.mediawiki.org/) (thanks to https://github.com/lucaswerkmeister) [5.4.0] * fix missing support for scope for refresh_token grant_type (thanks to https://github.com/tlxtellef) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java index de86d4407..8426d1924 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java @@ -4,52 +4,55 @@ public class MediaWikiApi extends DefaultApi10a { - private static final MediaWikiApi WIKIMEDIA_INSTANCE = new MediaWikiApi( - "https://meta.wikimedia.org/w/index.php", - "https://meta.wikimedia.org/wiki/" - ); + private static class InstanceHolder { - private static final MediaWikiApi WIKIMEDIA_BETA_INSTANCE = new MediaWikiApi( - "https://meta.wikimedia.beta.wmflabs.org/w/index.php", - "https://meta.wikimedia.beta.wmflabs.org/wiki/" - ); + private static final MediaWikiApi INSTANCE = new MediaWikiApi( + "https://meta.wikimedia.org/w/index.php", + "https://meta.wikimedia.org/wiki/" + ); + } + + private static class BetaInstanceHolder { + + private static final MediaWikiApi BETA_INSTANCE = new MediaWikiApi( + "https://meta.wikimedia.beta.wmflabs.org/w/index.php", + "https://meta.wikimedia.beta.wmflabs.org/wiki/" + ); + } private final String indexUrl; private final String niceUrlBase; /** - * @param indexUrl The URL to the index.php of the wiki. - * Due to a MediaWiki bug, - * some requests must currently use the non-nice URL. - * @param niceUrlBase The base of nice URLs for the wiki, including the trailing slash. - * Due to another MediaWiki bug, - * some requests must currently use the nice URL. + * @param indexUrl The URL to the index.php of the wiki. Due to a + * MediaWiki bug, some requests must currently use the non-nice URL. + * @param niceUrlBase The base of nice URLs for the wiki, including the trailing slash. Due to + * another MediaWiki bug, some requests must currently use + * the nice URL. */ - public MediaWikiApi(final String indexUrl, final String niceUrlBase) { + public MediaWikiApi(String indexUrl, String niceUrlBase) { this.indexUrl = indexUrl; this.niceUrlBase = niceUrlBase; } /** - * The instance for wikis hosted by the Wikimedia Foundation. - * Consumers are requested on + * The instance for wikis hosted by the Wikimedia Foundation. Consumers are requested on * * Special:OAuthConsumerRegistration/propose * . */ - public static MediaWikiApi wikimediaInstance() { - return WIKIMEDIA_INSTANCE; + public static MediaWikiApi instance() { + return InstanceHolder.INSTANCE; } /** - * The instance for wikis in the Wikimedia Foundation’s Beta Cluster. - * Consumers are requested on + * The instance for wikis in the Wikimedia Foundation’s Beta Cluster. Consumers are requested on * * Special:OAuthConsumerRegistration/propose * . */ - public static MediaWikiApi wikimediaBetaInstance() { - return WIKIMEDIA_BETA_INSTANCE; + public static MediaWikiApi instanceBeta() { + return BetaInstanceHolder.BETA_INSTANCE; } @Override diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java index 6d1ca6e17..6ec9e5b67 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java @@ -12,14 +12,14 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public final class MediaWikiExample { +public class MediaWikiExample { // To get your consumer key/secret, see https://meta.wikimedia.org/wiki/Special:OAuthConsumerRegistration/propose private static final String CONSUMER_KEY = ""; private static final String CONSUMER_SECRET = ""; - private static final String API_USERINFO_URL = - "https://meta.wikimedia.org/w/api.php?action=query&format=json&meta=userinfo"; + private static final String API_USERINFO_URL + = "https://meta.wikimedia.org/w/api.php?action=query&format=json&meta=userinfo"; private MediaWikiExample() { } @@ -27,7 +27,7 @@ private MediaWikiExample() { public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder(CONSUMER_KEY) .apiSecret(CONSUMER_SECRET) - .build(MediaWikiApi.wikimediaInstance()); + .build(MediaWikiApi.instance()); final Scanner in = new Scanner(System.in); From 57f0e8f8f1c73fcb12b0a6b5eaa7d709287758da Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 23 May 2018 12:30:07 +0300 Subject: [PATCH 087/481] update deps --- pom.xml | 4 ++-- scribejava-httpclient-ahc/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index e2b89b530..09fe4dfd5 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,7 @@ com.google.code.gson gson - 2.8.2 + 2.8.5 test @@ -150,7 +150,7 @@ org.apache.maven.plugins maven-resources-plugin - 3.0.2 + 3.1.0 UTF-8 diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 418fbccfa..0519a9851 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.4.5 + 2.4.7 com.github.scribejava From b30c11ff8497d983e84d1dd78f365b6b9c2ae83f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 23 May 2018 13:22:07 +0300 Subject: [PATCH 088/481] prepare 5.5.0 release --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 554c8e1fc..9b9cf3b58 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 5.4.0 + 5.5.0 ``` @@ -121,7 +121,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 5.4.0 + 5.5.0 ``` diff --git a/changelog b/changelog index 6b3c5a577..56317a30f 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[5.5.0] * fix error parsing for Fitbit (thanks to https://github.com/danmana) * optimize debug log performance impact on prod in OAuth1 and fix NoClassDefFoundError on Android device with SDK 18 and lower (thanks to https://github.com/arcao) From 963c00878b2f049564bdf99ad6c76fbe53f66d8f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 23 May 2018 13:23:10 +0300 Subject: [PATCH 089/481] [maven-release-plugin] prepare release scribejava-5.5.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 09fe4dfd5..cd2b792cb 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.4.1-SNAPSHOT + 5.5.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-5.5.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index da6150e43..55aade30f 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.1-SNAPSHOT + 5.5.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 60e6da8cf..7b4d8e21c 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.1-SNAPSHOT + 5.5.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 0519a9851..0a715e2a6 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.1-SNAPSHOT + 5.5.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 2a3eedc01..d86c6cfd3 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.1-SNAPSHOT + 5.5.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 0b13d47a1..069afde05 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.1-SNAPSHOT + 5.5.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index e135a6e93..ef9606be7 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.4.1-SNAPSHOT + 5.5.0 ../pom.xml From 72723ba99050eeca15a54fa8c8cf7294cc2bc66f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 23 May 2018 13:23:18 +0300 Subject: [PATCH 090/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index cd2b792cb..bc7d1d445 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.5.0 + 5.5.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-5.5.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 55aade30f..e92f60e67 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.0 + 5.5.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 7b4d8e21c..96ea8ad56 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.0 + 5.5.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 0a715e2a6..5b8d1116f 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.0 + 5.5.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index d86c6cfd3..bd4c1bab4 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.0 + 5.5.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 069afde05..fcd3e33aa 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.0 + 5.5.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index ef9606be7..bc10774b8 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.0 + 5.5.1-SNAPSHOT ../pom.xml From 7a635daf2131e00fc72a5a400806ac8af1e6f203 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 23 May 2018 13:53:35 +0300 Subject: [PATCH 091/481] drop deprecated methods and constructors --- .../scribejava/apis/service/FacebookService.java | 13 ------------- .../scribejava/apis/service/ImgurOAuthService.java | 13 ------------- .../apis/service/MailruOAuthService.java | 13 ------------- .../MicrosoftAzureActiveDirectoryService.java | 14 -------------- .../apis/service/OdnoklassnikiOAuthService.java | 14 -------------- .../scribejava/apis/service/TutByOAuthService.java | 13 ------------- .../scribejava/core/oauth/OAuth10aService.java | 12 ------------ .../scribejava/core/oauth/OAuth20Service.java | 13 ------------- .../github/scribejava/core/oauth/OAuthService.java | 13 ------------- 9 files changed, 118 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java index 565514efe..51e282310 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java @@ -5,7 +5,6 @@ import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; -import java.io.OutputStream; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.Formatter; @@ -14,18 +13,6 @@ public class FacebookService extends OAuth20Service { - /** - * @deprecated use {@link #FacebookService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java index c5bfb43f6..e1b146846 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java @@ -7,22 +7,9 @@ import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; -import java.io.OutputStream; public class ImgurOAuthService extends OAuth20Service { - /** - * @deprecated use {@link #ImgurOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java index aadfc58b5..f40727f53 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; -import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.security.MessageDigest; @@ -17,18 +16,6 @@ public class MailruOAuthService extends OAuth20Service { - /** - * @deprecated use {@link #MailruOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java index 59fc2f00b..bab20d3b7 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java @@ -5,26 +5,12 @@ import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; -import java.io.OutputStream; public class MicrosoftAzureActiveDirectoryService extends OAuth20Service { private static final String ACCEPTED_FORMAT = "application/json; odata=minimalmetadata; streaming=true; charset=utf-8"; - /** - * @deprecated use {@link #MicrosoftAzureActiveDirectoryService(com.github.scribejava.core.builder.api.DefaultApi20, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public MicrosoftAzureActiveDirectoryService(DefaultApi20 api, String apiKey, String apiSecret, String callback, - String scope, OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public MicrosoftAzureActiveDirectoryService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java index b2aa5cbda..34bd0fe89 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java @@ -7,7 +7,6 @@ import com.github.scribejava.core.model.Parameter; import com.github.scribejava.core.model.ParameterList; import com.github.scribejava.core.oauth.OAuth20Service; -import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; @@ -20,19 +19,6 @@ public class OdnoklassnikiOAuthService extends OAuth20Service { - /** - * @deprecated use {@link #OdnoklassnikiOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java index 17e64e7b5..82ded6c92 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java @@ -6,22 +6,9 @@ import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; -import java.io.OutputStream; public class TutByOAuthService extends OAuth20Service { - /** - * @deprecated use {@link #TutByOAuthService(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public TutByOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public TutByOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index 3986f45d5..b168a9f2c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -25,18 +25,6 @@ public class OAuth10aService extends OAuthService { private final OutputStream debugStream; private final DefaultApi10a api; - /** - * @deprecated use {@link #OAuth10aService(com.github.scribejava.core.builder.api.DefaultApi10a, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public OAuth10aService(DefaultApi10a api, String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, scope, debugStream, userAgent, httpClientConfig, httpClient); - } - public OAuth10aService(DefaultApi10a api, String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(apiKey, apiSecret, callback, scope, userAgent, httpClientConfig, httpClient); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 29df7e94e..80a46dbe1 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -20,7 +20,6 @@ import java.util.Map; import java.util.concurrent.ExecutionException; import com.github.scribejava.core.revoke.TokenTypeHint; -import java.io.OutputStream; public class OAuth20Service extends OAuthService { @@ -30,18 +29,6 @@ public class OAuth20Service extends OAuthService { private final String responseType; private final String state; - /** - * @deprecated use {@link #OAuth20Service(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 60c2d39aa..4b5ddb87c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -12,7 +12,6 @@ import java.io.File; import java.io.IOException; -import java.io.OutputStream; import java.util.ServiceLoader; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -41,18 +40,6 @@ public OAuthService(String apiKey, String apiSecret, String callback, String sco } } - /** - * @deprecated use {@link #OAuthService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public OAuthService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - this(apiKey, apiSecret, callback, scope, userAgent, httpClientConfig, httpClient); - } - private static HttpClient getClient(HttpClientConfig config) { for (HttpClientProvider provider : ServiceLoader.load(HttpClientProvider.class)) { final HttpClient client = provider.createClient(config); From 6787f8c50a776b4a39b1da9014021e1a84d6f93e Mon Sep 17 00:00:00 2001 From: zhangzhenli Date: Tue, 26 Jun 2018 16:12:35 +0800 Subject: [PATCH 092/481] =?UTF-8?q?Modify=20the=20enum=20as=20an=20abstrac?= =?UTF-8?q?t=20type,=20allowing=20custom=20implementations=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builder/api/ClientAuthenticationType.java | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java index 77212ce95..2faa81d46 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java @@ -12,28 +12,36 @@ * in it's part 2.3.1. Client Password
* https://tools.ietf.org/html/rfc6749#section-2.3.1 */ -public enum ClientAuthenticationType { - HTTP_BASIC_AUTHENTICATION_SCHEME { - private final Base64.Encoder base64Encoder = Base64.getEncoder(); +public abstract class ClientAuthenticationType { - @Override - public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) { - if (apiKey != null && apiSecret != null) { - request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + ' ' - + base64Encoder.encodeToString( + public static final ClientAuthenticationType HTTP_BASIC_AUTHENTICATION_SCHEME = + new ClientAuthenticationType() { + private final Base64.Encoder base64Encoder = Base64.getEncoder(); + + @Override + public void addClientAuthentication(OAuthRequest request, String apiKey, + String apiSecret) { + if (apiKey != null && apiSecret != null) { + request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + ' ' + + base64Encoder.encodeToString( String.format("%s:%s", apiKey, apiSecret).getBytes(Charset.forName("UTF-8")))); - } - } - }, - REQUEST_BODY { - @Override - public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) { - request.addParameter(OAuthConstants.CLIENT_ID, apiKey); - if (apiSecret != null) { - request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); - } - } - }; + } + } + }; + + public static final ClientAuthenticationType REQUEST_BODY = + new ClientAuthenticationType() { + + @Override + public void addClientAuthentication(OAuthRequest request, String apiKey, + String apiSecret) { + request.addParameter(OAuthConstants.CLIENT_ID, apiKey); + if (apiSecret != null) { + request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); + } + } + }; - public abstract void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret); + public abstract void addClientAuthentication(OAuthRequest request, String apiKey, + String apiSecret); } From 3e765687be1425f647bbd66a51a4b43a128cb970 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 26 Jul 2018 22:17:53 +0300 Subject: [PATCH 093/481] add Multipart functionality to JDK Http Client (thanks to https://github.com/eos1d3) --- changelog | 3 + .../AbstractAsyncOnlyHttpClient.java | 17 ++- .../core/httpclient/BodyPartPayload.java | 27 ++++ .../core/httpclient/HttpClient.java | 9 +- .../core/httpclient/MultipartPayload.java | 54 +++++++ .../core/httpclient/jdk/JDKHttpClient.java | 125 ++++++++------- .../scribejava/core/model/OAuthRequest.java | 144 +++++------------- .../scribejava/core/oauth/OAuthService.java | 7 +- .../httpclient/ahc/AhcHttpClient.java | 9 ++ .../httpclient/apache/ApacheHttpClient.java | 9 ++ .../httpclient/ning/NingHttpClient.java | 9 ++ .../httpclient/okhttp/OkHttpHttpClient.java | 29 +++- 12 files changed, 262 insertions(+), 180 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java diff --git a/changelog b/changelog index 56317a30f..0397fd622 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * add Multipart functionality to JDK Http Client (thanks to https://github.com/eos1d3) + [5.5.0] * fix error parsing for Fitbit (thanks to https://github.com/danmana) * optimize debug log performance impact on prod in OAuth1 and fix diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java index b8d6dead9..6f75ee6c1 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java @@ -13,6 +13,15 @@ public abstract class AbstractAsyncOnlyHttpClient implements HttpClient { @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents) throws InterruptedException, ExecutionException, IOException { + + return executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, null, + (OAuthRequest.ResponseConverter) null).get(); + } + + @Override + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + MultipartPayload bodyContents) throws InterruptedException, ExecutionException, IOException { + return executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, null, (OAuthRequest.ResponseConverter) null).get(); } @@ -20,6 +29,7 @@ public Response execute(String userAgent, Map headers, Verb http @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents) throws InterruptedException, ExecutionException, IOException { + return executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, null, (OAuthRequest.ResponseConverter) null).get(); } @@ -27,13 +37,8 @@ public Response execute(String userAgent, Map headers, Verb http @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, File bodyContents) throws InterruptedException, ExecutionException, IOException { + return executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, null, (OAuthRequest.ResponseConverter) null).get(); } - - @Override - public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, - OAuthRequest.MultipartPayloads multipartPayloads) throws InterruptedException, ExecutionException, IOException { - throw new UnsupportedOperationException("This HttpClient does not support Multipart payload for the moment"); - } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java new file mode 100644 index 000000000..3e8c6d47e --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java @@ -0,0 +1,27 @@ +package com.github.scribejava.core.httpclient; + +public class BodyPartPayload { + + private final String contentDisposition; + private final String contentType; + private final byte[] payload; + + public BodyPartPayload(String contentDisposition, String contentType, byte[] payload) { + this.contentDisposition = contentDisposition; + this.contentType = contentType; + this.payload = payload; + } + + public String getContentDisposition() { + return contentDisposition; + } + + public String getContentType() { + return contentType; + } + + public byte[] getPayload() { + return payload; + } + +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java index 41c5df134..40f9663f5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java @@ -12,6 +12,7 @@ import java.util.concurrent.Future; public interface HttpClient extends Closeable { + String DEFAULT_CONTENT_TYPE = "application/x-www-form-urlencoded"; String CONTENT_TYPE = "Content-Type"; String CONTENT_LENGTH = "Content-Length"; @@ -19,6 +20,10 @@ public interface HttpClient extends Closeable { Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter); + Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter); + Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter); @@ -27,9 +32,9 @@ Future executeAsync(String userAgent, Map headers, Verb h Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents) throws InterruptedException, ExecutionException, IOException; - + Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, - OAuthRequest.MultipartPayloads multipartPayloads) throws InterruptedException, ExecutionException, IOException; + MultipartPayload bodyContents) throws InterruptedException, ExecutionException, IOException; Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents) throws InterruptedException, ExecutionException, IOException; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java new file mode 100644 index 000000000..a1dbb5e7e --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java @@ -0,0 +1,54 @@ +package com.github.scribejava.core.httpclient; + +import java.util.ArrayList; +import java.util.List; + +/** + * The class containing more than one payload of multipart/form-data request + */ +public class MultipartPayload { + + private final String boundary; + private final List bodyParts = new ArrayList<>(); + + public MultipartPayload(String boundary) { + this.boundary = boundary; + } + + public byte[] getStartBoundary(BodyPartPayload bodyPart) { + return ("--" + boundary + "\r\n" + + "Content-Disposition: " + bodyPart.getContentDisposition() + "\r\n" + + (bodyPart.getContentType() == null ? "" : "Content-Type: " + bodyPart.getContentType() + "\r\n") + + "\r\n").getBytes(); + } + + public byte[] getEndBoundary() { + return ("\r\n--" + boundary + "--\r\n").getBytes(); + } + + public int getContentLength() { + int contentLength = 0; + for (BodyPartPayload bodyPart : bodyParts) { + contentLength += bodyPart.getPayload().length + + bodyPart.getContentDisposition().length(); + if (bodyPart.getContentType() != null) { + contentLength += 16 //length of constant portions of contentType header + + bodyPart.getContentType().length(); + } + } + + contentLength += (37 //length of constant portions of contentDisposition header, + //see getStartBoundary and getEndBoundary methods + + boundary.length() * 2 //twice. start and end parts + ) * bodyParts.size(); //for every part + return contentLength; + } + + public List getBodyParts() { + return bodyParts; + } + + public void addMultipartPayload(String contentDisposition, String contentType, byte[] payload) { + bodyParts.add(new BodyPartPayload(contentDisposition, contentType, payload)); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 3b4245671..cc810ded5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -1,7 +1,9 @@ package com.github.scribejava.core.httpclient.jdk; import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.httpclient.BodyPartPayload; import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.MultipartPayload; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; @@ -38,32 +40,46 @@ public void close() { @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - try { - final Response response = execute(userAgent, headers, httpVerb, completeUrl, bodyContents); - @SuppressWarnings("unchecked") - final T t = converter == null ? (T) response : converter.convert(response); - if (callback != null) { - callback.onCompleted(t); - } - return new JDKHttpFuture<>(t); - } catch (InterruptedException | ExecutionException | IOException e) { - callback.onThrowable(e); - return new JDKHttpFuture<>(e); - } + + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.BYTE_ARRAY, bodyContents, callback, + converter); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.MULTIPART, bodyContents, callback, + converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.STRING, bodyContents, callback, + converter); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + throw new UnsupportedOperationException("JDKHttpClient does not support File payload for the moment"); + } + + private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, BodyType bodyType, Object bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { try { - final Response response = execute(userAgent, headers, httpVerb, completeUrl, bodyContents); + final Response response = doExecute(userAgent, headers, httpVerb, completeUrl, bodyType, bodyContents); @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); if (callback != null) { callback.onCompleted(t); } return new JDKHttpFuture<>(t); - } catch (InterruptedException | ExecutionException | IOException e) { + } catch (IOException e) { if (callback != null) { callback.onThrowable(e); } @@ -72,15 +88,15 @@ public Future executeAsync(String userAgent, Map headers, } @Override - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - throw new UnsupportedOperationException("JDKHttpClient does not support File payload for the moment"); + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + byte[] bodyContents) throws InterruptedException, ExecutionException, IOException { + return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.BYTE_ARRAY, bodyContents); } @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, - byte[] bodyContents) throws InterruptedException, ExecutionException, IOException { - return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.BYTE_ARRAY, bodyContents); + MultipartPayload multipartPayloads) throws InterruptedException, ExecutionException, IOException { + return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.MULTIPART, multipartPayloads); } @Override @@ -92,15 +108,9 @@ public Response execute(String userAgent, Map headers, Verb http @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, File bodyContents) throws InterruptedException, ExecutionException, IOException { - throw new UnsupportedOperationException("JDKHttpClient do not support File payload for the moment"); + throw new UnsupportedOperationException("JDKHttpClient does not support File payload for the moment"); } - @Override - public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, - OAuthRequest.MultipartPayloads multipartPayloads) throws InterruptedException, ExecutionException, IOException { - return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.MULTIPART, multipartPayloads); - } - private Response doExecute(String userAgent, Map headers, Verb httpVerb, String completeUrl, BodyType bodyType, Object bodyContents) throws IOException { final HttpURLConnection connection = (HttpURLConnection) new URL(completeUrl).openConnection(); @@ -136,9 +146,9 @@ void setBody(HttpURLConnection connection, Object bodyContents, boolean requires } }, MULTIPART { - @Override + @Override void setBody(HttpURLConnection connection, Object bodyContents, boolean requiresBody) throws IOException { - addBody(connection, (OAuthRequest.MultipartPayloads) bodyContents, requiresBody); + addBody(connection, (MultipartPayload) bodyContents, requiresBody); } }, STRING { @@ -150,7 +160,6 @@ void setBody(HttpURLConnection connection, Object bodyContents, boolean requires abstract void setBody(HttpURLConnection connection, Object bodyContents, boolean requiresBody) throws IOException; - } private static Map parseHeaders(HttpURLConnection conn) { @@ -178,41 +187,41 @@ private static void addHeaders(HttpURLConnection connection, Map } } - /* - * Multipart implementation supporting more than one payload - * + /** + * Multipart implementation supporting more than one payload */ - private static void addBody(HttpURLConnection connection, OAuthRequest.MultipartPayloads multipartPayloads, boolean requiresBody) throws IOException { - int contentLength = multipartPayloads.getContentLength(); - System.out.println("length: " + contentLength); + private static void addBody(HttpURLConnection connection, MultipartPayload multipartPayload, boolean requiresBody) + throws IOException { + + final int contentLength = multipartPayload.getContentLength(); if (requiresBody || contentLength > 0) { - connection.setRequestProperty(CONTENT_LENGTH, String.valueOf(contentLength)); - if (connection.getRequestProperty(CONTENT_TYPE) == null) { - connection.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + final OutputStream os = prepareConnectionForBodyAndGetOutputStream(connection, contentLength); + + for (BodyPartPayload bodyPart : multipartPayload.getBodyParts()) { + os.write(multipartPayload.getStartBoundary(bodyPart)); + os.write(bodyPart.getPayload()); + os.write(multipartPayload.getEndBoundary()); } - System.out.println("content-length: " + connection.getRequestProperty(CONTENT_TYPE)); - connection.setDoOutput(true); - OutputStream os = connection.getOutputStream(); - - int totalParts = multipartPayloads.getMultipartPayloadList().size(); - for (int i = 0; i < totalParts; i++) { - os.write(multipartPayloads.getStartBoundary(i)); - os.write(multipartPayloads.getMultipartPayloadList().get(i).getPayload(), 0, multipartPayloads.getMultipartPayloadList().get(i).getLength()); - os.write(multipartPayloads.getEndBoundary(i)); - } - } - } - + } + } + private static void addBody(HttpURLConnection connection, byte[] content, boolean requiresBody) throws IOException { final int contentLength = content.length; if (requiresBody || contentLength > 0) { - connection.setRequestProperty(CONTENT_LENGTH, String.valueOf(contentLength)); - if (connection.getRequestProperty(CONTENT_TYPE) == null) { - connection.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); - } - connection.setDoOutput(true); - connection.getOutputStream().write(content); + prepareConnectionForBodyAndGetOutputStream(connection, contentLength).write(content); } } - + + private static OutputStream prepareConnectionForBodyAndGetOutputStream(HttpURLConnection connection, + int contentLength) throws IOException { + + connection.setRequestProperty(CONTENT_LENGTH, String.valueOf(contentLength)); + if (connection.getRequestProperty(CONTENT_TYPE) == null) { + connection.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); + + } + connection.setDoOutput(true); + return connection.getOutputStream(); + } + } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index 39b3dd73f..a33ac7d72 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -1,85 +1,22 @@ package com.github.scribejava.core.model; import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.httpclient.MultipartPayload; import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.Charset; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; - /** * The representation of an OAuth HttpRequest. */ public class OAuthRequest { - /* - * The class containing more than one payload of multipart/form-data request - */ - public class MultipartPayloads { - private String boundary; - private int contentLength; - private List multipartPayloadList; - - public MultipartPayloads(String boundary) { - this.boundary = boundary; - this.multipartPayloadList = new ArrayList<>(); - } - - public byte[] getStartBoundary(int index) { - MultipartPayload multipartPaayLoad = multipartPayloadList.get(index); - byte[] bytes = ("--" + boundary +"\r\n" - + "Content-Disposition: " + multipartPaayLoad.contentDisposition + "\r\n" - + (multipartPaayLoad == null ? "" : "Content-Type: " + multipartPaayLoad.contentType + "\r\n") - + "\r\n").getBytes(); - return bytes; - } - - public byte[] getEndBoundary(int index) { - return ("\r\n" - + "--" + boundary + "--\r\n").getBytes(); - } - - public int getContentLength() { - return contentLength; - } - - public void addContentLength(int length) { - this.contentLength += length; - } - - public List getMultipartPayloadList() { - return multipartPayloadList; - } - } - - public class MultipartPayload { - private String contentDisposition; - private String contentType; - private byte[] payload; - private int length; - - public MultipartPayload(String contentDisposition, String contentType, byte[] payload, int length) { - this.contentDisposition = contentDisposition; - this.contentType = contentType; - this.payload = payload; - this.length = length; - } - - public byte[] getPayload() { - return payload; - } - - public int getLength() { - return length; - } - } - - private static final String OAUTH_PREFIX = "oauth_"; + + private static final String OAUTH_PREFIX = "oauth_"; private final String url; private final Verb verb; @@ -92,7 +29,7 @@ public int getLength() { private String stringPayload; private byte[] byteArrayPayload; private File filePayload; - private MultipartPayloads multipartPayloads; + private MultipartPayload multipartPayload; private final Map oauthParameters = new HashMap<>(); @@ -188,43 +125,44 @@ public void addParameter(String key, String value) { querystringParams.add(key, value); } } - - /* + /** * Set boundary of multipart request - * + * * @param boundary can be any string */ - public void setMultipartBoundary(String boundary) { - multipartPayloads = new MultipartPayloads(boundary); - } - - - /* - * Add one multipart form-data payload to the request & increase the current Content-Length - * - * @param contentDisposition value of Content-Disposition header - * @param contentType value of Content-Type header - * @param payload data array containing the data to send - * @param length the max no of bytes to send - * - * Remarks: - * 57 and 37 are the length of constant portions of contentDisposition and/or contentType headers - * refer getStartBoundary and getEndBoundary for the constant - * - * Must be called after setMultipartBoundary method - */ - public void addMultipartPayload(String contentDisposition, String contentType, byte[] payload, int length) { - int contentLenght; - if (contentType == null) - contentLenght = 37 + multipartPayloads.boundary.length() * 2 + contentDisposition.length() + payload.length; - else - contentLenght = 53 + multipartPayloads.boundary.length() * 2 + contentDisposition.length() + + contentType.length() + payload.length; - multipartPayloads.addContentLength(contentLenght); - - multipartPayloads.getMultipartPayloadList().add(new MultipartPayload(contentDisposition, contentType, payload, length)); - } - + public void initMultipartBoundary(String boundary) { + multipartPayload = new MultipartPayload(boundary == null + ? Long.toString(System.currentTimeMillis()) + : boundary); + } + + /** + * init boundary of multipart request with default boundary + */ + public void initMultipartBoundary() { + initMultipartBoundary(null); + } + + /** + * you can invoke {@link #initMultipartBoundary(java.lang.String) } to set custom boundary + */ + public void addMultipartPayload(String contentDisposition, String contentType, byte[] payload) { + if (multipartPayload == null) { + initMultipartBoundary(); + } + multipartPayload.addMultipartPayload(contentDisposition, contentType, payload); + } + + public void setMultipartPayload(String contentDisposition, String contentType, byte[] payload) { + setMultipartPayload(null, contentDisposition, contentType, payload); + } + + public void setMultipartPayload(String boundary, String contentDisposition, String contentType, byte[] payload) { + initMultipartBoundary(boundary); + multipartPayload.addMultipartPayload(contentDisposition, contentType, payload); + } + /** * Set body payload. This method is used when the HTTP body is not a form-url-encoded string, but another thing. * Like for example XML. Note: The contents are not part of the OAuth signature @@ -260,7 +198,7 @@ private void resetPayload() { stringPayload = null; byteArrayPayload = null; filePayload = null; - multipartPayloads = null; + multipartPayload = null; } /** @@ -339,8 +277,8 @@ public byte[] getByteArrayPayload() { } } - public MultipartPayloads getMultipartPayloads() { - return multipartPayloads; + public MultipartPayload getMultipartPayloads() { + return multipartPayload; } public File getFilePayload() { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 3afd9855e..9f331a4ba 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -111,10 +111,9 @@ public Response execute(OAuthRequest request) throws InterruptedException, Execu return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), request.getStringPayload()); } else if (request.getMultipartPayloads() != null) { - return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), - request.getMultipartPayloads()); - } - else { + return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), + request.getMultipartPayloads()); + } else { return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), request.getByteArrayPayload()); } diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java index 623e5d49d..ebe551571 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java @@ -1,6 +1,7 @@ package com.github.scribejava.httpclient.ahc; import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; +import com.github.scribejava.core.httpclient.MultipartPayload; import com.github.scribejava.core.java8.Consumer; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; @@ -47,6 +48,14 @@ public Future executeAsync(String userAgent, Map headers, converter); } + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + + throw new UnsupportedOperationException("AhcHttpClient does not support MultipartPayload yet."); + } + @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, final String bodyContents, OAuthAsyncRequestCallback callback, diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java index 9075ff1ef..dc5a3607b 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java @@ -1,6 +1,7 @@ package com.github.scribejava.httpclient.apache; import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; +import com.github.scribejava.core.httpclient.MultipartPayload; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; @@ -53,6 +54,14 @@ public Future executeAsync(String userAgent, Map headers, return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, entity, callback, converter); } + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + + throw new UnsupportedOperationException("ApacheHttpClient does not support MultipartPayload yet."); + } + @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java index 90fc92fec..4463ea9e1 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java @@ -1,6 +1,7 @@ package com.github.scribejava.httpclient.ning; import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; +import com.github.scribejava.core.httpclient.MultipartPayload; import com.github.scribejava.core.java8.Consumer; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; @@ -53,6 +54,14 @@ public Future executeAsync(String userAgent, Map headers, converter); } + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + + throw new UnsupportedOperationException("NingHttpClient does not support MultipartPayload yet."); + } + @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, final String bodyContents, OAuthAsyncRequestCallback callback, diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 2582eab17..8436f11ed 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -1,10 +1,10 @@ package com.github.scribejava.httpclient.okhttp; import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.MultipartPayload; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.OAuthRequest.MultipartPayloads; import com.github.scribejava.core.model.Verb; import okhttp3.Call; import okhttp3.MediaType; @@ -55,13 +55,23 @@ public void close() throws IOException { @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.BYTE_ARRAY, bodyContents, callback, converter); } + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + + throw new UnsupportedOperationException("OKHttpClient does not support Multipart payload for the moment"); + } + @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.STRING, bodyContents, callback, converter); } @@ -69,6 +79,7 @@ public Future executeAsync(String userAgent, Map headers, @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.FILE, bodyContents, callback, converter); } @@ -85,27 +96,31 @@ private Future doExecuteAsync(String userAgent, Map heade @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents) throws InterruptedException, ExecutionException, IOException { + return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.BYTE_ARRAY, bodyContents); } + @Override + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + MultipartPayload bodyContents) throws InterruptedException, ExecutionException, IOException { + + throw new UnsupportedOperationException("OKHttpClient does not support Multipart payload for the moment"); + } + @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents) throws InterruptedException, ExecutionException, IOException { + return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.STRING, bodyContents); } @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, File bodyContents) throws InterruptedException, ExecutionException, IOException { + return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.FILE, bodyContents); } - @Override - public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, - MultipartPayloads multipartPayloads) throws InterruptedException, ExecutionException, IOException { - throw new UnsupportedOperationException("OKHttpClient does not support Multipart payload for the moment"); - } - private Response doExecute(String userAgent, Map headers, Verb httpVerb, String completeUrl, BodyType bodyType, Object bodyContents) throws IOException { final Call call = createCall(userAgent, headers, httpVerb, completeUrl, bodyType, bodyContents); From f96b6768cd2fcdb1f242e8de62e6737d4d0c4b02 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 26 Jul 2018 22:23:16 +0300 Subject: [PATCH 094/481] update maven deps --- pom.xml | 6 +++--- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index bc7d1d445..7f8d17a8f 100644 --- a/pom.xml +++ b/pom.xml @@ -71,7 +71,7 @@ com.squareup.okhttp3 mockwebserver - 3.10.0 + 3.11.0 test @@ -81,7 +81,7 @@ org.apache.felix maven-bundle-plugin - 3.5.0 + 3.5.1 bundle-manifest @@ -171,7 +171,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.0.0 + 3.0.1 UTF-8 diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 5b8d1116f..eacdd6208 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.4.7 + 2.5.2 com.github.scribejava diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index bd4c1bab4..e8815c53e 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -23,7 +23,7 @@ org.apache.httpcomponents httpclient - 4.5.5 + 4.5.6 org.apache.httpcomponents diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index bc10774b8..554be1054 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 3.10.0 + 3.11.0 com.github.scribejava From f4b9b8edf487f5bb59070c1a62702f6605a62e52 Mon Sep 17 00:00:00 2001 From: Jochen Klein Date: Fri, 27 Jul 2018 17:35:52 +0200 Subject: [PATCH 095/481] Implement response code check for OAuth2AccessTokenExtractor --- .../core/extractors/OAuth2AccessTokenExtractor.java | 4 ++++ .../extractors/OAuth2AccessTokenExtractorTest.java | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java index 8af44d3aa..22c1b90f0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.util.regex.Matcher; import java.util.regex.Pattern; + import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.Response; @@ -37,6 +38,9 @@ public static OAuth2AccessTokenExtractor instance() { */ @Override public OAuth2AccessToken extract(Response response) throws IOException { + if (response.getCode() != 200) { + throw new OAuthException("Response code not 200 but " + response.getCode()); + } final String body = response.getBody(); Preconditions.checkEmptyString(body, "Response body is incorrect. Can't extract a token from an empty string"); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java index 7f2cd4ddd..b123d90aa 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java @@ -58,6 +58,12 @@ public void shouldExtractTokenFromResponseWithManyParameters() throws IOExceptio assertEquals("foo1234", extracted.getAccessToken()); } + @Test(expected = OAuthException.class) + public void shouldThrowExceptionIfErrorResponse() throws IOException { + final String response = ""; + this.extractor.extract(error(response)); + } + @Test(expected = OAuthException.class) public void shouldThrowExceptionIfTokenIsAbsent() throws IOException { final String response = "&expires=5108"; @@ -78,4 +84,8 @@ public void shouldThrowExceptionIfResponseIsEmptyString() throws IOException { private static Response ok(String body) { return new Response(200, /* message */ null, /* headers */ Collections.emptyMap(), body); } + + private static Response error(final String body) { + return new Response(400, /* message */ null, /* headers */ Collections.emptyMap(), body); + } } From e46a55cca0bf2a4aee5488c32388d160ff65ff1d Mon Sep 17 00:00:00 2001 From: Jochen Klein Date: Fri, 27 Jul 2018 17:36:10 +0200 Subject: [PATCH 096/481] deliver OAuth exceptions from OAuthAsyncCompletionHandler - jdk http client --- .../scribejava/core/httpclient/jdk/JDKHttpClient.java | 2 +- .../scribejava/core/httpclient/jdk/JDKHttpFuture.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index cc810ded5..164a0520f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -79,7 +79,7 @@ private Future doExecuteAsync(String userAgent, Map heade callback.onCompleted(t); } return new JDKHttpFuture<>(t); - } catch (IOException e) { + } catch (Throwable e) { if (callback != null) { callback.onThrowable(e); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java index 1922d3aef..307c552c6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java @@ -11,10 +11,10 @@ */ public class JDKHttpFuture implements Future { - private final Exception exception; + private final Throwable exception; private final V response; - public JDKHttpFuture(Exception exception) { + public JDKHttpFuture(Throwable exception) { this(null, exception); } @@ -22,7 +22,7 @@ public JDKHttpFuture(V response) { this(response, null); } - private JDKHttpFuture(V response, Exception exception) { + private JDKHttpFuture(V response, Throwable exception) { this.response = response; this.exception = exception; } From 3a9ad1227c57c2cb26861ba9864a39155da27e55 Mon Sep 17 00:00:00 2001 From: Jochen Klein Date: Fri, 27 Jul 2018 17:36:24 +0200 Subject: [PATCH 097/481] deliver OAuth exceptions from OAuthAsyncCompletionHandler - apache httpclient --- .../apache/OAuthAsyncCompletionHandler.java | 25 ++++--- .../OauthAsyncCompletionHandlerTest.java | 75 +++++++++++++------ 2 files changed, 67 insertions(+), 33 deletions(-) diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java index 02fc7616f..b49dd8513 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java @@ -1,13 +1,5 @@ package com.github.scribejava.httpclient.apache; -import com.github.scribejava.core.model.OAuthAsyncRequestCallback; -import com.github.scribejava.core.model.OAuthRequest.ResponseConverter; -import com.github.scribejava.core.model.Response; -import org.apache.http.Header; -import org.apache.http.HttpResponse; -import org.apache.http.concurrent.FutureCallback; - -import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.concurrent.CancellationException; @@ -15,7 +7,15 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; + +import org.apache.http.Header; +import org.apache.http.HttpResponse; import org.apache.http.StatusLine; +import org.apache.http.concurrent.FutureCallback; + +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthRequest.ResponseConverter; +import com.github.scribejava.core.model.Response; public class OAuthAsyncCompletionHandler implements FutureCallback { @@ -23,7 +23,7 @@ public class OAuthAsyncCompletionHandler implements FutureCallback converter; private final CountDownLatch latch; private T result; - private Exception exception; + private Throwable exception; public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, ResponseConverter converter) { this.callback = callback; @@ -41,8 +41,9 @@ public void completed(HttpResponse httpResponse) { final StatusLine statusLine = httpResponse.getStatusLine(); - final Response response = new Response(statusLine.getStatusCode(), statusLine.getReasonPhrase(), - headersMap, httpResponse.getEntity().getContent()); + final Response response = + new Response(statusLine.getStatusCode(), statusLine.getReasonPhrase(), headersMap, + httpResponse.getEntity().getContent()); @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); @@ -50,7 +51,7 @@ public void completed(HttpResponse httpResponse) { if (callback != null) { callback.onCompleted(result); } - } catch (IOException e) { + } catch (Throwable e) { exception = e; if (callback != null) { callback.onThrowable(e); diff --git a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java index 3b0065c06..12c4588f3 100644 --- a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java @@ -1,8 +1,16 @@ package com.github.scribejava.httpclient.apache; -import com.github.scribejava.core.model.OAuthAsyncRequestCallback; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Response; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.concurrent.CancellationException; +import java.util.concurrent.ExecutionException; + import org.apache.http.HttpResponse; import org.apache.http.ProtocolVersion; import org.apache.http.entity.BasicHttpEntity; @@ -11,21 +19,17 @@ import org.junit.Before; import org.junit.Test; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.concurrent.CancellationException; -import java.util.concurrent.ExecutionException; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; public class OauthAsyncCompletionHandlerTest { private static final AllGoodResponseConverter ALL_GOOD_RESPONSE_CONVERTER = new AllGoodResponseConverter(); private static final ExceptionResponseConverter EXCEPTION_RESPONSE_CONVERTER = new ExceptionResponseConverter(); + private static final OAuthExceptionResponseConverter OAUTH_EXCEPTION_RESPONSE_CONVERTER = + new OAuthExceptionResponseConverter(); private OAuthAsyncCompletionHandler handler; private TestCallback callback; @@ -63,8 +67,8 @@ public void setUp() { @Test public void shouldReleaseLatchOnSuccess() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER); - final HttpResponse response = new BasicHttpResponse(new BasicStatusLine( - new ProtocolVersion("4", 1, 1), 200, "ok")); + final HttpResponse response = + new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); @@ -78,8 +82,8 @@ public void shouldReleaseLatchOnSuccess() throws Exception { @Test public void shouldReleaseLatchOnIOException() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, EXCEPTION_RESPONSE_CONVERTER); - final HttpResponse response = new BasicHttpResponse(new BasicStatusLine( - new ProtocolVersion("4", 1, 1), 200, "ok")); + final HttpResponse response = + new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); @@ -96,11 +100,32 @@ public void shouldReleaseLatchOnIOException() throws Exception { } } + @Test + public void shouldReportOAuthException() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, OAUTH_EXCEPTION_RESPONSE_CONVERTER); + final HttpResponse response = + new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); + final BasicHttpEntity entity = new BasicHttpEntity(); + entity.setContent(new ByteArrayInputStream(new byte[0])); + response.setEntity(entity); + handler.completed(response); + assertNull(callback.getResponse()); + assertNotNull(callback.getThrowable()); + assertTrue(callback.getThrowable() instanceof OAuthException); + // verify latch is released + try { + handler.getResult(); + fail(); + } catch (ExecutionException expected) { + // expected + } + } + @Test public void shouldReleaseLatchOnCancel() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER); - final HttpResponse response = new BasicHttpResponse(new BasicStatusLine( - new ProtocolVersion("4", 1, 1), 200, "ok")); + final HttpResponse response = + new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); @@ -120,8 +145,8 @@ public void shouldReleaseLatchOnCancel() throws Exception { @Test public void shouldReleaseLatchOnFailure() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER); - final HttpResponse response = new BasicHttpResponse(new BasicStatusLine( - new ProtocolVersion("4", 1, 1), 200, "ok")); + final HttpResponse response = + new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); @@ -153,4 +178,12 @@ public String convert(Response response) throws IOException { throw new IOException("Failed to convert"); } } + + private static class OAuthExceptionResponseConverter implements OAuthRequest.ResponseConverter { + + @Override + public String convert(Response response) throws IOException { + throw new OAuthException("bad oauth"); + } + } } From d7597b46f1384c7308ac28429d9a955ddeb71649 Mon Sep 17 00:00:00 2001 From: Jochen Klein Date: Fri, 27 Jul 2018 17:36:49 +0200 Subject: [PATCH 098/481] deliver OAuth exceptions from OAuthAsyncCompletionHandler - ning http client --- .../ning/OAuthAsyncCompletionHandler.java | 17 ++- .../httpclient/ning/MockResponse.java | 132 ++++++++++++++++++ .../ning/OauthAsyncCompletionHandlerTest.java | 98 +++++++++++++ 3 files changed, 241 insertions(+), 6 deletions(-) create mode 100644 scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/MockResponse.java create mode 100644 scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OauthAsyncCompletionHandlerTest.java diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java index c0aa14ecd..f4122c1e9 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java @@ -35,12 +35,17 @@ public T onCompleted(com.ning.http.client.Response ningResponse) throws IOExcept final Response response = new Response(ningResponse.getStatusCode(), ningResponse.getStatusText(), headersMap, ningResponse.getResponseBodyAsStream()); - @SuppressWarnings("unchecked") - final T t = converter == null ? (T) response : converter.convert(response); - if (callback != null) { - callback.onCompleted(t); + try { + @SuppressWarnings("unchecked") + final T t = converter == null ? (T) response : converter.convert(response); + if (callback != null) { + callback.onCompleted(t); + } + return t; + } catch (Throwable t) { + onThrowable(t); + return null; } - return t; } @Override @@ -49,4 +54,4 @@ public void onThrowable(Throwable t) { callback.onThrowable(t); } } -}; +} diff --git a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/MockResponse.java b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/MockResponse.java new file mode 100644 index 000000000..c432d9ed2 --- /dev/null +++ b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/MockResponse.java @@ -0,0 +1,132 @@ +package com.github.scribejava.httpclient.ning; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.util.List; + +import com.ning.http.client.FluentCaseInsensitiveStringsMap; +import com.ning.http.client.Response; +import com.ning.http.client.cookie.Cookie; +import com.ning.http.client.uri.Uri; + +/** + * + */ +public class MockResponse implements Response { + + private final int statusCode; + private final String statusText; + private final FluentCaseInsensitiveStringsMap headers; + private final byte[] body; + + /** + * @param statusCode + * @param statusText + * @param body + */ + public MockResponse(int statusCode, String statusText, FluentCaseInsensitiveStringsMap headers, + byte[] body) { + super(); + this.statusCode = statusCode; + this.statusText = statusText; + this.headers = headers; + this.body = body; + } + + @Override + public int getStatusCode() { + return statusCode; + } + + @Override + public String getStatusText() { + return statusText; + } + + @Override + public byte[] getResponseBodyAsBytes() throws IOException { + return body; + } + + @Override + public ByteBuffer getResponseBodyAsByteBuffer() throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public InputStream getResponseBodyAsStream() throws IOException { + return new ByteArrayInputStream(getResponseBodyAsBytes()); + } + + @Override + public String getResponseBodyExcerpt(final int maxLength, final String charset) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public String getResponseBodyExcerpt(final int maxLength) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public String getResponseBody(final String charset) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public String getResponseBody() throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public Uri getUri() { + throw new UnsupportedOperationException(); + } + + @Override + public String getContentType() { + throw new UnsupportedOperationException(); + } + + @Override + public String getHeader(final String name) { + return headers.getFirstValue(name); + } + + @Override + public List getHeaders(final String name) { + return headers.get(name); + } + + @Override + public FluentCaseInsensitiveStringsMap getHeaders() { + return headers; + } + + @Override + public boolean isRedirected() { + throw new UnsupportedOperationException(); + } + + @Override + public List getCookies() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean hasResponseStatus() { + return true; + } + + @Override + public boolean hasResponseHeaders() { + return !this.headers.isEmpty(); + } + + @Override + public boolean hasResponseBody() { + return body != null && body.length > 0; + } +} diff --git a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OauthAsyncCompletionHandlerTest.java b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OauthAsyncCompletionHandlerTest.java new file mode 100644 index 000000000..efc516d68 --- /dev/null +++ b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OauthAsyncCompletionHandlerTest.java @@ -0,0 +1,98 @@ +package com.github.scribejava.httpclient.ning; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import org.junit.Before; +import org.junit.Test; + +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.ning.http.client.FluentCaseInsensitiveStringsMap; + +public class OauthAsyncCompletionHandlerTest { + + private static final AllGoodResponseConverter ALL_GOOD_RESPONSE_CONVERTER = new AllGoodResponseConverter(); + private static final OAuthExceptionResponseConverter OAUTH_EXCEPTION_RESPONSE_CONVERTER = + new OAuthExceptionResponseConverter(); + + private OAuthAsyncCompletionHandler handler; + private TestCallback callback; + + private static class TestCallback implements OAuthAsyncRequestCallback { + + private Throwable throwable; + private String response; + + @Override + public void onCompleted(String response) { + this.response = response; + } + + @Override + public void onThrowable(Throwable throwable) { + this.throwable = throwable; + } + + public Throwable getThrowable() { + return throwable; + } + + public String getResponse() { + return response; + } + + } + + @Before + public void setUp() { + callback = new TestCallback(); + } + + @Test + public void shouldReleaseLatchOnSuccess() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER); + + final com.ning.http.client.Response response = + new MockResponse(200, "ok", new FluentCaseInsensitiveStringsMap(), new byte[0]); + handler.onCompleted(response); + assertNotNull(callback.getResponse()); + assertNull(callback.getThrowable()); + // verify latch is released + assertEquals("All good", callback.getResponse()); + } + + @Test + public void shouldReportOAuthException() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, OAUTH_EXCEPTION_RESPONSE_CONVERTER); + + final com.ning.http.client.Response response = + new MockResponse(200, "ok", new FluentCaseInsensitiveStringsMap(), new byte[0]); + handler.onCompleted(response); + assertNull(callback.getResponse()); + assertNotNull(callback.getThrowable()); + assertTrue(callback.getThrowable() instanceof OAuthException); + } + + private static class AllGoodResponseConverter implements OAuthRequest.ResponseConverter { + + @Override + public String convert(Response response) throws IOException { + return "All good"; + } + } + + private static class OAuthExceptionResponseConverter implements OAuthRequest.ResponseConverter { + + @Override + public String convert(Response response) throws IOException { + throw new OAuthException("bad oauth"); + } + } +} From b1afe2ffc3648908f5114b933243ec3b478aa1f9 Mon Sep 17 00:00:00 2001 From: Jochen Klein Date: Fri, 27 Jul 2018 17:37:02 +0200 Subject: [PATCH 099/481] deliver OAuth exceptions from OAuthAsyncCompletionHandler - ok http client --- .../okhttp/OAuthAsyncCompletionHandler.java | 19 +- .../httpclient/okhttp/OkHttpFuture.java | 15 +- .../httpclient/okhttp/MockCall.java | 66 ++++++ .../OauthAsyncCompletionHandlerTest.java | 189 ++++++++++++++++++ 4 files changed, 281 insertions(+), 8 deletions(-) create mode 100644 scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java create mode 100644 scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OauthAsyncCompletionHandlerTest.java diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java index af59abbb5..bd613138a 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java @@ -24,6 +24,7 @@ class OAuthAsyncCompletionHandler implements Callback { @Override public void onFailure(Call call, IOException e) { try { + this.okHttpFuture.setError(e); if (callback != null) { callback.onThrowable(e); } @@ -37,12 +38,18 @@ public void onResponse(Call call, okhttp3.Response okHttpResponse) throws IOExce try { final Response response = OkHttpHttpClient.convertResponse(okHttpResponse); - - @SuppressWarnings("unchecked") - final T t = converter == null ? (T) response : converter.convert(response); - okHttpFuture.setResult(t); - if (callback != null) { - callback.onCompleted(t); + try { + @SuppressWarnings("unchecked") + final T t = converter == null ? (T) response : converter.convert(response); + okHttpFuture.setResult(t); + if (callback != null) { + callback.onCompleted(t); + } + } catch (Throwable t) { + okHttpFuture.setError(t); + if (callback != null) { + callback.onThrowable(t); + } } } finally { okHttpFuture.finish(); diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpFuture.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpFuture.java index ebf459260..a75617dd4 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpFuture.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpFuture.java @@ -5,6 +5,7 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; + import okhttp3.Call; public class OkHttpFuture implements Future { @@ -12,6 +13,7 @@ public class OkHttpFuture implements Future { private final CountDownLatch latch = new CountDownLatch(1); private final Call call; private T result; + private Throwable t; public OkHttpFuture(Call call) { this.call = call; @@ -33,19 +35,28 @@ public boolean isDone() { return call.isExecuted(); } + public void setError(Throwable t) { + this.t = t; + } + @Override public T get() throws InterruptedException, ExecutionException { latch.await(); + if (t != null) { + throw new ExecutionException(t); + } return result; } @Override public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { if (latch.await(timeout, unit)) { + if (t != null) { + throw new ExecutionException(t); + } return result; - } else { - throw new TimeoutException(); } + throw new TimeoutException(); } void finish() { diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java new file mode 100644 index 000000000..9b4b1d447 --- /dev/null +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java @@ -0,0 +1,66 @@ +package com.github.scribejava.httpclient.okhttp; + +import java.io.IOException; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.ArrayList; +import java.util.Collection; + +import okhttp3.Call; +import okhttp3.Callback; + +/** + * the only reason, this is a dynamic proxy is, that checkstyle forbids implementing clone()! + */ +public class MockCall implements InvocationHandler { + + private final Collection callbacks; + private boolean canceled; + + public MockCall() { + this(new ArrayList()); + } + + private MockCall(Collection callbacks) { + this.callbacks = new ArrayList<>(callbacks); + } + + public void enqueue(Callback responseCallback) { + callbacks.add(responseCallback); + } + + public void cancel(Call proxy) { + canceled = true; + for (Callback callback : callbacks) { + callback.onFailure(proxy, new IOException("Canceled")); + } + } + + public boolean isCanceled() { + return canceled; + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + switch (method.getName()) { + case "enqueue": + enqueue((Callback) args[0]); + return null; + case "cancel": + cancel((Call) proxy); + return null; + case "isCanceled": + return isCanceled(); + default: + throw new UnsupportedOperationException(method.toString()); + } + } + + /** + * @return + */ + public static Call create() { + return (Call) Proxy.newProxyInstance(Call.class.getClassLoader(), new Class[] { Call.class }, new MockCall()); + } +} diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OauthAsyncCompletionHandlerTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OauthAsyncCompletionHandlerTest.java new file mode 100644 index 000000000..5181487ff --- /dev/null +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OauthAsyncCompletionHandlerTest.java @@ -0,0 +1,189 @@ +package com.github.scribejava.httpclient.okhttp; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +import org.junit.Before; +import org.junit.Test; + +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; + +import okhttp3.Call; +import okhttp3.MediaType; +import okhttp3.Protocol; +import okhttp3.Request; +import okhttp3.ResponseBody; + +public class OauthAsyncCompletionHandlerTest { + + private static final AllGoodResponseConverter ALL_GOOD_RESPONSE_CONVERTER = new AllGoodResponseConverter(); + private static final ExceptionResponseConverter EXCEPTION_RESPONSE_CONVERTER = new ExceptionResponseConverter(); + private static final OAuthExceptionResponseConverter OAUTH_EXCEPTION_RESPONSE_CONVERTER = + new OAuthExceptionResponseConverter(); + + private OAuthAsyncCompletionHandler handler; + private Call call; + private OkHttpFuture future; + private TestCallback callback; + + private static class TestCallback implements OAuthAsyncRequestCallback { + + private Throwable throwable; + private String response; + + @Override + public void onCompleted(String response) { + this.response = response; + } + + @Override + public void onThrowable(Throwable throwable) { + this.throwable = throwable; + } + + public Throwable getThrowable() { + return throwable; + } + + public String getResponse() { + return response; + } + + } + + @Before + public void setUp() { + callback = new TestCallback(); + call = MockCall.create(); + future = new OkHttpFuture<>(call); + } + + @Test + public void shouldReleaseLatchOnSuccess() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER, future); + call.enqueue(handler); + + final okhttp3.Request request = new Request.Builder().url("http://localhost/").build(); + final okhttp3.Response response = + new okhttp3.Response.Builder().request(request).protocol(Protocol.HTTP_1_1).code(200).message("ok") + .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])).build(); + handler.onResponse(call, response); + assertNotNull(callback.getResponse()); + assertNull(callback.getThrowable()); + // verify latch is released + assertEquals("All good", future.get()); + } + + @Test + public void shouldReleaseLatchOnIOException() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, EXCEPTION_RESPONSE_CONVERTER, future); + call.enqueue(handler); + + final okhttp3.Request request = new Request.Builder().url("http://localhost/").build(); + final okhttp3.Response response = + new okhttp3.Response.Builder().request(request).protocol(Protocol.HTTP_1_1).code(200).message("ok") + .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])).build(); + handler.onResponse(call, response); + assertNull(callback.getResponse()); + assertNotNull(callback.getThrowable()); + assertTrue(callback.getThrowable() instanceof IOException); + // verify latch is released + try { + future.get(); + fail(); + } catch (ExecutionException expected) { + // expected + } + } + + @Test + public void shouldReportOAuthException() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, OAUTH_EXCEPTION_RESPONSE_CONVERTER, future); + call.enqueue(handler); + + final okhttp3.Request request = new Request.Builder().url("http://localhost/").build(); + final okhttp3.Response response = + new okhttp3.Response.Builder().request(request).protocol(Protocol.HTTP_1_1).code(200).message("ok") + .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])).build(); + handler.onResponse(call, response); + assertNull(callback.getResponse()); + assertNotNull(callback.getThrowable()); + assertTrue(callback.getThrowable() instanceof OAuthException); + // verify latch is released + try { + future.get(); + fail(); + } catch (ExecutionException expected) { + // expected + } + } + + @Test + public void shouldReleaseLatchOnCancel() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER, future); + call.enqueue(handler); + + future.cancel(true); + assertNull(callback.getResponse()); + assertNotNull(callback.getThrowable()); + assertTrue(callback.getThrowable() instanceof IOException); + // verify latch is released + try { + future.get(); + fail(); + } catch (ExecutionException expected) { + // expected + } + } + + @Test + public void shouldReleaseLatchOnFailure() throws Exception { + handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER, future); + call.enqueue(handler); + + handler.onFailure(call, new IOException()); + assertNull(callback.getResponse()); + assertNotNull(callback.getThrowable()); + assertTrue(callback.getThrowable() instanceof IOException); + // verify latch is released + try { + future.get(); + fail(); + } catch (ExecutionException expected) { + // expected + } + } + + private static class AllGoodResponseConverter implements OAuthRequest.ResponseConverter { + + @Override + public String convert(Response response) throws IOException { + return "All good"; + } + } + + private static class ExceptionResponseConverter implements OAuthRequest.ResponseConverter { + + @Override + public String convert(Response response) throws IOException { + throw new IOException("Failed to convert"); + } + } + + private static class OAuthExceptionResponseConverter implements OAuthRequest.ResponseConverter { + + @Override + public String convert(Response response) throws IOException { + throw new OAuthException("bad oauth"); + } + } +} From 55fbe2f6f3d8e2df50953956de51644812d31ce7 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 3 Aug 2018 17:03:28 +0300 Subject: [PATCH 100/481] switch OAuth2 ClientAuthenticationType from enum to interface to be extensible according to https://tools.ietf.org/html/rfc6749#section-2.3.2 (thanks to https://github.com/zawn) --- changelog | 2 + .../github/scribejava/apis/AutomaticAPI.java | 8 +-- .../github/scribejava/apis/FacebookApi.java | 7 ++- .../com/github/scribejava/apis/HHApi.java | 7 ++- .../github/scribejava/apis/LinkedInApi20.java | 7 ++- .../MicrosoftAzureActiveDirectoryApi.java | 7 ++- .../scribejava/apis/OdnoklassnikiApi.java | 7 ++- .../github/scribejava/apis/PinterestApi.java | 7 ++- .../github/scribejava/apis/SalesforceApi.java | 7 ++- .../github/scribejava/apis/VkontakteApi.java | 7 ++- .../builder/api/ClientAuthenticationType.java | 60 +++++++++---------- .../core/builder/api/DefaultApi20.java | 18 ++++++ .../scribejava/core/oauth/OAuth20Service.java | 10 ++-- .../ClientAuthentication.java | 17 ++++++ .../HttpBasicAuthenticationScheme.java | 40 +++++++++++++ .../RequestBodyAuthenticationScheme.java | 34 +++++++++++ 16 files changed, 179 insertions(+), 66 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/ClientAuthentication.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/HttpBasicAuthenticationScheme.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/RequestBodyAuthenticationScheme.java diff --git a/changelog b/changelog index 0397fd622..c1a5c41f1 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,7 @@ [SNAPSHOT] * add Multipart functionality to JDK Http Client (thanks to https://github.com/eos1d3) + * switch OAuth2 ClientAuthenticationType from enum to interface to be extensible according to + https://tools.ietf.org/html/rfc6749#section-2.3.2 (thanks to https://github.com/zawn) [5.5.0] * fix error parsing for Fitbit (thanks to https://github.com/danmana) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java index 479fc5d59..58c82e040 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/AutomaticAPI.java @@ -1,7 +1,8 @@ package com.github.scribejava.apis; -import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; public class AutomaticAPI extends DefaultApi20 { @@ -37,8 +38,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.REQUEST_BODY; + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); } - } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index 463a44d6c..fb0668eb1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -2,13 +2,14 @@ import com.github.scribejava.apis.facebook.FacebookAccessTokenJsonExtractor; import com.github.scribejava.apis.service.FacebookService; -import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; import java.io.OutputStream; /** @@ -65,8 +66,8 @@ public TokenExtractor getAccessTokenExtractor() { } @Override - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.REQUEST_BODY; + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java index f1f307155..bd1224fe6 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java @@ -1,7 +1,8 @@ package com.github.scribejava.apis; -import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; public class HHApi extends DefaultApi20 { @@ -27,7 +28,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.REQUEST_BODY; + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java index 97f78b354..36d4ab702 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LinkedInApi20.java @@ -1,7 +1,8 @@ package com.github.scribejava.apis; -import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; public class LinkedInApi20 extends DefaultApi20 { @@ -27,7 +28,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.REQUEST_BODY; + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java index 223a88b1c..2c793ae14 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java @@ -1,10 +1,11 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.service.MicrosoftAzureActiveDirectoryService; -import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; import java.io.OutputStream; /** @@ -57,7 +58,7 @@ public MicrosoftAzureActiveDirectoryService createService(String apiKey, String } @Override - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.REQUEST_BODY; + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index c21983fa3..e7db8838d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -1,11 +1,12 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.service.OdnoklassnikiOAuthService; -import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; import java.io.OutputStream; public class OdnoklassnikiApi extends DefaultApi20 { @@ -45,7 +46,7 @@ public OAuth2SignatureType getSignatureType() { } @Override - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.REQUEST_BODY; + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java index f915aa605..70ef1caff 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PinterestApi.java @@ -1,7 +1,8 @@ package com.github.scribejava.apis; -import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; public class PinterestApi extends DefaultApi20 { @@ -27,7 +28,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.REQUEST_BODY; + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java index 0b1c3c11f..afd2eae5f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java @@ -3,11 +3,12 @@ import javax.net.ssl.SSLContext; import com.github.scribejava.apis.salesforce.SalesforceJsonTokenExtractor; -import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; import java.io.IOException; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; @@ -132,7 +133,7 @@ public static void initTLSv11orUpper() throws NoSuchAlgorithmException, KeyManag } @Override - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.REQUEST_BODY; + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index 1654ff34a..ff11d902c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -1,12 +1,13 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.vk.VKJsonTokenExtractor; -import com.github.scribejava.core.builder.api.ClientAuthenticationType; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; public class VkontakteApi extends DefaultApi20 { @@ -45,8 +46,8 @@ public OAuth2SignatureType getSignatureType() { } @Override - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.REQUEST_BODY; + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); } @Override diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java index 2faa81d46..097ba1081 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java @@ -1,9 +1,8 @@ package com.github.scribejava.core.builder.api; -import com.github.scribejava.core.java8.Base64; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; -import java.nio.charset.Charset; +import com.github.scribejava.core.oauth2.clientauthentication.HttpBasicAuthenticationScheme; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; /** * Represents
@@ -11,37 +10,32 @@ * https://tools.ietf.org/html/rfc6749#section-2.3
* in it's part 2.3.1. Client Password
* https://tools.ietf.org/html/rfc6749#section-2.3.1 + * + * @deprecated use {@link com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication} */ -public abstract class ClientAuthenticationType { +@Deprecated +public enum ClientAuthenticationType { + /** + * @deprecated use {@link com.github.scribejava.core.oauth2.clientauthentication.HttpBasicAuthenticationScheme} + */ + @Deprecated + HTTP_BASIC_AUTHENTICATION_SCHEME { - public static final ClientAuthenticationType HTTP_BASIC_AUTHENTICATION_SCHEME = - new ClientAuthenticationType() { - private final Base64.Encoder base64Encoder = Base64.getEncoder(); + @Override + public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) { + HttpBasicAuthenticationScheme.instance().addClientAuthentication(request, apiKey, apiSecret); + } + }, + /** + * @deprecated use {@link com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme} + */ + @Deprecated + REQUEST_BODY { + @Override + public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) { + RequestBodyAuthenticationScheme.instance().addClientAuthentication(request, apiKey, apiSecret); + } + }; - @Override - public void addClientAuthentication(OAuthRequest request, String apiKey, - String apiSecret) { - if (apiKey != null && apiSecret != null) { - request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + ' ' - + base64Encoder.encodeToString( - String.format("%s:%s", apiKey, apiSecret).getBytes(Charset.forName("UTF-8")))); - } - } - }; - - public static final ClientAuthenticationType REQUEST_BODY = - new ClientAuthenticationType() { - - @Override - public void addClientAuthentication(OAuthRequest request, String apiKey, - String apiSecret) { - request.addParameter(OAuthConstants.CLIENT_ID, apiKey); - if (apiSecret != null) { - request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); - } - } - }; - - public abstract void addClientAuthentication(OAuthRequest request, String apiKey, - String apiSecret); + public abstract void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 5555faac3..b429142a6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -9,6 +9,9 @@ import com.github.scribejava.core.model.ParameterList; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.HttpBasicAuthenticationScheme; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; import java.io.OutputStream; import java.util.Map; @@ -109,6 +112,21 @@ public OAuth2SignatureType getSignatureType() { return OAuth2SignatureType.BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD; } + public ClientAuthentication getClientAuthentication() { + switch (getClientAuthenticationType()) { + case HTTP_BASIC_AUTHENTICATION_SCHEME: + return HttpBasicAuthenticationScheme.instance(); + case REQUEST_BODY: + return RequestBodyAuthenticationScheme.instance(); + default: + throw new IllegalStateException("there was no such Client Authentication Type"); + } + } + + /** + * @deprecated use {@link #getClientAuthentication() } + */ + @Deprecated public ClientAuthenticationType getClientAuthenticationType() { return ClientAuthenticationType.HTTP_BASIC_AUTHENTICATION_SCHEME; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 80a46dbe1..5b10849af 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -105,7 +105,7 @@ public Future getAccessToken(String code, protected OAuthRequest createAccessTokenRequest(String code) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - api.getClientAuthenticationType().addClientAuthentication(request, getApiKey(), getApiSecret()); + api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); request.addParameter(OAuthConstants.CODE, code); request.addParameter(OAuthConstants.REDIRECT_URI, getCallback()); @@ -149,7 +149,7 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken) { } final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint()); - api.getClientAuthenticationType().addClientAuthentication(request, getApiKey(), getApiSecret()); + api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); final String scope = getScope(); if (scope != null) { @@ -199,7 +199,7 @@ protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, St request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.PASSWORD); - api.getClientAuthenticationType().addClientAuthentication(request, getApiKey(), getApiSecret()); + api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); return request; } @@ -232,7 +232,7 @@ public Future getAccessTokenClientCredentialsGrant( protected OAuthRequest createAccessTokenClientCredentialsGrantRequest() { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - api.getClientAuthenticationType().addClientAuthentication(request, getApiKey(), getApiSecret()); + api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); final String scope = getScope(); if (scope != null) { @@ -308,7 +308,7 @@ public DefaultApi20 getApi() { protected OAuthRequest createRevokeTokenRequest(String tokenToRevoke, TokenTypeHint tokenTypeHint) { final OAuthRequest request = new OAuthRequest(Verb.POST, api.getRevokeTokenEndpoint()); - api.getClientAuthenticationType().addClientAuthentication(request, getApiKey(), getApiSecret()); + api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); request.addParameter("token", tokenToRevoke); if (tokenTypeHint != null) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/ClientAuthentication.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/ClientAuthentication.java new file mode 100644 index 000000000..54fdb5de6 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/ClientAuthentication.java @@ -0,0 +1,17 @@ +package com.github.scribejava.core.oauth2.clientauthentication; + +import com.github.scribejava.core.model.OAuthRequest; + +/** + * Represents
+ * 2.3. Client Authentication
+ * https://tools.ietf.org/html/rfc6749#section-2.3 + *
+ * just implement this interface to implement "2.3.2. Other Authentication Methods"
+ * https://tools.ietf.org/html/rfc6749#section-2.3.2 + * + */ +public interface ClientAuthentication { + + void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/HttpBasicAuthenticationScheme.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/HttpBasicAuthenticationScheme.java new file mode 100644 index 000000000..509869d51 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/HttpBasicAuthenticationScheme.java @@ -0,0 +1,40 @@ +package com.github.scribejava.core.oauth2.clientauthentication; + +import com.github.scribejava.core.java8.Base64; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import java.nio.charset.Charset; + +/** + * 2.3. Client Authentication
+ * 2.3.1. Client Password
+ * https://tools.ietf.org/html/rfc6749#section-2.3.1 + *
+ * НTTP Basic authentication scheme + */ +public class HttpBasicAuthenticationScheme implements ClientAuthentication { + + private final Base64.Encoder base64Encoder = Base64.getEncoder(); + + protected HttpBasicAuthenticationScheme() { + } + + private static class InstanceHolder { + + private static final HttpBasicAuthenticationScheme INSTANCE = new HttpBasicAuthenticationScheme(); + } + + public static HttpBasicAuthenticationScheme instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) { + if (apiKey != null && apiSecret != null) { + request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + ' ' + + base64Encoder.encodeToString( + String.format("%s:%s", apiKey, apiSecret).getBytes(Charset.forName("UTF-8")))); + } + } + +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/RequestBodyAuthenticationScheme.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/RequestBodyAuthenticationScheme.java new file mode 100644 index 000000000..5e91affa7 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/RequestBodyAuthenticationScheme.java @@ -0,0 +1,34 @@ +package com.github.scribejava.core.oauth2.clientauthentication; + +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; + +/** + * 2.3. Client Authentication
+ * 2.3.1. Client Password
+ * https://tools.ietf.org/html/rfc6749#section-2.3.1 + *
+ * request-body authentication scheme + */ +public class RequestBodyAuthenticationScheme implements ClientAuthentication { + + protected RequestBodyAuthenticationScheme() { + } + + private static class InstanceHolder { + + private static final RequestBodyAuthenticationScheme INSTANCE = new RequestBodyAuthenticationScheme(); + } + + public static RequestBodyAuthenticationScheme instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) { + request.addParameter(OAuthConstants.CLIENT_ID, apiKey); + if (apiSecret != null) { + request.addParameter(OAuthConstants.CLIENT_SECRET, apiSecret); + } + } +} From 7608d4312ee2cb1c0aab11a5c9bc520671559eaf Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 3 Aug 2018 17:06:31 +0300 Subject: [PATCH 101/481] update httpasyncclient --- scribejava-httpclient-apache/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index e8815c53e..0043155d0 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -28,7 +28,7 @@ org.apache.httpcomponents httpasyncclient - 4.1.3 + 4.1.4 com.github.scribejava From b867f072a2818ffba37095cd83b964e4b7488eda Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 13 Aug 2018 18:36:53 +0300 Subject: [PATCH 102/481] =?UTF-8?q?remove=20support=20for=20obsolete=20Net?= =?UTF-8?q?Ease=20(http://www.163.com/)=20and=20sohu=20=E6=90=9C=E7=8B=90?= =?UTF-8?q?=20(http://www.sohu.com/)=20(thanks=20to=20https://github.com/z?= =?UTF-8?q?awn)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 - changelog | 1 + .../scribejava/apis/NeteaseWeibooApi.java | 60 ---------------- .../github/scribejava/apis/SohuWeiboApi.java | 36 ---------- .../apis/examples/NeteaseWeiboExample.java | 72 ------------------- .../apis/examples/SohuWeiboExample.java | 72 ------------------- 6 files changed, 1 insertion(+), 242 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java delete mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java delete mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java diff --git a/README.md b/README.md index 9b9cf3b58..29d1833dd 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,6 @@ ScribeJava support out-of-box several HTTP clients: * MediaWiki (https://www.mediawiki.org/) * Meetup (http://www.meetup.com/) * NAVER (http://www.naver.com/) -* NetEase (http://www.163.com/) * Odnoklassniki Одноклассники (http://ok.ru/) * Pinterest (https://www.pinterest.com/) * 500px (https://500px.com/) @@ -74,7 +73,6 @@ ScribeJava support out-of-box several HTTP clients: * Salesforce (https://www.salesforce.com/) * Sina (http://www.sina.com.cn/ http://weibo.com/login.php) * Skyrock (http://skyrock.com/) -* sohu 搜狐 (http://www.sohu.com/) * StackExchange (http://stackexchange.com/) * The Things Network (v1-staging and v2-preview) (https://www.thethingsnetwork.org/) * Trello (https://trello.com/) diff --git a/changelog b/changelog index c1a5c41f1..b711f672e 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,5 @@ [SNAPSHOT] + * remove support for obsolete NetEase (http://www.163.com/) and sohu 搜狐 (http://www.sohu.com/) (thanks to https://github.com/zawn) * add Multipart functionality to JDK Http Client (thanks to https://github.com/eos1d3) * switch OAuth2 ClientAuthenticationType from enum to interface to be extensible according to https://tools.ietf.org/html/rfc6749#section-2.3.2 (thanks to https://github.com/zawn) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java deleted file mode 100644 index 2446b5f58..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NeteaseWeibooApi.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; -import com.github.scribejava.core.model.OAuth1Token; - -public class NeteaseWeibooApi extends DefaultApi10a { - - private static final String REQUEST_TOKEN_URL = "http://api.t.163.com/oauth/request_token"; - private static final String ACCESS_TOKEN_URL = "http://api.t.163.com/oauth/access_token"; - private static final String AUTHORIZE_URL = "http://api.t.163.com/oauth/authorize"; - private static final String AUTHENTICATE_URL = "http://api.t.163.com/oauth/authenticate?oauth_token=%s"; - - protected NeteaseWeibooApi() { - } - - private static class InstanceHolder { - private static final NeteaseWeibooApi INSTANCE = new NeteaseWeibooApi(); - } - - public static NeteaseWeibooApi instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getRequestTokenEndpoint() { - return REQUEST_TOKEN_URL; - } - - @Override - public String getAccessTokenEndpoint() { - return ACCESS_TOKEN_URL; - } - - /** - * this method will ignore your callback if you're creating a desktop client please choose this url else your can - * call getAuthenticateUrl - * - * via - * http://open.t.163.com/wiki/index.php?title=%E8%AF%B7%E6%B1%82%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83Token(oauth/authorize) - * @return url to redirect user to (to get code) - */ - @Override - public String getAuthorizationBaseUrl() { - return AUTHORIZE_URL; - } - - /** - * this method is for web client with callback url if you're creating a desktop client please call - * getAuthorizationUrl - * - * via - * http://open.t.163.com/wiki/index.php?title=%E8%AF%B7%E6%B1%82%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83Token(oauth/authenticate) - * - * @param requestToken Token - * @return String - */ - public String getAuthenticateUrl(OAuth1Token requestToken) { - return String.format(AUTHENTICATE_URL, requestToken.getToken()); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java deleted file mode 100644 index a8447efd0..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SohuWeiboApi.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi10a; - -public class SohuWeiboApi extends DefaultApi10a { - - private static final String REQUEST_TOKEN_URL = "http://api.t.sohu.com/oauth/request_token"; - private static final String ACCESS_TOKEN_URL = "http://api.t.sohu.com/oauth/access_token"; - private static final String AUTHORIZE_URL = "http://api.t.sohu.com/oauth/authorize"; - - protected SohuWeiboApi() { - } - - private static class InstanceHolder { - private static final SohuWeiboApi INSTANCE = new SohuWeiboApi(); - } - - public static SohuWeiboApi instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getRequestTokenEndpoint() { - return REQUEST_TOKEN_URL; - } - - @Override - public String getAccessTokenEndpoint() { - return ACCESS_TOKEN_URL; - } - - @Override - public String getAuthorizationBaseUrl() { - return AUTHORIZE_URL; - } -} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java deleted file mode 100644 index e56a05a0c..000000000 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NeteaseWeiboExample.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.github.scribejava.apis.examples; - -import java.util.Scanner; -import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.apis.NeteaseWeibooApi; -import com.github.scribejava.core.model.OAuth1AccessToken; -import com.github.scribejava.core.model.OAuth1RequestToken; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuth10aService; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -public class NeteaseWeiboExample { - - private static final String NETWORK_NAME = "NetEase(163.com) Weibo"; - private static final String PROTECTED_RESOURCE_URL = "http://api.t.163.com/account/verify_credentials.json"; - - private NeteaseWeiboExample() { - } - - public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - // Replace these with your own api key and secret - final String apiKey = "your key"; - final String apiSecret = "your secret"; - final OAuth10aService service = new ServiceBuilder(apiKey) - .apiSecret(apiSecret) - .build(NeteaseWeibooApi.instance()); - final Scanner in = new Scanner(System.in); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); - System.out.println(); - - // Grab a request token. - System.out.println("Fetching request token."); - final OAuth1RequestToken requestToken = service.getRequestToken(); - System.out.println("Got it ... "); - System.out.println(requestToken.getToken()); - - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(requestToken); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - final String oauthVerifier = in.nextLine(); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); - System.out.println("Got the Access Token!"); - System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - - System.out.println(); - System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); - } -} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java deleted file mode 100644 index 690efa9a8..000000000 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SohuWeiboExample.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.github.scribejava.apis.examples; - -import java.util.Scanner; -import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.apis.SohuWeiboApi; -import com.github.scribejava.core.model.OAuth1AccessToken; -import com.github.scribejava.core.model.OAuth1RequestToken; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuth10aService; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -public class SohuWeiboExample { - - private static final String NETWORK_NAME = "SohuWeibo"; - private static final String PROTECTED_RESOURCE_URL = "http://api.t.sohu.com/account/verify_credentials.json"; - - private SohuWeiboExample() { - } - - public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - // Replace these with your own api key and secret - final String apiKey = "your_key"; - final String apiSecret = "your_secret"; - final OAuth10aService service = new ServiceBuilder(apiKey) - .apiSecret(apiSecret) - .build(SohuWeiboApi.instance()); - final Scanner in = new Scanner(System.in); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); - System.out.println(); - - // Grab a request token. - System.out.println("Fetching request token."); - final OAuth1RequestToken requestToken = service.getRequestToken(); - System.out.println("Got it ... "); - System.out.println(requestToken.getToken()); - - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(requestToken); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - final String oauthVerifier = in.nextLine(); - System.out.println(); - - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); - System.out.println("Got the Access Token!"); - System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); - System.out.println(); - - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - - System.out.println(); - System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); - } -} From a88c391ab620dfd820489f1d030ca22d8d1a1b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20B=C3=B6hmer?= Date: Wed, 22 Aug 2018 18:09:12 +0200 Subject: [PATCH 103/481] Added OAuth2 API and example for HiOrg-Server --- .../scribejava/apis/HiOrgServerApi20.java | 52 +++++++++++ .../apis/examples/HiOrgServerExample.java | 93 +++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java new file mode 100644 index 000000000..e78d093c9 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java @@ -0,0 +1,52 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; + +/** + * OAuth2 API for HiOrg-Server + * + * @see https://wiki.hiorg-server.de/admin/oauth2 + */ +public class HiOrgServerApi20 extends DefaultApi20 { + + private final String version; + + protected HiOrgServerApi20() { + this("v1"); + } + + protected HiOrgServerApi20(String version) { + this.version = version; + } + + private static class InstanceHolder { + + private static final HiOrgServerApi20 INSTANCE = new HiOrgServerApi20(); + } + + public static HiOrgServerApi20 instance() { + return InstanceHolder.INSTANCE; + } + + public static HiOrgServerApi20 customVersion(String version) { + return new HiOrgServerApi20(version); + } + + @Override + public String getAccessTokenEndpoint() { + return "https://www.hiorg-server.de/api/oauth2/" + version + "/token.php"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://www.hiorg-server.de/api/oauth2/" + version + "/authorize.php"; + } + + @Override + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); + } + +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java new file mode 100644 index 000000000..6055af753 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java @@ -0,0 +1,93 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.HiOrgServerApi20; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.IOException; +import java.util.Random; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public class HiOrgServerExample { + + private static final String NETWORK_NAME = "HiOrgServer"; + private static final String PROTECTED_RESOURCE_URL = "https://www.hiorg-server.de/api/oauth2/v1/user.php"; + private static final String CLIENT_ID = "your client id"; + private static final String CLIENT_SECRET = "your client secret"; + private static final String CALLBACK_URL = "http://www.example.com/oauth_callback/"; + + private HiOrgServerExample() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = CLIENT_ID; + final String clientSecret = CLIENT_SECRET; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .scope("basic eigenedaten") + .state(secretState) + .callback(CALLBACK_URL) + .build(HiOrgServerApi20.instance()); + + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + System.out.println("Refreshing the Access Token..."); + accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); + System.out.println("Refreshed the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } + +} From 434fc4cc41a41c41af8c33870b19118a470ac3f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20B=C3=B6hmer?= Date: Wed, 22 Aug 2018 19:01:36 +0200 Subject: [PATCH 104/481] Corrected javadoc --- .../main/java/com/github/scribejava/apis/HiOrgServerApi20.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java index e78d093c9..0733381cf 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java @@ -7,7 +7,7 @@ /** * OAuth2 API for HiOrg-Server * - * @see https://wiki.hiorg-server.de/admin/oauth2 + * @see HiOrg-Server OAuth API documentation */ public class HiOrgServerApi20 extends DefaultApi20 { From e8ba32375e9c60c6a03006e3172ac9e6e791d70f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 Aug 2018 16:52:27 +0300 Subject: [PATCH 105/481] * add RuntimeException processing in async http clients (delivered to onError callbacks) + check 200 status code from response in OAuth2AccessTokenExtractor (thanks to https://github.com/jochen314) --- changelog | 2 + checkstyle.xml | 1 - .../OAuth2AccessTokenExtractor.java | 2 +- .../core/httpclient/jdk/JDKHttpClient.java | 2 +- .../core/httpclient/jdk/JDKHttpFuture.java | 6 +- .../OAuth2AccessTokenExtractorTest.java | 4 +- .../ahc/OAuthAsyncCompletionHandler.java | 33 +++++----- .../apache/OAuthAsyncCompletionHandler.java | 10 ++-- ...a => OAuthAsyncCompletionHandlerTest.java} | 26 ++++---- .../ning/OAuthAsyncCompletionHandler.java | 28 ++++----- .../httpclient/ning/MockResponse.java | 12 +--- ...a => OAuthAsyncCompletionHandlerTest.java} | 14 ++--- .../okhttp/OAuthAsyncCompletionHandler.java | 14 ++--- .../httpclient/okhttp/OkHttpFuture.java | 14 ++--- .../httpclient/okhttp/MockCall.java | 60 ++++++++----------- ...a => OAuthAsyncCompletionHandlerTest.java} | 38 ++++++++---- 16 files changed, 131 insertions(+), 135 deletions(-) rename scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/{OauthAsyncCompletionHandlerTest.java => OAuthAsyncCompletionHandlerTest.java} (88%) rename scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/{OauthAsyncCompletionHandlerTest.java => OAuthAsyncCompletionHandlerTest.java} (86%) rename scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/{OauthAsyncCompletionHandlerTest.java => OAuthAsyncCompletionHandlerTest.java} (83%) diff --git a/changelog b/changelog index b711f672e..9b63227d1 100644 --- a/changelog +++ b/changelog @@ -3,6 +3,8 @@ * add Multipart functionality to JDK Http Client (thanks to https://github.com/eos1d3) * switch OAuth2 ClientAuthenticationType from enum to interface to be extensible according to https://tools.ietf.org/html/rfc6749#section-2.3.2 (thanks to https://github.com/zawn) + * add RuntimeException processing in async http clients (delivered to onError callbacks) (thanks to https://github.com/jochen314) + * check 200 status code from response in OAuth2AccessTokenExtractor (thanks to https://github.com/jochen314) [5.5.0] * fix error parsing for Fitbit (thanks to https://github.com/danmana) diff --git a/checkstyle.xml b/checkstyle.xml index 2955d30b9..f3befc8a5 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -45,7 +45,6 @@ - diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java index 22c1b90f0..855a03c43 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractor.java @@ -39,7 +39,7 @@ public static OAuth2AccessTokenExtractor instance() { @Override public OAuth2AccessToken extract(Response response) throws IOException { if (response.getCode() != 200) { - throw new OAuthException("Response code not 200 but " + response.getCode()); + throw new OAuthException("Response code is not 200 but '" + response.getCode() + '\''); } final String body = response.getBody(); Preconditions.checkEmptyString(body, diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 164a0520f..7e87dba0b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -79,7 +79,7 @@ private Future doExecuteAsync(String userAgent, Map heade callback.onCompleted(t); } return new JDKHttpFuture<>(t); - } catch (Throwable e) { + } catch (IOException | RuntimeException e) { if (callback != null) { callback.onThrowable(e); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java index 307c552c6..1922d3aef 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java @@ -11,10 +11,10 @@ */ public class JDKHttpFuture implements Future { - private final Throwable exception; + private final Exception exception; private final V response; - public JDKHttpFuture(Throwable exception) { + public JDKHttpFuture(Exception exception) { this(null, exception); } @@ -22,7 +22,7 @@ public JDKHttpFuture(V response) { this(response, null); } - private JDKHttpFuture(V response, Throwable exception) { + private JDKHttpFuture(V response, Exception exception) { this.response = response; this.exception = exception; } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java index b123d90aa..a79a87615 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java @@ -61,7 +61,7 @@ public void shouldExtractTokenFromResponseWithManyParameters() throws IOExceptio @Test(expected = OAuthException.class) public void shouldThrowExceptionIfErrorResponse() throws IOException { final String response = ""; - this.extractor.extract(error(response)); + extractor.extract(error(response)); } @Test(expected = OAuthException.class) @@ -85,7 +85,7 @@ private static Response ok(String body) { return new Response(200, /* message */ null, /* headers */ Collections.emptyMap(), body); } - private static Response error(final String body) { + private static Response error(String body) { return new Response(400, /* message */ null, /* headers */ Collections.emptyMap(), body); } } diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java index 100406fda..08706c195 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java @@ -20,21 +20,26 @@ public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, } @Override - public T onCompleted(org.asynchttpclient.Response ahcResponse) throws IOException { - final Map headersMap = new HashMap<>(); - for (Map.Entry header : ahcResponse.getHeaders()) { - headersMap.put(header.getKey(), header.getValue()); + public T onCompleted(org.asynchttpclient.Response ahcResponse) { + try { + final Map headersMap = new HashMap<>(); + for (Map.Entry header : ahcResponse.getHeaders()) { + headersMap.put(header.getKey(), header.getValue()); + } + + final Response response = new Response(ahcResponse.getStatusCode(), ahcResponse.getStatusText(), headersMap, + ahcResponse.getResponseBodyAsStream()); + + @SuppressWarnings("unchecked") + final T t = converter == null ? (T) response : converter.convert(response); + if (callback != null) { + callback.onCompleted(t); + } + return t; + } catch (IOException | RuntimeException e) { + onThrowable(e); + return null; } - - final Response response = new Response(ahcResponse.getStatusCode(), ahcResponse.getStatusText(), headersMap, - ahcResponse.getResponseBodyAsStream()); - - @SuppressWarnings("unchecked") - final T t = converter == null ? (T) response : converter.convert(response); - if (callback != null) { - callback.onCompleted(t); - } - return t; } @Override diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java index b49dd8513..65b92a178 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java @@ -16,6 +16,7 @@ import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthRequest.ResponseConverter; import com.github.scribejava.core.model.Response; +import java.io.IOException; public class OAuthAsyncCompletionHandler implements FutureCallback { @@ -23,7 +24,7 @@ public class OAuthAsyncCompletionHandler implements FutureCallback converter; private final CountDownLatch latch; private T result; - private Throwable exception; + private Exception exception; public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, ResponseConverter converter) { this.callback = callback; @@ -41,9 +42,8 @@ public void completed(HttpResponse httpResponse) { final StatusLine statusLine = httpResponse.getStatusLine(); - final Response response = - new Response(statusLine.getStatusCode(), statusLine.getReasonPhrase(), headersMap, - httpResponse.getEntity().getContent()); + final Response response = new Response(statusLine.getStatusCode(), statusLine.getReasonPhrase(), headersMap, + httpResponse.getEntity().getContent()); @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); @@ -51,7 +51,7 @@ public void completed(HttpResponse httpResponse) { if (callback != null) { callback.onCompleted(result); } - } catch (Throwable e) { + } catch (IOException | RuntimeException e) { exception = e; if (callback != null) { callback.onThrowable(e); diff --git a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandlerTest.java similarity index 88% rename from scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java rename to scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandlerTest.java index 12c4588f3..c43fbed9e 100644 --- a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OauthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandlerTest.java @@ -24,12 +24,12 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; -public class OauthAsyncCompletionHandlerTest { +public class OAuthAsyncCompletionHandlerTest { private static final AllGoodResponseConverter ALL_GOOD_RESPONSE_CONVERTER = new AllGoodResponseConverter(); private static final ExceptionResponseConverter EXCEPTION_RESPONSE_CONVERTER = new ExceptionResponseConverter(); - private static final OAuthExceptionResponseConverter OAUTH_EXCEPTION_RESPONSE_CONVERTER = - new OAuthExceptionResponseConverter(); + private static final OAuthExceptionResponseConverter OAUTH_EXCEPTION_RESPONSE_CONVERTER + = new OAuthExceptionResponseConverter(); private OAuthAsyncCompletionHandler handler; private TestCallback callback; @@ -67,8 +67,8 @@ public void setUp() { @Test public void shouldReleaseLatchOnSuccess() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER); - final HttpResponse response = - new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); + final HttpResponse response + = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); @@ -82,8 +82,8 @@ public void shouldReleaseLatchOnSuccess() throws Exception { @Test public void shouldReleaseLatchOnIOException() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, EXCEPTION_RESPONSE_CONVERTER); - final HttpResponse response = - new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); + final HttpResponse response + = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); @@ -103,8 +103,8 @@ public void shouldReleaseLatchOnIOException() throws Exception { @Test public void shouldReportOAuthException() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, OAUTH_EXCEPTION_RESPONSE_CONVERTER); - final HttpResponse response = - new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); + final HttpResponse response + = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); @@ -124,8 +124,8 @@ public void shouldReportOAuthException() throws Exception { @Test public void shouldReleaseLatchOnCancel() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER); - final HttpResponse response = - new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); + final HttpResponse response + = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); @@ -145,8 +145,8 @@ public void shouldReleaseLatchOnCancel() throws Exception { @Test public void shouldReleaseLatchOnFailure() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER); - final HttpResponse response = - new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); + final HttpResponse response + = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(new byte[0])); response.setEntity(entity); diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java index f4122c1e9..cd8a25ce1 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandler.java @@ -21,29 +21,29 @@ public OAuthAsyncCompletionHandler(OAuthAsyncRequestCallback callback, } @Override - public T onCompleted(com.ning.http.client.Response ningResponse) throws IOException { - final Map headersMap = new HashMap<>(); - - for (Map.Entry> header : ningResponse.getHeaders().entrySet()) { - final StringBuilder value = new StringBuilder(); - for (String str : header.getValue()) { - value.append(str); + public T onCompleted(com.ning.http.client.Response ningResponse) { + try { + final Map headersMap = new HashMap<>(); + + for (Map.Entry> header : ningResponse.getHeaders().entrySet()) { + final StringBuilder value = new StringBuilder(); + for (String str : header.getValue()) { + value.append(str); + } + headersMap.put(header.getKey(), value.toString()); } - headersMap.put(header.getKey(), value.toString()); - } - final Response response = new Response(ningResponse.getStatusCode(), ningResponse.getStatusText(), headersMap, - ningResponse.getResponseBodyAsStream()); + final Response response = new Response(ningResponse.getStatusCode(), ningResponse.getStatusText(), + headersMap, ningResponse.getResponseBodyAsStream()); - try { @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); if (callback != null) { callback.onCompleted(t); } return t; - } catch (Throwable t) { - onThrowable(t); + } catch (IOException | RuntimeException e) { + onThrowable(e); return null; } } diff --git a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/MockResponse.java b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/MockResponse.java index c432d9ed2..af75bf871 100644 --- a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/MockResponse.java +++ b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/MockResponse.java @@ -11,9 +11,6 @@ import com.ning.http.client.cookie.Cookie; import com.ning.http.client.uri.Uri; -/** - * - */ public class MockResponse implements Response { private final int statusCode; @@ -21,14 +18,7 @@ public class MockResponse implements Response { private final FluentCaseInsensitiveStringsMap headers; private final byte[] body; - /** - * @param statusCode - * @param statusText - * @param body - */ - public MockResponse(int statusCode, String statusText, FluentCaseInsensitiveStringsMap headers, - byte[] body) { - super(); + public MockResponse(int statusCode, String statusText, FluentCaseInsensitiveStringsMap headers, byte[] body) { this.statusCode = statusCode; this.statusText = statusText; this.headers = headers; diff --git a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OauthAsyncCompletionHandlerTest.java b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandlerTest.java similarity index 86% rename from scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OauthAsyncCompletionHandlerTest.java rename to scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandlerTest.java index efc516d68..c235061e9 100644 --- a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OauthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandlerTest.java @@ -16,11 +16,11 @@ import com.github.scribejava.core.model.Response; import com.ning.http.client.FluentCaseInsensitiveStringsMap; -public class OauthAsyncCompletionHandlerTest { +public class OAuthAsyncCompletionHandlerTest { private static final AllGoodResponseConverter ALL_GOOD_RESPONSE_CONVERTER = new AllGoodResponseConverter(); - private static final OAuthExceptionResponseConverter OAUTH_EXCEPTION_RESPONSE_CONVERTER = - new OAuthExceptionResponseConverter(); + private static final OAuthExceptionResponseConverter OAUTH_EXCEPTION_RESPONSE_CONVERTER + = new OAuthExceptionResponseConverter(); private OAuthAsyncCompletionHandler handler; private TestCallback callback; @@ -59,8 +59,8 @@ public void setUp() { public void shouldReleaseLatchOnSuccess() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER); - final com.ning.http.client.Response response = - new MockResponse(200, "ok", new FluentCaseInsensitiveStringsMap(), new byte[0]); + final com.ning.http.client.Response response + = new MockResponse(200, "ok", new FluentCaseInsensitiveStringsMap(), new byte[0]); handler.onCompleted(response); assertNotNull(callback.getResponse()); assertNull(callback.getThrowable()); @@ -72,8 +72,8 @@ public void shouldReleaseLatchOnSuccess() throws Exception { public void shouldReportOAuthException() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, OAUTH_EXCEPTION_RESPONSE_CONVERTER); - final com.ning.http.client.Response response = - new MockResponse(200, "ok", new FluentCaseInsensitiveStringsMap(), new byte[0]); + final com.ning.http.client.Response response + = new MockResponse(200, "ok", new FluentCaseInsensitiveStringsMap(), new byte[0]); handler.onCompleted(response); assertNull(callback.getResponse()); assertNotNull(callback.getThrowable()); diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java index bd613138a..8345fa9d1 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java @@ -22,11 +22,11 @@ class OAuthAsyncCompletionHandler implements Callback { } @Override - public void onFailure(Call call, IOException e) { + public void onFailure(Call call, IOException exception) { try { - this.okHttpFuture.setError(e); + okHttpFuture.setException(exception); if (callback != null) { - callback.onThrowable(e); + callback.onThrowable(exception); } } finally { okHttpFuture.finish(); @@ -34,7 +34,7 @@ public void onFailure(Call call, IOException e) { } @Override - public void onResponse(Call call, okhttp3.Response okHttpResponse) throws IOException { + public void onResponse(Call call, okhttp3.Response okHttpResponse) { try { final Response response = OkHttpHttpClient.convertResponse(okHttpResponse); @@ -45,10 +45,10 @@ public void onResponse(Call call, okhttp3.Response okHttpResponse) throws IOExce if (callback != null) { callback.onCompleted(t); } - } catch (Throwable t) { - okHttpFuture.setError(t); + } catch (IOException | RuntimeException e) { + okHttpFuture.setException(e); if (callback != null) { - callback.onThrowable(t); + callback.onThrowable(e); } } } finally { diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpFuture.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpFuture.java index a75617dd4..417b03e0a 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpFuture.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpFuture.java @@ -13,7 +13,7 @@ public class OkHttpFuture implements Future { private final CountDownLatch latch = new CountDownLatch(1); private final Call call; private T result; - private Throwable t; + private Exception exception; public OkHttpFuture(Call call) { this.call = call; @@ -35,15 +35,15 @@ public boolean isDone() { return call.isExecuted(); } - public void setError(Throwable t) { - this.t = t; + public void setException(Exception exception) { + this.exception = exception; } @Override public T get() throws InterruptedException, ExecutionException { latch.await(); - if (t != null) { - throw new ExecutionException(t); + if (exception != null) { + throw new ExecutionException(exception); } return result; } @@ -51,8 +51,8 @@ public T get() throws InterruptedException, ExecutionException { @Override public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { if (latch.await(timeout, unit)) { - if (t != null) { - throw new ExecutionException(t); + if (exception != null) { + throw new ExecutionException(exception); } return result; } diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java index 9b4b1d447..967d96c4a 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java @@ -1,66 +1,54 @@ package com.github.scribejava.httpclient.okhttp; import java.io.IOException; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.Collection; import okhttp3.Call; import okhttp3.Callback; +import okhttp3.Request; +import okhttp3.Response; -/** - * the only reason, this is a dynamic proxy is, that checkstyle forbids implementing clone()! - */ -public class MockCall implements InvocationHandler { +public class MockCall implements Call { - private final Collection callbacks; + private final Collection callbacks = new ArrayList<>(); private boolean canceled; - public MockCall() { - this(new ArrayList()); - } - - private MockCall(Collection callbacks) { - this.callbacks = new ArrayList<>(callbacks); - } - + @Override public void enqueue(Callback responseCallback) { callbacks.add(responseCallback); } - public void cancel(Call proxy) { + @Override + public void cancel() { canceled = true; for (Callback callback : callbacks) { - callback.onFailure(proxy, new IOException("Canceled")); + callback.onFailure(this, new IOException("Canceled")); } } + @Override public boolean isCanceled() { return canceled; } @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - switch (method.getName()) { - case "enqueue": - enqueue((Callback) args[0]); - return null; - case "cancel": - cancel((Call) proxy); - return null; - case "isCanceled": - return isCanceled(); - default: - throw new UnsupportedOperationException(method.toString()); - } + public Request request() { + throw new UnsupportedOperationException("Not supported yet."); } - /** - * @return - */ - public static Call create() { - return (Call) Proxy.newProxyInstance(Call.class.getClassLoader(), new Class[] { Call.class }, new MockCall()); + @Override + public Response execute() throws IOException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean isExecuted() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Call clone() { + throw new UnsupportedOperationException("Not supported yet."); } } diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OauthAsyncCompletionHandlerTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java similarity index 83% rename from scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OauthAsyncCompletionHandlerTest.java rename to scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java index 5181487ff..863d2eee3 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OauthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java @@ -23,12 +23,12 @@ import okhttp3.Request; import okhttp3.ResponseBody; -public class OauthAsyncCompletionHandlerTest { +public class OAuthAsyncCompletionHandlerTest { private static final AllGoodResponseConverter ALL_GOOD_RESPONSE_CONVERTER = new AllGoodResponseConverter(); private static final ExceptionResponseConverter EXCEPTION_RESPONSE_CONVERTER = new ExceptionResponseConverter(); - private static final OAuthExceptionResponseConverter OAUTH_EXCEPTION_RESPONSE_CONVERTER = - new OAuthExceptionResponseConverter(); + private static final OAuthExceptionResponseConverter OAUTH_EXCEPTION_RESPONSE_CONVERTER + = new OAuthExceptionResponseConverter(); private OAuthAsyncCompletionHandler handler; private Call call; @@ -63,7 +63,7 @@ public String getResponse() { @Before public void setUp() { callback = new TestCallback(); - call = MockCall.create(); + call = new MockCall(); future = new OkHttpFuture<>(call); } @@ -73,9 +73,13 @@ public void shouldReleaseLatchOnSuccess() throws Exception { call.enqueue(handler); final okhttp3.Request request = new Request.Builder().url("http://localhost/").build(); - final okhttp3.Response response = - new okhttp3.Response.Builder().request(request).protocol(Protocol.HTTP_1_1).code(200).message("ok") - .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])).build(); + final okhttp3.Response response = new okhttp3.Response.Builder() + .request(request) + .protocol(Protocol.HTTP_1_1) + .code(200) + .message("ok") + .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])) + .build(); handler.onResponse(call, response); assertNotNull(callback.getResponse()); assertNull(callback.getThrowable()); @@ -89,9 +93,13 @@ public void shouldReleaseLatchOnIOException() throws Exception { call.enqueue(handler); final okhttp3.Request request = new Request.Builder().url("http://localhost/").build(); - final okhttp3.Response response = - new okhttp3.Response.Builder().request(request).protocol(Protocol.HTTP_1_1).code(200).message("ok") - .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])).build(); + final okhttp3.Response response = new okhttp3.Response.Builder() + .request(request) + .protocol(Protocol.HTTP_1_1) + .code(200) + .message("ok") + .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])) + .build(); handler.onResponse(call, response); assertNull(callback.getResponse()); assertNotNull(callback.getThrowable()); @@ -111,9 +119,13 @@ public void shouldReportOAuthException() throws Exception { call.enqueue(handler); final okhttp3.Request request = new Request.Builder().url("http://localhost/").build(); - final okhttp3.Response response = - new okhttp3.Response.Builder().request(request).protocol(Protocol.HTTP_1_1).code(200).message("ok") - .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])).build(); + final okhttp3.Response response = new okhttp3.Response.Builder() + .request(request) + .protocol(Protocol.HTTP_1_1) + .code(200) + .message("ok") + .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])) + .build(); handler.onResponse(call, response); assertNull(callback.getResponse()); assertNotNull(callback.getThrowable()); From c308760b84c5efef6ec8c0ab599dafaf8940da0d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 Aug 2018 17:25:38 +0300 Subject: [PATCH 106/481] update maven compiler plugin --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7f8d17a8f..7fd7e0dd9 100644 --- a/pom.xml +++ b/pom.xml @@ -126,7 +126,7 @@ maven-compiler-plugin - 3.7.0 + 3.8.0 UTF-8 1.7 From 3be2efcc4308fee45c8ba642b6af35fcc6a0e175 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 6 Sep 2018 13:12:42 +0300 Subject: [PATCH 107/481] fix case sensitive Http Headers comparison and sending Content-Type header along with content-type (thanks to https://github.com/marnix) --- changelog | 1 + .../core/httpclient/MultipartPayload.java | 3 ++- .../scribejava/core/model/OAuthRequest.java | 9 +++++---- .../core/model/OAuthRequestTest.java | 19 +++++++++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/changelog b/changelog index 9b63227d1..aaddba45e 100644 --- a/changelog +++ b/changelog @@ -5,6 +5,7 @@ https://tools.ietf.org/html/rfc6749#section-2.3.2 (thanks to https://github.com/zawn) * add RuntimeException processing in async http clients (delivered to onError callbacks) (thanks to https://github.com/jochen314) * check 200 status code from response in OAuth2AccessTokenExtractor (thanks to https://github.com/jochen314) + * fix case sensitive Http Headers comparison and sending Content-Type header along with content-type (thanks to https://github.com/marnix) [5.5.0] * fix error parsing for Fitbit (thanks to https://github.com/danmana) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java index a1dbb5e7e..71d67f508 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java @@ -18,7 +18,8 @@ public MultipartPayload(String boundary) { public byte[] getStartBoundary(BodyPartPayload bodyPart) { return ("--" + boundary + "\r\n" + "Content-Disposition: " + bodyPart.getContentDisposition() + "\r\n" - + (bodyPart.getContentType() == null ? "" : "Content-Type: " + bodyPart.getContentType() + "\r\n") + + (bodyPart.getContentType() == null + ? "" : HttpClient.CONTENT_TYPE + ": " + bodyPart.getContentType() + "\r\n") + "\r\n").getBytes(); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index a33ac7d72..d132da1dc 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -10,6 +10,7 @@ import java.nio.charset.Charset; import java.util.HashMap; import java.util.Map; +import java.util.TreeMap; /** * The representation of an OAuth HttpRequest. @@ -22,7 +23,7 @@ public class OAuthRequest { private final Verb verb; private final ParameterList querystringParams = new ParameterList(); private final ParameterList bodyParams = new ParameterList(); - private final Map headers = new HashMap<>(); + private final Map headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); private String charset; @@ -95,7 +96,7 @@ public String getCompleteUrl() { * @param value the header value */ public void addHeader(String key, String value) { - this.headers.put(key, value); + headers.put(key, value); } /** @@ -105,7 +106,7 @@ public void addHeader(String key, String value) { * @param value the parameter value */ public void addBodyParameter(String key, String value) { - this.bodyParams.add(key, value); + bodyParams.add(key, value); } /** @@ -115,7 +116,7 @@ public void addBodyParameter(String key, String value) { * @param value the parameter value */ public void addQuerystringParameter(String key, String value) { - this.querystringParams.add(key, value); + querystringParams.add(key, value); } public void addParameter(String key, String value) { diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/OAuthRequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/OAuthRequestTest.java index 0ea88985d..03688ce16 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/OAuthRequestTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/OAuthRequestTest.java @@ -1,6 +1,7 @@ package com.github.scribejava.core.model; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; @@ -28,4 +29,22 @@ public void shouldAddOAuthParamters() { public void shouldThrowExceptionIfParameterIsNotOAuth() { request.addOAuthParameter("otherParam", "value"); } + + @Test + public void shouldNotSentHeaderTwice() { + assertTrue(request.getHeaders().isEmpty()); + request.addHeader("HEADER-NAME", "first"); + request.addHeader("header-name", "middle"); + request.addHeader("Header-Name", "last"); + + assertEquals(1, request.getHeaders().size()); + + assertTrue(request.getHeaders().containsKey("HEADER-NAME")); + assertTrue(request.getHeaders().containsKey("header-name")); + assertTrue(request.getHeaders().containsKey("Header-Name")); + + assertEquals("last", request.getHeaders().get("HEADER-NAME")); + assertEquals("last", request.getHeaders().get("header-name")); + assertEquals("last", request.getHeaders().get("Header-Name")); + } } From f00afdb763c883890227a26cfb7455a4013ff661 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 6 Sep 2018 13:18:16 +0300 Subject: [PATCH 108/481] update async-http-client --- scribejava-httpclient-ahc/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index eacdd6208..7ed0dbe69 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.5.2 + 2.5.3 com.github.scribejava From 3bf1ce4fd9117d41f312c3009c149288c6f07b99 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 10 Sep 2018 13:07:21 +0300 Subject: [PATCH 109/481] update info in pom --- pom.xml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 7fd7e0dd9..25acee28b 100644 --- a/pom.xml +++ b/pom.xml @@ -41,15 +41,12 @@ kullfar Stas Gromov - s.gromov@hh.ru - hh.ru - http://hh.ru + kullfar@gmail.com all +3 - kullfar@gmail.com +7-909-677-11-16 From 1547b3e644960fcb11ff61be468fe5c0b06ff570 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 10 Sep 2018 13:07:58 +0300 Subject: [PATCH 110/481] Seems, it was illegal to add copyright here --- LICENSE.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 8cde51fa9..6085098bc 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,5 @@ The MIT License -Copyright (c) 2013 hh.ru Copyright (c) 2010 Pablo Fernandez Permission is hereby granted, free of charge, to any person obtaining a copy @@ -19,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file +THE SOFTWARE. From fb22d4158ec528a585abc4a2ad46179950ea7e41 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 11 Sep 2018 09:55:34 +0300 Subject: [PATCH 111/481] add HiOrg-Server (https://www.hiorg-server.de/) API (thanks to https://github.com/MartinBoehmer) --- README.md | 1 + changelog | 1 + .../java/com/github/scribejava/apis/HiOrgServerApi20.java | 8 -------- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 29d1833dd..af82ae54f 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ ScribeJava support out-of-box several HTTP clients: * GitHub (https://github.com/) * Google (https://www.google.com/) * HeadHunter ХэдХантер (https://hh.ru/) +* HiOrg-Server (https://www.hiorg-server.de/) * Imgur (http://imgur.com/) * Kaixin 开心网 (http://www.kaixin001.com/) * LinkedIn (https://www.linkedin.com/) diff --git a/changelog b/changelog index aaddba45e..4df2d5ccc 100644 --- a/changelog +++ b/changelog @@ -6,6 +6,7 @@ * add RuntimeException processing in async http clients (delivered to onError callbacks) (thanks to https://github.com/jochen314) * check 200 status code from response in OAuth2AccessTokenExtractor (thanks to https://github.com/jochen314) * fix case sensitive Http Headers comparison and sending Content-Type header along with content-type (thanks to https://github.com/marnix) + * add HiOrg-Server (https://www.hiorg-server.de/) API (thanks to https://github.com/MartinBoehmer) [5.5.0] * fix error parsing for Fitbit (thanks to https://github.com/danmana) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java index 0733381cf..a69673a25 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HiOrgServerApi20.java @@ -1,8 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; -import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; /** * OAuth2 API for HiOrg-Server @@ -43,10 +41,4 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://www.hiorg-server.de/api/oauth2/" + version + "/authorize.php"; } - - @Override - public ClientAuthentication getClientAuthentication() { - return RequestBodyAuthenticationScheme.instance(); - } - } From f54525dd0b5c7329c55b5f50f73807627e7fa8fd Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 11 Sep 2018 10:36:53 +0300 Subject: [PATCH 112/481] prepare 5.6.0 release --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index af82ae54f..25b0ce33e 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 5.5.0 + 5.6.0 ``` @@ -120,7 +120,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 5.5.0 + 5.6.0 ``` diff --git a/changelog b/changelog index 4df2d5ccc..d7e6441ee 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[5.6.0] * remove support for obsolete NetEase (http://www.163.com/) and sohu 搜狐 (http://www.sohu.com/) (thanks to https://github.com/zawn) * add Multipart functionality to JDK Http Client (thanks to https://github.com/eos1d3) * switch OAuth2 ClientAuthenticationType from enum to interface to be extensible according to From 92068d25e6904ab443ce90264cd7cea8d731b06d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 11 Sep 2018 10:38:49 +0300 Subject: [PATCH 113/481] [maven-release-plugin] prepare release scribejava-5.6.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 25acee28b..609b4375a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.5.1-SNAPSHOT + 5.6.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-5.6.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index e92f60e67..e8193e7f8 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.1-SNAPSHOT + 5.6.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 96ea8ad56..9f2e9ad18 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.1-SNAPSHOT + 5.6.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 7ed0dbe69..7312bb98c 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.1-SNAPSHOT + 5.6.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 0043155d0..1429b4840 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.1-SNAPSHOT + 5.6.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index fcd3e33aa..fdecfd145 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.1-SNAPSHOT + 5.6.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 554be1054..991f26dda 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.5.1-SNAPSHOT + 5.6.0 ../pom.xml From 0df58e1ad282c1d54c048f75cea23013e87f9d6e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 11 Sep 2018 10:40:01 +0300 Subject: [PATCH 114/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 609b4375a..30c158970 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.6.0 + 5.6.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-5.6.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index e8193e7f8..3cc2f5f5a 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.0 + 5.6.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 9f2e9ad18..b07f9627b 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.0 + 5.6.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 7312bb98c..ec7ab0a77 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.0 + 5.6.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 1429b4840..f49a10a12 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.0 + 5.6.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index fdecfd145..dffa0f860 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.0 + 5.6.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 991f26dda..3d249abe7 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.0 + 5.6.1-SNAPSHOT ../pom.xml From 218dc162cdce822e2983bde186400f7496719aac Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 11 Sep 2018 12:21:22 +0300 Subject: [PATCH 115/481] remove deprecated ClientAuthenticationType --- .../builder/api/ClientAuthenticationType.java | 41 ------------------- .../core/builder/api/DefaultApi20.java | 18 +------- 2 files changed, 1 insertion(+), 58 deletions(-) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java deleted file mode 100644 index 097ba1081..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/ClientAuthenticationType.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.github.scribejava.core.builder.api; - -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth2.clientauthentication.HttpBasicAuthenticationScheme; -import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; - -/** - * Represents
- * 2.3. Client Authentication
- * https://tools.ietf.org/html/rfc6749#section-2.3
- * in it's part 2.3.1. Client Password
- * https://tools.ietf.org/html/rfc6749#section-2.3.1 - * - * @deprecated use {@link com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication} - */ -@Deprecated -public enum ClientAuthenticationType { - /** - * @deprecated use {@link com.github.scribejava.core.oauth2.clientauthentication.HttpBasicAuthenticationScheme} - */ - @Deprecated - HTTP_BASIC_AUTHENTICATION_SCHEME { - - @Override - public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) { - HttpBasicAuthenticationScheme.instance().addClientAuthentication(request, apiKey, apiSecret); - } - }, - /** - * @deprecated use {@link com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme} - */ - @Deprecated - REQUEST_BODY { - @Override - public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) { - RequestBodyAuthenticationScheme.instance().addClientAuthentication(request, apiKey, apiSecret); - } - }; - - public abstract void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret); -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index b429142a6..e10a57aeb 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -11,7 +11,6 @@ import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.HttpBasicAuthenticationScheme; -import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; import java.io.OutputStream; import java.util.Map; @@ -113,21 +112,6 @@ public OAuth2SignatureType getSignatureType() { } public ClientAuthentication getClientAuthentication() { - switch (getClientAuthenticationType()) { - case HTTP_BASIC_AUTHENTICATION_SCHEME: - return HttpBasicAuthenticationScheme.instance(); - case REQUEST_BODY: - return RequestBodyAuthenticationScheme.instance(); - default: - throw new IllegalStateException("there was no such Client Authentication Type"); - } - } - - /** - * @deprecated use {@link #getClientAuthentication() } - */ - @Deprecated - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.HTTP_BASIC_AUTHENTICATION_SCHEME; + return HttpBasicAuthenticationScheme.instance(); } } From 32604f1f336e1f9621984df05ba640d789459751 Mon Sep 17 00:00:00 2001 From: Marvin Bredal Lillehaug Date: Fri, 14 Sep 2018 12:10:54 +0200 Subject: [PATCH 116/481] Issue #870 Avoid 'Cannot encode null object' when omitting callback url --- .../com/github/scribejava/core/oauth/OAuth20Service.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 5b10849af..addd023a7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -108,7 +108,10 @@ protected OAuthRequest createAccessTokenRequest(String code) { api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); request.addParameter(OAuthConstants.CODE, code); - request.addParameter(OAuthConstants.REDIRECT_URI, getCallback()); + String callback = getCallback(); + if (callback != null) { + request.addParameter(OAuthConstants.REDIRECT_URI, callback); + } final String scope = getScope(); if (scope != null) { request.addParameter(OAuthConstants.SCOPE, scope); From 701d8d8d13c108cb02e9f7bf73dcdf8120a0c3fd Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 14 Sep 2018 14:12:48 +0300 Subject: [PATCH 117/481] make redirect_uri optional while Access Token requesting on OAuth 2.0 (thanks to https://github.com/computerlove) --- changelog | 3 +++ .../java/com/github/scribejava/core/oauth/OAuth20Service.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/changelog b/changelog index d7e6441ee..ed410e999 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * make redirect_uri optional while Access Token requesting on OAuth 2.0 (thanks to https://github.com/computerlove) + [5.6.0] * remove support for obsolete NetEase (http://www.163.com/) and sohu 搜狐 (http://www.sohu.com/) (thanks to https://github.com/zawn) * add Multipart functionality to JDK Http Client (thanks to https://github.com/eos1d3) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index addd023a7..d02b3f17b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -108,7 +108,7 @@ protected OAuthRequest createAccessTokenRequest(String code) { api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); request.addParameter(OAuthConstants.CODE, code); - String callback = getCallback(); + final String callback = getCallback(); if (callback != null) { request.addParameter(OAuthConstants.REDIRECT_URI, callback); } From f974ca0714ea5c3f99e4f816867f456f8b23d316 Mon Sep 17 00:00:00 2001 From: Jokuni Date: Sun, 23 Sep 2018 01:47:54 +0200 Subject: [PATCH 118/481] Add support for Discord based on https://github.com/scribejava/scribejava/pull/735 --- README.md | 1 + .../github/scribejava/apis/DiscordApi.java | 47 ++++++++++ .../apis/service/DiscordService.java | 23 +++++ .../apis/examples/DiscordExample.java | 91 +++++++++++++++++++ 4 files changed, 162 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/DiscordApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/DiscordService.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java diff --git a/README.md b/README.md index 25b0ce33e..86501a17b 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ ScribeJava support out-of-box several HTTP clients: * Box (https://www.box.com/) * Dataporten (https://docs.dataporten.no/) * Digg (http://digg.com/) +* Discord (https://discordapp.com/) * Доктор на работе (https://www.doktornarabote.ru/) * Etsy (https://www.etsy.com/) * Facebook (https://www.facebook.com/) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DiscordApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiscordApi.java new file mode 100644 index 000000000..96a3c31bf --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiscordApi.java @@ -0,0 +1,47 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.service.DiscordService; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.OutputStream; + +public class DiscordApi extends DefaultApi20 { + + private DiscordApi() { + } + + private static class InstanceHolder { + private static final DiscordApi INSTANCE = new DiscordApi(); + } + + public static DiscordApi instance() { + return DiscordApi.InstanceHolder.INSTANCE; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://discordapp.com/api/oauth2/authorize"; + } + + @Override + public String getRevokeTokenEndpoint() { + return "https://discordapp.com/api/oauth2/token/revoke"; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://discordapp.com/api/oauth2/token"; + } + + @Override + public OAuth20Service createService(String apiKey, String apiSecret, String callback, + String scope, OutputStream debugStream, String state, + String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new DiscordService(this, apiKey, apiSecret, callback, scope, state, responseType, + userAgent, httpClientConfig, httpClient); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DiscordService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DiscordService.java new file mode 100644 index 000000000..c97c10d7d --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DiscordService.java @@ -0,0 +1,23 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; + +public class DiscordService extends OAuth20Service { + public DiscordService(DefaultApi20 api, String apiKey, String apiSecret, String callback, + String scope, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + @Override + public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { + request.addHeader(OAuthConstants.HEADER, accessToken.getTokenType() + ' ' + accessToken.getAccessToken()); + } + +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java new file mode 100644 index 000000000..cad56cd73 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java @@ -0,0 +1,91 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.DiscordApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.IOException; +import java.util.Random; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public final class DiscordExample { + + private static final String NETWORK_NAME = "Discord"; + private static final String PROTECTED_RESOURCE_URL = "https://discordapp.com/api/users/@me"; + + private DiscordExample() { + } + + public static void main(String... args) throws IOException, ExecutionException, InterruptedException { + // Replace these with your client id and secret + final String clientId = "client id"; + final String clientSecret = "client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .scope("identify") // replace with desired scope + .state(secretState) + .callback("http://example.com/callback") + .userAgent("ScribeJava") + .build(DiscordApi.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + + System.out.println("Refreshing the Access Token..."); + accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); + System.out.println("Refreshed the Access Token!"); + System.out.println("(if your curious it looks like this: " + accessToken + + ", 'rawResponse'='" + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} From f69dbb249e56b560aecc4fb789e4421c4a2bd56c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 25 Sep 2018 18:16:23 +0300 Subject: [PATCH 119/481] remove travis integration --- .travis.yml | 7 ------- README.md | 1 - 2 files changed, 8 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1420112b3..000000000 --- a/.travis.yml +++ /dev/null @@ -1,7 +0,0 @@ -dist: trusty -language: java -script: mvn clean package -jdk: - - openjdk7 -os: - - linux diff --git a/README.md b/README.md index 25b0ce33e..2ab83e798 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # Welcome to the home of ScribeJava, the simple OAuth client Java lib! -[![Build Status](https://travis-ci.org/scribejava/scribejava.svg?branch=master)](https://travis-ci.org/scribejava/scribejava) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.scribejava/scribejava/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.scribejava/scribejava) From c4254c3aa5b15b249cd2eddfd2ff965899ed548a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 27 Sep 2018 14:17:33 +0300 Subject: [PATCH 120/481] switch to java 9+ (from java 7 only) for compilation. Runtime is still java 7+. Complement README with links and RFC descriptions. --- README.md | 19 +++++-- changelog | 4 +- pom.xml | 54 ++++++++++--------- .../github/scribejava/apis/MediaWikiApi.java | 6 ++- .../core/builder/api/DefaultApi20.java | 5 ++ .../extractors/BaseStringExtractorImpl.java | 2 + .../github/scribejava/core/java8/Base64.java | 38 +++++++------ .../scribejava/core/model/OAuthRequest.java | 3 ++ .../services/RSASha1SignatureServiceTest.java | 7 +-- .../httpclient/ahc/AhcHttpClientTest.java | 2 - 10 files changed, 87 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 2ab83e798..6ab369f0f 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ OAuthService service = new ServiceBuilder(YOUR_API_KEY) That **single line** (added newlines for readability) is the only thing you need to configure ScribeJava with LinkedIn's OAuth API for example. Working runnable examples are [here](https://github.com/scribejava/scribejava/tree/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples) +Common usage: [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java) ### Threadsafe @@ -26,17 +27,27 @@ Hit ScribeJava as hard and with many threads as you like. ### Java 7 compatible That's it. You can use it in old environments and in android apps. +note: To compile from sources you will need Java 9 or newer ### Async and other HTTP clients ScribeJava support out-of-box several HTTP clients: - * ning async http client 1.9.x (maven module scribejava-httpclient-ning) - * Async Http Client asynchttpclient 2.x (maven module scribejava-httpclient-ahc) - * OkHttp (maven module scribejava-httpclient-okhttp) - * Apache HttpComponents HttpClient (maven module scribejava-httpclient-apache) + * ning async http client 1.9.x (maven module scribejava-httpclient-ning) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java) + * Async Http Client asynchttpclient 2.x (maven module scribejava-httpclient-ahc) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java) + * OkHttp (maven module scribejava-httpclient-okhttp) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java) + * Apache HttpComponents HttpClient (maven module scribejava-httpclient-apache) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java) + * any externally created HTTP client [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java) just add corresponding maven modules to your pom +### Supports many flows and additional features + + * RFC 6749 The OAuth 2.0 Authorization Framework, Authorization Code Authorization Grant [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java) + * RFC 6749 The OAuth 2.0 Authorization Framework, Client Credentials Authorization Grant [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java) + * RFC 6749 The OAuth 2.0 Authorization Framework, Resource Owner Password Credentials Authorization Grant + * RFC 7636 Proof Key for Code Exchange by OAuth Public Clients (PKCE) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) + * RFC 7009 OAuth 2.0 Token Revocation [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java) + ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box * Automatic (https://www.automatic.com/) diff --git a/changelog b/changelog index ed410e999..e2df12e69 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * make redirect_uri optional while Access Token requesting on OAuth 2.0 (thanks to https://github.com/computerlove) + * switch to java 9+ (from java 7 only) for compilation. Runtime is still java 7+. Complement README with links and RFC descriptions. [5.6.0] * remove support for obsolete NetEase (http://www.163.com/) and sohu 搜狐 (http://www.sohu.com/) (thanks to https://github.com/zawn) @@ -205,8 +206,7 @@ [2.0] * merge back SubScribe fork to the ScribeJava - + for previous changes see v1-changelog - changelog for 1.x version v2pre-changelog - changelog for SubScribe fork - diff --git a/pom.xml b/pom.xml index 30c158970..85d155e54 100644 --- a/pom.xml +++ b/pom.xml @@ -34,8 +34,8 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD - + HEAD + @@ -78,7 +78,7 @@ org.apache.felix maven-bundle-plugin - 3.5.1 + 4.0.0 bundle-manifest @@ -107,17 +107,38 @@ com.puppycrawl.tools checkstyle - 6.19 + 8.12 + org.apache.maven.plugins maven-release-plugin 2.5.3 true + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.0 + + + org.apache.maven.plugins + maven-clean-plugin + 3.1.0 + + + org.apache.maven.plugins + maven-enforcer-plugin + 1.4.1 + + + org.apache.maven.plugins + maven-install-plugin + 2.5.2 +
@@ -126,8 +147,7 @@ 3.8.0 UTF-8 - 1.7 - 1.7 + 7 true
@@ -170,7 +190,9 @@ maven-javadoc-plugin 3.0.1 + ${java.home}/bin/javadoc UTF-8 + -html5 @@ -203,26 +225,6 @@
- - org.apache.maven.plugins - maven-enforcer-plugin - 1.4.1 - - - enforce-java - - enforce - - - - - (,1.8) - - - - - - diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java index 8426d1924..d3c078f9b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java @@ -36,10 +36,12 @@ public MediaWikiApi(String indexUrl, String niceUrlBase) { } /** - * The instance for wikis hosted by the Wikimedia Foundation. Consumers are requested on + * The instance for wikis hosted by the Wikimedia Foundation.Consumers are requested on * * Special:OAuthConsumerRegistration/propose * . + * + * @return instance */ public static MediaWikiApi instance() { return InstanceHolder.INSTANCE; @@ -50,6 +52,8 @@ public static MediaWikiApi instance() { * * Special:OAuthConsumerRegistration/propose * . + * + * @return instanceBeta */ public static MediaWikiApi instanceBeta() { return BetaInstanceHolder.BETA_INSTANCE; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index e10a57aeb..6eec12bb6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -75,7 +75,12 @@ public String getRevokeTokenEndpoint() { /** * Returns the URL where you should redirect your users to authenticate your application. * + * @param responseType responseType + * @param apiKey apiKey * @param additionalParams any additional GET params to add to the URL + * @param callback callback + * @param state state + * @param scope scope * @return the URL where you should redirect your users */ public String getAuthorizationUrl(String responseType, String apiKey, String callback, String scope, String state, diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java index acda30254..3547fbcac 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/BaseStringExtractorImpl.java @@ -32,6 +32,8 @@ protected String getVerb(OAuthRequest request) { /** * https://tools.ietf.org/html/rfc5849#section-3.4.1.2 + * @param request request + * @return url */ protected String getUrl(OAuthRequest request) { return request.getSanitizedUrl(); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java index 7e599c6e5..6da66f9de 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java @@ -40,19 +40,19 @@ * RFC 2045. * *
    - *
  • Basic + *
  • Basic *

    * Uses "The Base64 Alphabet" as specified in Table 1 of RFC 4648 and RFC 2045 for encoding and decoding operation. The * encoder does not add any line feed (line separator) character. The decoder rejects data that contains characters * outside the base64 alphabet.

  • * - *
  • URL and Filename safe + *
  • URL and Filename safe *

    * Uses the "URL and Filename safe Base64 Alphabet" as specified in Table 2 of RFC 4648 for encoding and decoding. The * encoder does not add any line feed (line separator) character. The decoder rejects data that contains characters * outside the base64 alphabet.

  • * - *
  • MIME + *
  • MIME *

    * Uses the "The Base64 Alphabet" as specified in Table 1 of RFC 2045 for encoding and decoding operation. The encoded * output must be represented in lines of no more than 76 characters each and uses a carriage return {@code '\r'} @@ -629,7 +629,8 @@ private int outLength(byte[] src, int sp, int sl) { len -= (sl - sp + 1); break; } - if ((b = base64[b]) == -1) { + b = base64[b]; + if (b == -1) { n++; } } @@ -655,7 +656,8 @@ private int decode0(byte[] src, int sp, int sl, byte[] dst) { int shiftto = 18; // pos of first byte of 4-byte atom while (sp < sl) { int b = src[sp++] & 0xff; - if ((b = base64[b]) < 0) { + b = base64[b]; + if (b < 0) { if (b == -2) { // padding byte '=' // = shiftto==18 unnecessary padding // x= shiftto==12 a dangling single x @@ -689,15 +691,20 @@ private int decode0(byte[] src, int sp, int sl, byte[] dst) { } } // reached end of byte array or hit padding '=' characters. - if (shiftto == 6) { - dst[dp++] = (byte) (bits >> 16); - } else if (shiftto == 0) { - dst[dp++] = (byte) (bits >> 16); - dst[dp++] = (byte) (bits >> 8); - } else if (shiftto == 12) { - // dangling single "x", incorrectly encoded. - throw new IllegalArgumentException( - "Last unit does not have enough valid bits"); + switch (shiftto) { + case 6: + dst[dp++] = (byte) (bits >> 16); + break; + case 0: + dst[dp++] = (byte) (bits >> 16); + dst[dp++] = (byte) (bits >> 8); + break; + case 12: + // dangling single "x", incorrectly encoded. + throw new IllegalArgumentException( + "Last unit does not have enough valid bits"); + default: + break; } // anything left is invalid, if is not MIME. // if MIME, ignore all non-base64 character @@ -929,7 +936,8 @@ public int read(byte[] b, int off, int len) throws IOException { eof = true; break; } - if ((v = base64[v]) == -1) { + v = base64[v]; + if (v == -1) { if (isMIME) // skip if for rfc2045 { continue; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index d132da1dc..87ace27bc 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -147,6 +147,9 @@ public void initMultipartBoundary() { /** * you can invoke {@link #initMultipartBoundary(java.lang.String) } to set custom boundary + * @param contentDisposition contentDisposition + * @param contentType contentType + * @param payload payload */ public void addMultipartPayload(String contentDisposition, String contentType, byte[] payload) { if (multipartPayload == null) { diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/services/RSASha1SignatureServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/services/RSASha1SignatureServiceTest.java index 261bc2bb4..adf93c68f 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/services/RSASha1SignatureServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/services/RSASha1SignatureServiceTest.java @@ -1,11 +1,11 @@ package com.github.scribejava.core.services; +import com.github.scribejava.core.java8.Base64; import java.security.KeyFactory; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.spec.InvalidKeySpecException; import java.security.spec.PKCS8EncodedKeySpec; -import javax.xml.bind.DatatypeConverter; import static org.junit.Assert.assertEquals; import org.junit.Test; @@ -48,11 +48,12 @@ private static PrivateKey getPrivateKey() { + "I/AfAkEA0Y9vr0tombsUB8cZv0v5OYoBZvCTbMANtzfb4AOHpiKqqbohDOevLQ7/\n" + "SpvgVCmVaDz2PptcRAyEBZ5MCssneQJAB2pmvaDH7Ambfod5bztLfOhLCtY5EkXJ\n" + "n6rZcDbRaHorRhdG7m3VtDKOUKZ2DF7glkQGV33phKukErVPUzlHBwJAScD9TqaG\n" - + "wJ3juUsVtujV23SnH43iMggXT7m82STpPGam1hPfmqu2Z0niePFo927ogQ7H1EMJ\n" + "UHgqXmuvk2X/Ww=="; + + "wJ3juUsVtujV23SnH43iMggXT7m82STpPGam1hPfmqu2Z0niePFo927ogQ7H1EMJ\n" + + "UHgqXmuvk2X/Ww=="; try { final KeyFactory fac = KeyFactory.getInstance("RSA"); - final PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(DatatypeConverter.parseBase64Binary(str)); + final PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(Base64.getMimeDecoder().decode(str)); return fac.generatePrivate(privKeySpec); } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { throw new RuntimeException(e); diff --git a/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java b/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java index 1ee1ebaa1..5de2d153e 100644 --- a/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java +++ b/scribejava-httpclient-ahc/src/test/java/com/github/scribejava/httpclient/ahc/AhcHttpClientTest.java @@ -2,9 +2,7 @@ import com.github.scribejava.core.AbstractClientTest; import com.github.scribejava.core.httpclient.HttpClient; -import org.junit.Ignore; -@Ignore(value = "we are java7 and AHC is java8") public class AhcHttpClientTest extends AbstractClientTest { @Override From d82112bb4d41c39265c3447c4d51ad97dff5ed2f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Oct 2018 11:54:50 +0300 Subject: [PATCH 121/481] switch OAuth2 Bearer Token Usage from enum OAuth2SignatureType to interface BearerSignature to be extensible --- README.md | 1 + changelog | 3 +- .../com/github/scribejava/apis/BoxApi20.java | 7 +++-- .../scribejava/apis/Foursquare2Api.java | 7 +++-- .../github/scribejava/apis/KaixinApi20.java | 7 +++-- .../com/github/scribejava/apis/LiveApi.java | 7 +++-- .../com/github/scribejava/apis/MisfitApi.java | 7 +++-- .../com/github/scribejava/apis/NaverApi.java | 7 +++-- .../scribejava/apis/OdnoklassnikiApi.java | 7 +++-- .../com/github/scribejava/apis/RenrenApi.java | 7 +++-- .../scribejava/apis/SinaWeiboApi20.java | 7 +++-- .../scribejava/apis/StackExchangeApi.java | 7 +++-- .../com/github/scribejava/apis/ViadeoApi.java | 7 +++-- .../github/scribejava/apis/VkontakteApi.java | 7 +++-- .../core/builder/api/DefaultApi20.java | 18 ++++++++++++ .../core/builder/api/OAuth2SignatureType.java | 19 +++++++++---- .../scribejava/core/oauth/OAuth20Service.java | 2 +- .../bearersignature/BearerSignature.java | 12 ++++++++ ...natureAuthorizationRequestHeaderField.java | 28 +++++++++++++++++++ .../BearerSignatureURIQueryParameter.java | 27 ++++++++++++++++++ .../scribejava/core/oauth/OAuth20ApiUnit.java | 7 +++-- 21 files changed, 154 insertions(+), 47 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignature.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureAuthorizationRequestHeaderField.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureURIQueryParameter.java diff --git a/README.md b/README.md index 6ab369f0f..4e82b188e 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ ScribeJava support out-of-box several HTTP clients: * RFC 6749 The OAuth 2.0 Authorization Framework, Authorization Code Authorization Grant [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java) * RFC 6749 The OAuth 2.0 Authorization Framework, Client Credentials Authorization Grant [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java) * RFC 6749 The OAuth 2.0 Authorization Framework, Resource Owner Password Credentials Authorization Grant + * RFC 6750 The OAuth 2.0 Authorization Framework: Bearer Token Usage * RFC 7636 Proof Key for Code Exchange by OAuth Public Clients (PKCE) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) * RFC 7009 OAuth 2.0 Token Revocation [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java) diff --git a/changelog b/changelog index e2df12e69..869884876 100644 --- a/changelog +++ b/changelog @@ -1,11 +1,12 @@ [SNAPSHOT] * make redirect_uri optional while Access Token requesting on OAuth 2.0 (thanks to https://github.com/computerlove) * switch to java 9+ (from java 7 only) for compilation. Runtime is still java 7+. Complement README with links and RFC descriptions. + * switch OAuth2 Bearer Token Usage from enum OAuth2SignatureType to interface BearerSignature to be extensible [5.6.0] * remove support for obsolete NetEase (http://www.163.com/) and sohu 搜狐 (http://www.sohu.com/) (thanks to https://github.com/zawn) * add Multipart functionality to JDK Http Client (thanks to https://github.com/eos1d3) - * switch OAuth2 ClientAuthenticationType from enum to interface to be extensible according to + * switch OAuth2 ClientAuthenticationType from enum to interface ClientAuthentication to be extensible according to https://tools.ietf.org/html/rfc6749#section-2.3.2 (thanks to https://github.com/zawn) * add RuntimeException processing in async http clients (delivered to onError callbacks) (thanks to https://github.com/jochen314) * check 200 status code from response in OAuth2AccessTokenExtractor (thanks to https://github.com/jochen314) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java index d21cc39be..91a4b7c16 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/BoxApi20.java @@ -1,7 +1,8 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; /** * Box.com Api @@ -31,7 +32,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java index 321554af2..a90547f3a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Foursquare2Api.java @@ -1,8 +1,9 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; public class Foursquare2Api extends DefaultApi20 { @@ -33,7 +34,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java index 927813535..b94e8e1a3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KaixinApi20.java @@ -1,8 +1,9 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; /** * Kaixin(http://www.kaixin001.com/) open platform api based on OAuth 2.0. @@ -36,7 +37,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java index 83cd89780..7a0a64ea5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/LiveApi.java @@ -1,7 +1,8 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; public class LiveApi extends DefaultApi20 { @@ -27,7 +28,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java index c34d2cc15..051de70c1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MisfitApi.java @@ -1,7 +1,8 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; public class MisfitApi extends DefaultApi20 { @@ -28,7 +29,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java index a3028ae11..3ff3a9b0a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java @@ -1,7 +1,8 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; public class NaverApi extends DefaultApi20 { protected NaverApi() { @@ -29,7 +30,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index e7db8838d..f82b585b6 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -2,9 +2,10 @@ import com.github.scribejava.apis.service.OdnoklassnikiOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; import java.io.OutputStream; @@ -41,8 +42,8 @@ public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java index cc475440e..d4ade9fad 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/RenrenApi.java @@ -1,8 +1,9 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; /** * Renren(http://www.renren.com/) OAuth 2.0 based api. @@ -36,7 +37,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java index edd316f87..19aa9f356 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SinaWeiboApi20.java @@ -1,7 +1,8 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; /** * SinaWeibo OAuth 2.0 api. @@ -30,7 +31,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java index 554c97b33..3ba195460 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/StackExchangeApi.java @@ -1,10 +1,11 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.extractors.OAuth2AccessTokenExtractor; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; /** * Stack Exchange authentication via OAuth 2.0 (stackoverflow.com, @@ -39,7 +40,7 @@ public TokenExtractor getAccessTokenExtractor() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java index 30c0ffcfe..fb70de258 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ViadeoApi.java @@ -1,8 +1,9 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; public class ViadeoApi extends DefaultApi20 { @@ -33,7 +34,7 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index ff11d902c..1662891c3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -2,10 +2,11 @@ import com.github.scribejava.apis.vk.VKJsonTokenExtractor; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; @@ -41,8 +42,8 @@ protected String getAuthorizationBaseUrl() { } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } @Override diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 6eec12bb6..84d7ab91c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -9,6 +9,9 @@ import com.github.scribejava.core.model.ParameterList; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureAuthorizationRequestHeaderField; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.HttpBasicAuthenticationScheme; import java.io.OutputStream; @@ -112,10 +115,25 @@ public OAuth20Service createService(String apiKey, String apiSecret, String call httpClientConfig, httpClient); } + /** + * @deprecated use {@link #getBearerSignature() } + */ + @Deprecated public OAuth2SignatureType getSignatureType() { return OAuth2SignatureType.BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD; } + public BearerSignature getBearerSignature() { + switch (getSignatureType()) { + case BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD: + return BearerSignatureAuthorizationRequestHeaderField.instance(); + case BEARER_URI_QUERY_PARAMETER: + return BearerSignatureURIQueryParameter.instance(); + default: + throw new IllegalStateException("unknown OAuth2SignatureType"); + } + } + public ClientAuthentication getClientAuthentication() { return HttpBasicAuthenticationScheme.instance(); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java index c42b54d98..baf246381 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java @@ -1,28 +1,35 @@ package com.github.scribejava.core.builder.api; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureAuthorizationRequestHeaderField; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; +/** + * @deprecated use {@link com.github.scribejava.core.oauth2.bearersignature.BearerSignature} + */ +@Deprecated public enum OAuth2SignatureType { /** - * https://tools.ietf.org/html/rfc6750#section-2.1 + * @deprecated use + * {@link com.github.scribejava.core.oauth2.bearersignature.BearerSignatureAuthorizationRequestHeaderField} */ + @Deprecated BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD { @Override public void signRequest(String accessToken, OAuthRequest request) { - request.addHeader("Authorization", "Bearer " + accessToken); + BearerSignatureAuthorizationRequestHeaderField.instance().signRequest(accessToken, request); } }, /** - * https://tools.ietf.org/html/rfc6750#section-2.3 + * @deprecated use {@link com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter} */ + @Deprecated BEARER_URI_QUERY_PARAMETER { @Override public void signRequest(String accessToken, OAuthRequest request) { - request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken); + BearerSignatureURIQueryParameter.instance().signRequest(accessToken, request); } - }; public abstract void signRequest(String accessToken, OAuthRequest request); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index d02b3f17b..f7564ff1d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -254,7 +254,7 @@ public String getVersion() { } public void signRequest(String accessToken, OAuthRequest request) { - api.getSignatureType().signRequest(accessToken, request); + api.getBearerSignature().signRequest(accessToken, request); } public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignature.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignature.java new file mode 100644 index 000000000..61739e93e --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignature.java @@ -0,0 +1,12 @@ +package com.github.scribejava.core.oauth2.bearersignature; + +import com.github.scribejava.core.model.OAuthRequest; + +/** + * Represents
    + * 2. Authenticated Requests
    + * https://tools.ietf.org/html/rfc6750#section-2 + */ +public interface BearerSignature { + void signRequest(String accessToken, OAuthRequest request); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureAuthorizationRequestHeaderField.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureAuthorizationRequestHeaderField.java new file mode 100644 index 000000000..72ab0cbd2 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureAuthorizationRequestHeaderField.java @@ -0,0 +1,28 @@ +package com.github.scribejava.core.oauth2.bearersignature; + +import com.github.scribejava.core.model.OAuthRequest; + +/** + * 2.1. Authorization Request Header Field
    + * https://tools.ietf.org/html/rfc6750#section-2.1 + */ +public class BearerSignatureAuthorizationRequestHeaderField implements BearerSignature { + + protected BearerSignatureAuthorizationRequestHeaderField() { + } + + private static class InstanceHolder { + + private static final BearerSignatureAuthorizationRequestHeaderField INSTANCE + = new BearerSignatureAuthorizationRequestHeaderField(); + } + + public static BearerSignatureAuthorizationRequestHeaderField instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + request.addHeader("Authorization", "Bearer " + accessToken); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureURIQueryParameter.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureURIQueryParameter.java new file mode 100644 index 000000000..72cc64b43 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureURIQueryParameter.java @@ -0,0 +1,27 @@ +package com.github.scribejava.core.oauth2.bearersignature; + +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; + +/** + * 2.3. URI Query Parameter
    + * https://tools.ietf.org/html/rfc6750#section-2.3 + */ +public class BearerSignatureURIQueryParameter implements BearerSignature { + protected BearerSignatureURIQueryParameter() { + } + + private static class InstanceHolder { + + private static final BearerSignatureURIQueryParameter INSTANCE = new BearerSignatureURIQueryParameter(); + } + + public static BearerSignatureURIQueryParameter instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken); + } +} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java index a3187957e..8d7777f86 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java @@ -1,9 +1,10 @@ package com.github.scribejava.core.oauth; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; import java.io.OutputStream; class OAuth20ApiUnit extends DefaultApi20 { @@ -27,7 +28,7 @@ public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String } @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); } } From 82fbbcc69f11f779771cbee97689a69ab023aa53 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Oct 2018 12:40:40 +0300 Subject: [PATCH 122/481] move Bearer Token Usage logic from MicrosoftAzureActiveDirectoryService and TutByOAuthService to their BearerSignature implementations --- .../MicrosoftAzureActiveDirectoryApi.java | 11 ++++++++ .../com/github/scribejava/apis/TutByApi.java | 11 ++++++++ ...ftAzureActiveDirectoryBearerSignature.java | 28 +++++++++++++++++++ .../MicrosoftAzureActiveDirectoryService.java | 14 +++++++--- .../apis/service/TutByOAuthService.java | 12 ++++++-- .../apis/tutby/TutByBearerSignature.java | 25 +++++++++++++++++ 6 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectoryBearerSignature.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/tutby/TutByBearerSignature.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java index 2c793ae14..2bbbe2ac5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java @@ -1,9 +1,11 @@ package com.github.scribejava.apis; +import com.github.scribejava.apis.microsoftazureactivedirectory.MicrosoftAzureActiveDirectoryBearerSignature; import com.github.scribejava.apis.service.MicrosoftAzureActiveDirectoryService; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; import java.io.OutputStream; @@ -49,6 +51,10 @@ protected String getAuthorizationBaseUrl() { return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI; } + /** + * @deprecated moved to {@link #getBearerSignature() } + */ + @Deprecated @Override public MicrosoftAzureActiveDirectoryService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, @@ -61,4 +67,9 @@ public MicrosoftAzureActiveDirectoryService createService(String apiKey, String public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } + + @Override + public BearerSignature getBearerSignature() { + return MicrosoftAzureActiveDirectoryBearerSignature.instance(); + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java index 377bc9046..94905a010 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java @@ -1,9 +1,11 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.service.TutByOAuthService; +import com.github.scribejava.apis.tutby.TutByBearerSignature; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; import java.io.OutputStream; public class TutByApi extends DefaultApi20 { @@ -29,6 +31,10 @@ protected String getAuthorizationBaseUrl() { return "http://profile.tut.by/auth"; } + /** + * @deprecated moved to {@link #getBearerSignature() } + */ + @Deprecated @Override public TutByOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, @@ -36,4 +42,9 @@ public TutByOAuthService createService(String apiKey, String apiSecret, String c return new TutByOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } + + @Override + public BearerSignature getBearerSignature() { + return TutByBearerSignature.instance(); + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectoryBearerSignature.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectoryBearerSignature.java new file mode 100644 index 000000000..dddf62d50 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectoryBearerSignature.java @@ -0,0 +1,28 @@ +package com.github.scribejava.apis.microsoftazureactivedirectory; + +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureAuthorizationRequestHeaderField; + +public class MicrosoftAzureActiveDirectoryBearerSignature extends BearerSignatureAuthorizationRequestHeaderField { + private static final String ACCEPTED_FORMAT + = "application/json; odata=minimalmetadata; streaming=true; charset=utf-8"; + + protected MicrosoftAzureActiveDirectoryBearerSignature() { + } + + private static class InstanceHolder { + + private static final MicrosoftAzureActiveDirectoryBearerSignature INSTANCE + = new MicrosoftAzureActiveDirectoryBearerSignature(); + } + + public static MicrosoftAzureActiveDirectoryBearerSignature instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + super.signRequest(accessToken, request); + request.addHeader("Accept", ACCEPTED_FORMAT); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java index bab20d3b7..e2ff45c3b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java @@ -6,20 +6,26 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; +/** + * @deprecated doesn't do anything useful, all MicrosoftAzureActiveDirectory specific logic was moved to + * {@link com.github.scribejava.apis.microsoftazureactivedirectory.MicrosoftAzureActiveDirectoryBearerSignature} + */ +@Deprecated public class MicrosoftAzureActiveDirectoryService extends OAuth20Service { - private static final String ACCEPTED_FORMAT - = "application/json; odata=minimalmetadata; streaming=true; charset=utf-8"; - public MicrosoftAzureActiveDirectoryService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } + /** + * @deprecated moved to + * {@link com.github.scribejava.apis.microsoftazureactivedirectory.MicrosoftAzureActiveDirectoryBearerSignature} + */ + @Deprecated @Override public void signRequest(String accessToken, OAuthRequest request) { super.signRequest(accessToken, request); - request.addHeader("Accept", ACCEPTED_FORMAT); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java index 82ded6c92..1b92ca8da 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java @@ -3,10 +3,14 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; +/** + * @deprecated doesn't do anything useful, all TutBy specific logic was moved to + * {@link com.github.scribejava.apis.tutby.TutByBearerSignature} + */ +@Deprecated public class TutByOAuthService extends OAuth20Service { public TutByOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, @@ -15,8 +19,12 @@ public TutByOAuthService(DefaultApi20 api, String apiKey, String apiSecret, Stri super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } + /** + * @deprecated moved to {@link com.github.scribejava.apis.tutby.TutByBearerSignature} + */ + @Deprecated @Override public void signRequest(String accessToken, OAuthRequest request) { - request.addQuerystringParameter(OAuthConstants.TOKEN, accessToken); + super.signRequest(accessToken, request); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/tutby/TutByBearerSignature.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/tutby/TutByBearerSignature.java new file mode 100644 index 000000000..0c7609073 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/tutby/TutByBearerSignature.java @@ -0,0 +1,25 @@ +package com.github.scribejava.apis.tutby; + +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; + +public class TutByBearerSignature implements BearerSignature { + + protected TutByBearerSignature() { + } + + private static class InstanceHolder { + + private static final TutByBearerSignature INSTANCE = new TutByBearerSignature(); + } + + public static TutByBearerSignature instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + request.addQuerystringParameter(OAuthConstants.TOKEN, accessToken); + } +} From 73fc48f5b134c79f0027b14e197d2399e8611ee3 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Oct 2018 13:09:45 +0300 Subject: [PATCH 123/481] move all classes from com.github.scribejava.apis.services to their APIs packages --- .../github/scribejava/apis/FacebookApi.java | 2 +- .../com/github/scribejava/apis/ImgurApi.java | 2 +- .../com/github/scribejava/apis/MailruApi.java | 2 +- .../scribejava/apis/OdnoklassnikiApi.java | 2 +- .../apis/facebook/FacebookService.java | 43 +++++++++++ .../apis/imgur/ImgurOAuthService.java | 40 +++++++++++ .../apis/mailru/MailruOAuthService.java | 72 +++++++++++++++++++ .../OdnoklassnikiOAuthService.java | 69 ++++++++++++++++++ .../apis/service/FacebookService.java | 35 ++------- .../apis/service/ImgurOAuthService.java | 32 ++------- .../apis/service/MailruOAuthService.java | 64 ++--------------- .../service/OdnoklassnikiOAuthService.java | 60 ++-------------- 12 files changed, 248 insertions(+), 175 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index fb0668eb1..6418d8964 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.facebook.FacebookAccessTokenJsonExtractor; -import com.github.scribejava.apis.service.FacebookService; +import com.github.scribejava.apis.facebook.FacebookService; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.httpclient.HttpClient; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index b8c802647..f04736880 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -1,6 +1,6 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.service.ImgurOAuthService; +import com.github.scribejava.apis.imgur.ImgurOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index 05ae5cb8a..3835fff49 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis; +import com.github.scribejava.apis.mailru.MailruOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.apis.service.MailruOAuthService; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import java.io.OutputStream; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index f82b585b6..f0d873b71 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -1,6 +1,6 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.service.OdnoklassnikiOAuthService; +import com.github.scribejava.apis.odnoklassniki.OdnoklassnikiOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java new file mode 100644 index 000000000..6aa4419e1 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java @@ -0,0 +1,43 @@ +package com.github.scribejava.apis.facebook; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.util.Formatter; +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; + +public class FacebookService extends OAuth20Service { + + public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + super.signRequest(accessToken, request); + + final Mac mac; + try { + mac = Mac.getInstance("HmacSHA256"); + final SecretKeySpec secretKey = new SecretKeySpec(getApiSecret().getBytes(), "HmacSHA256"); + mac.init(secretKey); + + final Formatter appsecretProof = new Formatter(); + + for (byte b : mac.doFinal(accessToken.getBytes())) { + appsecretProof.format("%02x", b); + } + + request.addParameter("appsecret_proof", appsecretProof.toString()); + } catch (NoSuchAlgorithmException | InvalidKeyException e) { + throw new IllegalStateException("There is a problem while generating Facebook appsecret_proof.", e); + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java new file mode 100644 index 000000000..f37dfab95 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java @@ -0,0 +1,40 @@ +package com.github.scribejava.apis.imgur; + +import com.github.scribejava.apis.ImgurApi; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; + +public class ImgurOAuthService extends OAuth20Service { + + public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + @Override + protected OAuthRequest createAccessTokenRequest(String oauthVerifier) { + final DefaultApi20 api = getApi(); + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); + request.addBodyParameter(OAuthConstants.CLIENT_ID, getApiKey()); + request.addBodyParameter(OAuthConstants.CLIENT_SECRET, getApiSecret()); + + if (ImgurApi.isOob(getCallback())) { + request.addBodyParameter(OAuthConstants.GRANT_TYPE, "pin"); + request.addBodyParameter("pin", oauthVerifier); + } else { + request.addBodyParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); + request.addBodyParameter(OAuthConstants.CODE, oauthVerifier); + } + return request; + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + request.addHeader("Authorization", accessToken == null ? "Client-ID " + getApiKey() : "Bearer " + accessToken); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java new file mode 100644 index 000000000..f17a922a1 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java @@ -0,0 +1,72 @@ +package com.github.scribejava.apis.mailru; + +import java.net.URLDecoder; +import java.util.Map; +import java.util.TreeMap; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Formatter; + +public class MailruOAuthService extends OAuth20Service { + + public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + // sig = md5(params + secret_key) + request.addQuerystringParameter("session_key", accessToken); + request.addQuerystringParameter("app_id", getApiKey()); + final String completeUrl = request.getCompleteUrl(); + + try { + final String clientSecret = getApiSecret(); + final int queryIndex = completeUrl.indexOf('?'); + if (queryIndex != -1) { + final String urlPart = completeUrl.substring(queryIndex + 1); + final Map map = new TreeMap<>(); + for (String param : urlPart.split("&")) { + final String[] parts = param.split("="); + map.put(parts[0], (parts.length == 1) ? "" : parts[1]); + } + + final StringBuilder urlNew = new StringBuilder(); + for (Map.Entry entry : map.entrySet()) { + urlNew.append(entry.getKey()); + urlNew.append('='); + urlNew.append(entry.getValue()); + } + + final String sigSource = URLDecoder.decode(urlNew.toString(), "UTF-8") + clientSecret; + request.addQuerystringParameter("sig", md5(sigSource)); + } + } catch (UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + } + + public static String md5(String orgString) { + try { + final MessageDigest md = MessageDigest.getInstance("MD5"); + final byte[] array = md.digest(orgString.getBytes(Charset.forName("UTF-8"))); + final Formatter builder = new Formatter(); + for (byte b : array) { + builder.format("%02x", b); + } + return builder.toString(); + } catch (NoSuchAlgorithmException e) { + throw new IllegalStateException("MD5 is unsupported?", e); + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java new file mode 100644 index 000000000..16a9f10a5 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java @@ -0,0 +1,69 @@ +package com.github.scribejava.apis.odnoklassniki; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Parameter; +import com.github.scribejava.core.model.ParameterList; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.UnsupportedEncodingException; + +import java.net.URLDecoder; +import java.nio.charset.Charset; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Collections; +import java.util.Formatter; +import java.util.List; + +public class OdnoklassnikiOAuthService extends OAuth20Service { + + public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + //sig = lower(md5( sorted_request_params_composed_string + md5(access_token + application_secret_key))) + try { + final String tokenDigest = md5(accessToken + getApiSecret()); + + final ParameterList queryParams = request.getQueryStringParams(); + queryParams.addAll(request.getBodyParams()); + final List allParams = queryParams.getParams(); + + Collections.sort(allParams); + + final StringBuilder stringParams = new StringBuilder(); + for (Parameter param : allParams) { + stringParams.append(param.getKey()) + .append('=') + .append(param.getValue()); + } + + final String sigSource = URLDecoder.decode(stringParams.toString(), "UTF-8") + tokenDigest; + request.addQuerystringParameter("sig", md5(sigSource).toLowerCase()); + + super.signRequest(accessToken, request); + } catch (UnsupportedEncodingException unex) { + throw new IllegalStateException(unex); + } + } + + public static String md5(String orgString) { + try { + final MessageDigest md = MessageDigest.getInstance("MD5"); + final byte[] array = md.digest(orgString.getBytes(Charset.forName("UTF-8"))); + final Formatter builder = new Formatter(); + for (byte b : array) { + builder.format("%02x", b); + } + return builder.toString(); + } catch (NoSuchAlgorithmException e) { + throw new IllegalStateException("MD5 is unsupported?", e); + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java index 51e282310..ca14eb8c4 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java @@ -3,41 +3,16 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.util.Formatter; -import javax.crypto.Mac; -import javax.crypto.spec.SecretKeySpec; -public class FacebookService extends OAuth20Service { +/** + * @deprecated moved to {@link com.github.scribejava.apis.facebook.FacebookService} + */ +@Deprecated +public class FacebookService extends com.github.scribejava.apis.facebook.FacebookService { public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } - - @Override - public void signRequest(String accessToken, OAuthRequest request) { - super.signRequest(accessToken, request); - - final Mac mac; - try { - mac = Mac.getInstance("HmacSHA256"); - final SecretKeySpec secretKey = new SecretKeySpec(getApiSecret().getBytes(), "HmacSHA256"); - mac.init(secretKey); - - final Formatter appsecretProof = new Formatter(); - - for (byte b : mac.doFinal(accessToken.getBytes())) { - appsecretProof.format("%02x", b); - } - - request.addParameter("appsecret_proof", appsecretProof.toString()); - } catch (NoSuchAlgorithmException | InvalidKeyException e) { - throw new IllegalStateException("There is a problem while generating Facebook appsecret_proof.", e); - } - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java index e1b146846..fb51337da 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java @@ -1,40 +1,18 @@ package com.github.scribejava.apis.service; -import com.github.scribejava.apis.ImgurApi; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; -public class ImgurOAuthService extends OAuth20Service { +/** + * @deprecated moved to {@link com.github.scribejava.apis.imgur.ImgurOAuthService} + */ +@Deprecated +public class ImgurOAuthService extends com.github.scribejava.apis.imgur.ImgurOAuthService { public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } - - @Override - protected OAuthRequest createAccessTokenRequest(String oauthVerifier) { - final DefaultApi20 api = getApi(); - final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - request.addBodyParameter(OAuthConstants.CLIENT_ID, getApiKey()); - request.addBodyParameter(OAuthConstants.CLIENT_SECRET, getApiSecret()); - - if (ImgurApi.isOob(getCallback())) { - request.addBodyParameter(OAuthConstants.GRANT_TYPE, "pin"); - request.addBodyParameter("pin", oauthVerifier); - } else { - request.addBodyParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); - request.addBodyParameter(OAuthConstants.CODE, oauthVerifier); - } - return request; - } - - @Override - public void signRequest(String accessToken, OAuthRequest request) { - request.addHeader("Authorization", accessToken == null ? "Client-ID " + getApiKey() : "Bearer " + accessToken); - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java index f40727f53..c1593dd45 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java @@ -1,72 +1,18 @@ package com.github.scribejava.apis.service; -import java.net.URLDecoder; -import java.util.Map; -import java.util.TreeMap; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; -import java.io.UnsupportedEncodingException; -import java.nio.charset.Charset; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Formatter; -public class MailruOAuthService extends OAuth20Service { +/** + * @deprecated moved to {@link com.github.scribejava.apis.mailru.MailruOAuthService} + */ +@Deprecated +public class MailruOAuthService extends com.github.scribejava.apis.mailru.MailruOAuthService { public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } - - - @Override - public void signRequest(String accessToken, OAuthRequest request) { - // sig = md5(params + secret_key) - request.addQuerystringParameter("session_key", accessToken); - request.addQuerystringParameter("app_id", getApiKey()); - final String completeUrl = request.getCompleteUrl(); - - try { - final String clientSecret = getApiSecret(); - final int queryIndex = completeUrl.indexOf('?'); - if (queryIndex != -1) { - final String urlPart = completeUrl.substring(queryIndex + 1); - final Map map = new TreeMap<>(); - for (String param : urlPart.split("&")) { - final String[] parts = param.split("="); - map.put(parts[0], (parts.length == 1) ? "" : parts[1]); - } - - final StringBuilder urlNew = new StringBuilder(); - for (Map.Entry entry : map.entrySet()) { - urlNew.append(entry.getKey()); - urlNew.append('='); - urlNew.append(entry.getValue()); - } - - final String sigSource = URLDecoder.decode(urlNew.toString(), "UTF-8") + clientSecret; - request.addQuerystringParameter("sig", md5(sigSource)); - } - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException(e); - } - } - - public static String md5(String orgString) { - try { - final MessageDigest md = MessageDigest.getInstance("MD5"); - final byte[] array = md.digest(orgString.getBytes(Charset.forName("UTF-8"))); - final Formatter builder = new Formatter(); - for (byte b : array) { - builder.format("%02x", b); - } - return builder.toString(); - } catch (NoSuchAlgorithmException e) { - throw new IllegalStateException("MD5 is unsupported?", e); - } - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java index 34bd0fe89..46a34102f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java @@ -3,21 +3,12 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Parameter; -import com.github.scribejava.core.model.ParameterList; -import com.github.scribejava.core.oauth.OAuth20Service; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.nio.charset.Charset; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Collections; -import java.util.Formatter; -import java.util.List; - -public class OdnoklassnikiOAuthService extends OAuth20Service { +/** + * @deprecated moved to {@link com.github.scribejava.apis.odnoklassniki.OdnoklassnikiOAuthService} + */ +@Deprecated +public class OdnoklassnikiOAuthService extends com.github.scribejava.apis.odnoklassniki.OdnoklassnikiOAuthService { public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, @@ -25,45 +16,4 @@ public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecr super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } - @Override - public void signRequest(String accessToken, OAuthRequest request) { - //sig = lower(md5( sorted_request_params_composed_string + md5(access_token + application_secret_key))) - try { - final String tokenDigest = md5(accessToken + getApiSecret()); - - final ParameterList queryParams = request.getQueryStringParams(); - queryParams.addAll(request.getBodyParams()); - final List allParams = queryParams.getParams(); - - Collections.sort(allParams); - - final StringBuilder stringParams = new StringBuilder(); - for (Parameter param : allParams) { - stringParams.append(param.getKey()) - .append('=') - .append(param.getValue()); - } - - final String sigSource = URLDecoder.decode(stringParams.toString(), "UTF-8") + tokenDigest; - request.addQuerystringParameter("sig", md5(sigSource).toLowerCase()); - - super.signRequest(accessToken, request); - } catch (UnsupportedEncodingException unex) { - throw new IllegalStateException(unex); - } - } - - public static String md5(String orgString) { - try { - final MessageDigest md = MessageDigest.getInstance("MD5"); - final byte[] array = md.digest(orgString.getBytes(Charset.forName("UTF-8"))); - final Formatter builder = new Formatter(); - for (byte b : array) { - builder.format("%02x", b); - } - return builder.toString(); - } catch (NoSuchAlgorithmException e) { - throw new IllegalStateException("MD5 is unsupported?", e); - } - } } From 8269f2ac9b3455899fcf8dd0a987c34538ca76ba Mon Sep 17 00:00:00 2001 From: M-F-K Date: Mon, 16 Jul 2018 16:19:47 +0200 Subject: [PATCH 124/481] Add support for the Wunderlist API --- .../scribejava/apis/WunderlistAPI20.java | 43 +++++++++++ .../apis/examples/Wunderlist20Example.java | 76 +++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI20.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Wunderlist20Example.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI20.java new file mode 100644 index 000000000..b7e82456a --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI20.java @@ -0,0 +1,43 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.ClientAuthenticationType; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.OAuth2SignatureType; + +/** + * Wunderlist.com Api + */ +public class WunderlistAPI20 extends DefaultApi20 { + + + protected WunderlistAPI20() { + } + + private static class InstanceHolder { + private static final WunderlistAPI20 INSTANCE = new WunderlistAPI20(); + } + + public static WunderlistAPI20 instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://www.wunderlist.com/oauth/access_token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://www.wunderlist.com/oauth/authorize"; + } + + @Override + public OAuth2SignatureType getSignatureType() { + return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; + } + + @Override + public ClientAuthenticationType getClientAuthenticationType() { + return ClientAuthenticationType.REQUEST_BODY; + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Wunderlist20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Wunderlist20Example.java new file mode 100644 index 000000000..3528f3e9d --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Wunderlist20Example.java @@ -0,0 +1,76 @@ +package com.github.scribejava.apis.examples; + +import java.io.IOException; +import java.util.Random; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +import com.github.scribejava.apis.WunderlistAPI20; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +public class Wunderlist20Example { + + private static final String NETWORK_NAME = "Wunderlist"; + private static final String PROTECTED_RESOURCE_URL = "https://a.wunderlist.com/api/v1/user"; + + private Wunderlist20Example() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your own values + final String apiKey = "your_api_key"; + final String apiSecret = "your_api_secret"; + final String callbackUrl = "http://example.com/callback"; + final String secretState = "security_token" + new Random().nextInt(999_999); + + final OAuth20Service service = new ServiceBuilder(apiKey) + .apiSecret(apiSecret) + .callback(callbackUrl) + .state(secretState) + .debug() + .build(WunderlistAPI20.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + in.close(); + System.out.println(); + + // Trade the Request Token and Verifier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + request.addHeader("X-Client-ID", apiKey); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} From f571674dfd9f882583f7be0889b0942135bb13a2 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Oct 2018 13:34:11 +0300 Subject: [PATCH 125/481] add new API Wunderlist (https://www.wunderlist.com/) (thanks to https://github.com/M-F-K) --- README.md | 3 +- changelog | 1 + .../github/scribejava/apis/WunderlistAPI.java | 58 +++++++++++++++++++ .../scribejava/apis/WunderlistAPI20.java | 43 -------------- .../apis/service/WunderlistOAuthService.java | 22 +++++++ ...t20Example.java => WunderlistExample.java} | 46 +++++++-------- 6 files changed, 105 insertions(+), 68 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI20.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/WunderlistOAuthService.java rename scribejava-apis/src/test/java/com/github/scribejava/apis/examples/{Wunderlist20Example.java => WunderlistExample.java} (68%) diff --git a/README.md b/README.md index 4e82b188e..b2ca047e7 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ ScribeJava support out-of-box several HTTP clients: * LinkedIn (https://www.linkedin.com/) * Microsoft Azure Active Directory (Azure AD) (http://azure.microsoft.com/) * Microsoft Live (https://login.live.com/) +* Misfit (http://misfit.com/) * Mail.Ru (https://mail.ru/) * MediaWiki (https://www.mediawiki.org/) * Meetup (http://www.meetup.com/) @@ -94,9 +95,9 @@ ScribeJava support out-of-box several HTTP clients: * uCoz (https://www.ucoz.com/) * Viadeo (http://viadeo.com/) * VK ВКонтакте (http://vk.com/) +* Wunderlist (https://www.wunderlist.com/) * XING (https://www.xing.com/) * Yahoo (https://www.yahoo.com/) -* Misfit (http://misfit.com/) * check the [examples folder](https://github.com/scribejava/scribejava/tree/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples) ### Small and modular diff --git a/changelog b/changelog index 869884876..5019675e9 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * make redirect_uri optional while Access Token requesting on OAuth 2.0 (thanks to https://github.com/computerlove) * switch to java 9+ (from java 7 only) for compilation. Runtime is still java 7+. Complement README with links and RFC descriptions. * switch OAuth2 Bearer Token Usage from enum OAuth2SignatureType to interface BearerSignature to be extensible + * add new API Wunderlist (https://www.wunderlist.com/) (thanks to https://github.com/M-F-K) [5.6.0] * remove support for obsolete NetEase (http://www.163.com/) and sohu 搜狐 (http://www.sohu.com/) (thanks to https://github.com/zawn) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java new file mode 100644 index 000000000..989725155 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java @@ -0,0 +1,58 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.service.WunderlistOAuthService; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; +import java.io.OutputStream; + +/** + * Wunderlist.com Api + */ +public class WunderlistAPI extends DefaultApi20 { + + protected WunderlistAPI() { + } + + private static class InstanceHolder { + + private static final WunderlistAPI INSTANCE = new WunderlistAPI(); + } + + public static WunderlistAPI instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://www.wunderlist.com/oauth/access_token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://www.wunderlist.com/oauth/authorize"; + } + + @Override + public BearerSignature getBearerSignature() { + return BearerSignatureURIQueryParameter.instance(); + } + + @Override + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); + } + + @Override + public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String state, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new WunderlistOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, + httpClientConfig, httpClient); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI20.java deleted file mode 100644 index b7e82456a..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI20.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.ClientAuthenticationType; -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; - -/** - * Wunderlist.com Api - */ -public class WunderlistAPI20 extends DefaultApi20 { - - - protected WunderlistAPI20() { - } - - private static class InstanceHolder { - private static final WunderlistAPI20 INSTANCE = new WunderlistAPI20(); - } - - public static WunderlistAPI20 instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getAccessTokenEndpoint() { - return "https://www.wunderlist.com/oauth/access_token"; - } - - @Override - protected String getAuthorizationBaseUrl() { - return "https://www.wunderlist.com/oauth/authorize"; - } - - @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_URI_QUERY_PARAMETER; - } - - @Override - public ClientAuthenticationType getClientAuthenticationType() { - return ClientAuthenticationType.REQUEST_BODY; - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/WunderlistOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/WunderlistOAuthService.java new file mode 100644 index 000000000..1374a9e61 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/WunderlistOAuthService.java @@ -0,0 +1,22 @@ +package com.github.scribejava.apis.service; + +import com.github.scribejava.apis.WunderlistAPI; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.OAuth20Service; + +public class WunderlistOAuthService extends OAuth20Service { + + public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, String scope, + String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + super.signRequest(accessToken, request); + request.addHeader("X-Client-ID", getApiKey()); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Wunderlist20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java similarity index 68% rename from scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Wunderlist20Example.java rename to scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java index 3528f3e9d..91bb5f523 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Wunderlist20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java @@ -5,7 +5,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -import com.github.scribejava.apis.WunderlistAPI20; +import com.github.scribejava.apis.WunderlistAPI; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; @@ -13,43 +13,42 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; -public class Wunderlist20Example { +public class WunderlistExample { private static final String NETWORK_NAME = "Wunderlist"; private static final String PROTECTED_RESOURCE_URL = "https://a.wunderlist.com/api/v1/user"; - private Wunderlist20Example() { + private WunderlistExample() { } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own values - final String apiKey = "your_api_key"; - final String apiSecret = "your_api_secret"; + final String apiKey = "apiKey"; + final String apiSecret = "apiSecret"; final String callbackUrl = "http://example.com/callback"; - final String secretState = "security_token" + new Random().nextInt(999_999); - + final String secretState = "security_token" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .callback(callbackUrl) .state(secretState) .debug() - .build(WunderlistAPI20.instance()); - final Scanner in = new Scanner(System.in, "UTF-8"); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); - System.out.println(); - + .build(WunderlistAPI.instance()); - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - final String code = in.nextLine(); - in.close(); + final String code; + try (Scanner in = new Scanner(System.in, "UTF-8")) { + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + code = in.nextLine(); + } System.out.println(); // Trade the Request Token and Verifier for the Access Token @@ -62,7 +61,6 @@ public static void main(String... args) throws IOException, InterruptedException // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); - request.addHeader("X-Client-ID", apiKey); service.signRequest(accessToken, request); final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); From bdd1741370c056f7322669f438b7eb12b9e2318b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Oct 2018 13:48:26 +0300 Subject: [PATCH 126/481] move all classes from com.github.scribejava.apis.services to their APIs packages - 2 --- .../src/main/java/com/github/scribejava/apis/WunderlistAPI.java | 2 +- .../apis/{service => wunderlist}/WunderlistOAuthService.java | 2 +- .../{service => odnoklassniki}/OdnoklassnikiServiceTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename scribejava-apis/src/main/java/com/github/scribejava/apis/{service => wunderlist}/WunderlistOAuthService.java (95%) rename scribejava-apis/src/test/java/com/github/scribejava/apis/{service => odnoklassniki}/OdnoklassnikiServiceTest.java (97%) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java index 989725155..e8eb92111 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java @@ -1,6 +1,6 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.service.WunderlistOAuthService; +import com.github.scribejava.apis.wunderlist.WunderlistOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/WunderlistOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java similarity index 95% rename from scribejava-apis/src/main/java/com/github/scribejava/apis/service/WunderlistOAuthService.java rename to scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java index 1374a9e61..e5a5b07a7 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/WunderlistOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java @@ -1,4 +1,4 @@ -package com.github.scribejava.apis.service; +package com.github.scribejava.apis.wunderlist; import com.github.scribejava.apis.WunderlistAPI; import com.github.scribejava.core.httpclient.HttpClient; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/service/OdnoklassnikiServiceTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiServiceTest.java similarity index 97% rename from scribejava-apis/src/test/java/com/github/scribejava/apis/service/OdnoklassnikiServiceTest.java rename to scribejava-apis/src/test/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiServiceTest.java index 0dded23fb..f1e108f49 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/service/OdnoklassnikiServiceTest.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiServiceTest.java @@ -1,4 +1,4 @@ -package com.github.scribejava.apis.service; +package com.github.scribejava.apis.odnoklassniki; import com.github.scribejava.apis.OdnoklassnikiApi; import com.github.scribejava.core.builder.ServiceBuilder; From a5b7b1e6f59e85944b8afbb5a9179c8047a25178 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Oct 2018 14:06:24 +0300 Subject: [PATCH 127/481] update dependencies --- pom.xml | 2 +- .../com/github/scribejava/core/builder/api/DefaultApi20.java | 1 + scribejava-httpclient-ahc/pom.xml | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 85d155e54..574a9913c 100644 --- a/pom.xml +++ b/pom.xml @@ -107,7 +107,7 @@ com.puppycrawl.tools checkstyle - 8.12 + 8.13 diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 84d7ab91c..75cdd40ba 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -116,6 +116,7 @@ public OAuth20Service createService(String apiKey, String apiSecret, String call } /** + * @return OAuth2SignatureType * @deprecated use {@link #getBearerSignature() } */ @Deprecated diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index ec7ab0a77..4828697c4 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -8,7 +8,7 @@ 5.6.1-SNAPSHOT ../pom.xml - + com.github.scribejava scribejava-httpclient-ahc ScribeJava Async Http Http Client support @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.5.3 + 2.5.4 com.github.scribejava From dcfc1d1b9ca0a905e5bcee3ff69addb72afc96cf Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Oct 2018 14:19:25 +0300 Subject: [PATCH 128/481] prepare release v6.0.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b2ca047e7..2cc181033 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 5.6.0 + 6.0.0 ``` @@ -132,7 +132,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 5.6.0 + 6.0.0 ``` diff --git a/changelog b/changelog index 5019675e9..81c5e188d 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.0.0] * make redirect_uri optional while Access Token requesting on OAuth 2.0 (thanks to https://github.com/computerlove) * switch to java 9+ (from java 7 only) for compilation. Runtime is still java 7+. Complement README with links and RFC descriptions. * switch OAuth2 Bearer Token Usage from enum OAuth2SignatureType to interface BearerSignature to be extensible From 785e8f68c2e2126705451a5ed3026310e4a2fb31 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Oct 2018 14:21:42 +0300 Subject: [PATCH 129/481] [maven-release-plugin] prepare release scribejava-6.0.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 574a9913c..42a99b4c5 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 5.6.1-SNAPSHOT + 6.0.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.0.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 3cc2f5f5a..88d931471 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.1-SNAPSHOT + 6.0.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index b07f9627b..4f866dc84 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.1-SNAPSHOT + 6.0.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 4828697c4..db7d34d1f 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.1-SNAPSHOT + 6.0.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index f49a10a12..10c48bf42 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.1-SNAPSHOT + 6.0.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index dffa0f860..ba1f6a2bb 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.1-SNAPSHOT + 6.0.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 3d249abe7..640477e11 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 5.6.1-SNAPSHOT + 6.0.0 ../pom.xml From 4f14bdbf5e9148e077eb85ef2398f2c39005e650 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Oct 2018 14:21:49 +0300 Subject: [PATCH 130/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 42a99b4c5..85f930caf 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.0.0 + 6.0.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.0.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 88d931471..c96f2850c 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.0 + 6.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 4f866dc84..5924eab0d 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.0 + 6.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index db7d34d1f..a8826d0d1 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.0 + 6.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 10c48bf42..41694af95 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.0 + 6.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index ba1f6a2bb..7226faaea 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.0 + 6.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 640477e11..b93300259 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.0 + 6.0.1-SNAPSHOT ../pom.xml From 73c2ef4a3984336dfa3474a52e6e390170bc3fdc Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Oct 2018 14:47:45 +0300 Subject: [PATCH 131/481] remove deprecated code --- .../MicrosoftAzureActiveDirectoryApi.java | 16 --------- .../com/github/scribejava/apis/TutByApi.java | 16 --------- .../apis/service/FacebookService.java | 18 ---------- .../apis/service/ImgurOAuthService.java | 18 ---------- .../apis/service/MailruOAuthService.java | 18 ---------- .../MicrosoftAzureActiveDirectoryService.java | 31 ---------------- .../service/OdnoklassnikiOAuthService.java | 19 ---------- .../apis/service/TutByOAuthService.java | 30 ---------------- .../core/builder/api/DefaultApi20.java | 19 +--------- .../core/builder/api/OAuth2SignatureType.java | 36 ------------------- 10 files changed, 1 insertion(+), 220 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java index 2bbbe2ac5..6817cc686 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java @@ -1,14 +1,10 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.microsoftazureactivedirectory.MicrosoftAzureActiveDirectoryBearerSignature; -import com.github.scribejava.apis.service.MicrosoftAzureActiveDirectoryService; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; -import java.io.OutputStream; /** * Microsoft Azure Active Directory Api @@ -51,18 +47,6 @@ protected String getAuthorizationBaseUrl() { return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI; } - /** - * @deprecated moved to {@link #getBearerSignature() } - */ - @Deprecated - @Override - public MicrosoftAzureActiveDirectoryService createService(String apiKey, String apiSecret, String callback, - String scope, OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new MicrosoftAzureActiveDirectoryService(this, apiKey, apiSecret, callback, scope, state, responseType, - userAgent, httpClientConfig, httpClient); - } - @Override public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java index 94905a010..41f71b307 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/TutByApi.java @@ -1,12 +1,8 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.service.TutByOAuthService; import com.github.scribejava.apis.tutby.TutByBearerSignature; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; -import java.io.OutputStream; public class TutByApi extends DefaultApi20 { @@ -31,18 +27,6 @@ protected String getAuthorizationBaseUrl() { return "http://profile.tut.by/auth"; } - /** - * @deprecated moved to {@link #getBearerSignature() } - */ - @Deprecated - @Override - public TutByOAuthService createService(String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new TutByOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, - httpClientConfig, httpClient); - } - @Override public BearerSignature getBearerSignature() { return TutByBearerSignature.instance(); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java deleted file mode 100644 index ca14eb8c4..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/FacebookService.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; - -/** - * @deprecated moved to {@link com.github.scribejava.apis.facebook.FacebookService} - */ -@Deprecated -public class FacebookService extends com.github.scribejava.apis.facebook.FacebookService { - - public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java deleted file mode 100644 index fb51337da..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/ImgurOAuthService.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; - -/** - * @deprecated moved to {@link com.github.scribejava.apis.imgur.ImgurOAuthService} - */ -@Deprecated -public class ImgurOAuthService extends com.github.scribejava.apis.imgur.ImgurOAuthService { - - public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java deleted file mode 100644 index c1593dd45..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MailruOAuthService.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; - -/** - * @deprecated moved to {@link com.github.scribejava.apis.mailru.MailruOAuthService} - */ -@Deprecated -public class MailruOAuthService extends com.github.scribejava.apis.mailru.MailruOAuthService { - - public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java deleted file mode 100644 index e2ff45c3b..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/MicrosoftAzureActiveDirectoryService.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; - -/** - * @deprecated doesn't do anything useful, all MicrosoftAzureActiveDirectory specific logic was moved to - * {@link com.github.scribejava.apis.microsoftazureactivedirectory.MicrosoftAzureActiveDirectoryBearerSignature} - */ -@Deprecated -public class MicrosoftAzureActiveDirectoryService extends OAuth20Service { - - public MicrosoftAzureActiveDirectoryService(DefaultApi20 api, String apiKey, String apiSecret, String callback, - String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - - /** - * @deprecated moved to - * {@link com.github.scribejava.apis.microsoftazureactivedirectory.MicrosoftAzureActiveDirectoryBearerSignature} - */ - @Deprecated - @Override - public void signRequest(String accessToken, OAuthRequest request) { - super.signRequest(accessToken, request); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java deleted file mode 100644 index 46a34102f..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/OdnoklassnikiOAuthService.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; - -/** - * @deprecated moved to {@link com.github.scribejava.apis.odnoklassniki.OdnoklassnikiOAuthService} - */ -@Deprecated -public class OdnoklassnikiOAuthService extends com.github.scribejava.apis.odnoklassniki.OdnoklassnikiOAuthService { - - public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java deleted file mode 100644 index 1b92ca8da..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/TutByOAuthService.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; - -/** - * @deprecated doesn't do anything useful, all TutBy specific logic was moved to - * {@link com.github.scribejava.apis.tutby.TutByBearerSignature} - */ -@Deprecated -public class TutByOAuthService extends OAuth20Service { - - public TutByOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - - /** - * @deprecated moved to {@link com.github.scribejava.apis.tutby.TutByBearerSignature} - */ - @Deprecated - @Override - public void signRequest(String accessToken, OAuthRequest request) { - super.signRequest(accessToken, request); - } -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 75cdd40ba..d12f4844c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -11,7 +11,6 @@ import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureAuthorizationRequestHeaderField; -import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.HttpBasicAuthenticationScheme; import java.io.OutputStream; @@ -115,24 +114,8 @@ public OAuth20Service createService(String apiKey, String apiSecret, String call httpClientConfig, httpClient); } - /** - * @return OAuth2SignatureType - * @deprecated use {@link #getBearerSignature() } - */ - @Deprecated - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD; - } - public BearerSignature getBearerSignature() { - switch (getSignatureType()) { - case BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD: - return BearerSignatureAuthorizationRequestHeaderField.instance(); - case BEARER_URI_QUERY_PARAMETER: - return BearerSignatureURIQueryParameter.instance(); - default: - throw new IllegalStateException("unknown OAuth2SignatureType"); - } + return BearerSignatureAuthorizationRequestHeaderField.instance(); } public ClientAuthentication getClientAuthentication() { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java deleted file mode 100644 index baf246381..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth2SignatureType.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.scribejava.core.builder.api; - -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureAuthorizationRequestHeaderField; -import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; - -/** - * @deprecated use {@link com.github.scribejava.core.oauth2.bearersignature.BearerSignature} - */ -@Deprecated -public enum OAuth2SignatureType { - /** - * @deprecated use - * {@link com.github.scribejava.core.oauth2.bearersignature.BearerSignatureAuthorizationRequestHeaderField} - */ - @Deprecated - BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD { - @Override - public void signRequest(String accessToken, OAuthRequest request) { - BearerSignatureAuthorizationRequestHeaderField.instance().signRequest(accessToken, request); - } - - }, - /** - * @deprecated use {@link com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter} - */ - @Deprecated - BEARER_URI_QUERY_PARAMETER { - @Override - public void signRequest(String accessToken, OAuthRequest request) { - BearerSignatureURIQueryParameter.instance().signRequest(accessToken, request); - } - }; - - public abstract void signRequest(String accessToken, OAuthRequest request); -} From d44ac101a52c461bc29f4ffcdb9258c1408fe1dc Mon Sep 17 00:00:00 2001 From: JureZe Date: Fri, 12 Oct 2018 14:28:32 +0200 Subject: [PATCH 132/481] Keycloak api and keyclak example --- .../github/scribejava/apis/KeyloackApi.java | 57 ++++++++++++++ .../apis/examples/KeyloackExample.java | 75 +++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/KeyloackApi.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeyloackExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KeyloackApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KeyloackApi.java new file mode 100644 index 000000000..d138505d5 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KeyloackApi.java @@ -0,0 +1,57 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.openid.OpenIdJsonTokenExtractor; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.builder.api.OAuth2SignatureType; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.model.OAuth2AccessToken; + +public class KeyloackApi extends DefaultApi20 { + + private String baseUrl = "http://localhost:8080"; + private String realm = "master"; + + public void setBaseUrl(String baseUrl) { + this.baseUrl = baseUrl + (baseUrl.endsWith("/")? "" : "/"); + } + + public void setRealm(String realm) { + this.realm = realm; + } + + protected KeyloackApi() { + } + + private static class InstanceHolder { + private static final KeyloackApi INSTANCE = new KeyloackApi(); + } + + public static KeyloackApi instance() { + return KeyloackApi.InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return baseUrl + "auth/realms/" + realm + "/protocol/openid-connect/token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return baseUrl + "auth/realms/" + realm + "/protocol/openid-connect/auth"; + } + + @Override + public OAuth2SignatureType getSignatureType() { + return OAuth2SignatureType.BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD; + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return OpenIdJsonTokenExtractor.instance(); + } + + @Override + public String getRevokeTokenEndpoint() { + throw new RuntimeException("Not implemented yet"); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeyloackExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeyloackExample.java new file mode 100644 index 000000000..9d977008f --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeyloackExample.java @@ -0,0 +1,75 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.KeyloackApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.IOException; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public final class KeyloackExample { + + private static final String BASE_URL = "https://sicas.setcce.si"; + + private static final String REALM = "TEST_SP"; + + private static final String PROTECTED_RESOURCE_URL = BASE_URL + "/auth/realms/" + REALM + "/protocol/openid-connect/userinfo"; + + private KeyloackExample() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your own api key and secret + final String apiKey = "TEST_SP"; + final String apiSecret = "c9e04342-23e2-433a-a644-5af2a6c5d015"; + final KeyloackApi keyloackApi = KeyloackApi.instance(); + keyloackApi.setBaseUrl(BASE_URL); + keyloackApi.setRealm(REALM); + final OAuth20Service service = new ServiceBuilder(apiKey) + .apiSecret(apiSecret) + .scope("openid") + .callback("http://najdi.si") + .build(keyloackApi); + final Scanner in = new Scanner(System.in); + + System.out.println("=== Keyloack's OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + + } +} From bd527f6af5f88a9f62202cc74056e0b62ddde692 Mon Sep 17 00:00:00 2001 From: JureZe Date: Mon, 15 Oct 2018 12:13:27 +0200 Subject: [PATCH 133/481] Renamed api classes --- .../apis/{KeyloackApi.java => KeycloakApi.java} | 16 +++++----------- ...KeyloackExample.java => KeycloakExample.java} | 10 +++++----- 2 files changed, 10 insertions(+), 16 deletions(-) rename scribejava-apis/src/main/java/com/github/scribejava/apis/{KeyloackApi.java => KeycloakApi.java} (72%) rename scribejava-apis/src/test/java/com/github/scribejava/apis/examples/{KeyloackExample.java => KeycloakExample.java} (92%) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KeyloackApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java similarity index 72% rename from scribejava-apis/src/main/java/com/github/scribejava/apis/KeyloackApi.java rename to scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java index d138505d5..ca16dcbfe 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KeyloackApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java @@ -2,11 +2,10 @@ import com.github.scribejava.apis.openid.OpenIdJsonTokenExtractor; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.builder.api.OAuth2SignatureType; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; -public class KeyloackApi extends DefaultApi20 { +public class KeycloakApi extends DefaultApi20 { private String baseUrl = "http://localhost:8080"; private String realm = "master"; @@ -19,15 +18,15 @@ public void setRealm(String realm) { this.realm = realm; } - protected KeyloackApi() { + protected KeycloakApi() { } private static class InstanceHolder { - private static final KeyloackApi INSTANCE = new KeyloackApi(); + private static final KeycloakApi INSTANCE = new KeycloakApi(); } - public static KeyloackApi instance() { - return KeyloackApi.InstanceHolder.INSTANCE; + public static KeycloakApi instance() { + return KeycloakApi.InstanceHolder.INSTANCE; } @Override @@ -40,11 +39,6 @@ protected String getAuthorizationBaseUrl() { return baseUrl + "auth/realms/" + realm + "/protocol/openid-connect/auth"; } - @Override - public OAuth2SignatureType getSignatureType() { - return OAuth2SignatureType.BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD; - } - @Override public TokenExtractor getAccessTokenExtractor() { return OpenIdJsonTokenExtractor.instance(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeyloackExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java similarity index 92% rename from scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeyloackExample.java rename to scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java index 9d977008f..de3202431 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeyloackExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java @@ -1,6 +1,6 @@ package com.github.scribejava.apis.examples; -import com.github.scribejava.apis.KeyloackApi; +import com.github.scribejava.apis.KeycloakApi; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; @@ -12,7 +12,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class KeyloackExample { +public final class KeycloakExample { private static final String BASE_URL = "https://sicas.setcce.si"; @@ -20,14 +20,14 @@ public final class KeyloackExample { private static final String PROTECTED_RESOURCE_URL = BASE_URL + "/auth/realms/" + REALM + "/protocol/openid-connect/userinfo"; - private KeyloackExample() { + private KeycloakExample() { } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "TEST_SP"; - final String apiSecret = "c9e04342-23e2-433a-a644-5af2a6c5d015"; - final KeyloackApi keyloackApi = KeyloackApi.instance(); + final String apiSecret = "a8fe62c9-c3a1-4545-81ca-fda5df1c032b"; + final KeycloakApi keyloackApi = KeycloakApi.instance(); keyloackApi.setBaseUrl(BASE_URL); keyloackApi.setRealm(REALM); final OAuth20Service service = new ServiceBuilder(apiKey) From d5fa6563056f93cc523d2cf9c4f25cb7c06e0268 Mon Sep 17 00:00:00 2001 From: JureZe Date: Mon, 15 Oct 2018 13:58:08 +0200 Subject: [PATCH 134/481] immutable API classes - as suggested by kullfar --- .../github/scribejava/apis/KeycloakApi.java | 37 ++++++++++++------- .../apis/examples/KeycloakExample.java | 5 +-- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java index ca16dcbfe..1e24c482f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java @@ -5,38 +5,47 @@ import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + public class KeycloakApi extends DefaultApi20 { - private String baseUrl = "http://localhost:8080"; - private String realm = "master"; + private final String baseUrlWithRealm; - public void setBaseUrl(String baseUrl) { - this.baseUrl = baseUrl + (baseUrl.endsWith("/")? "" : "/"); - } + private static final ConcurrentMap INSTANCES = new ConcurrentHashMap<>(); - public void setRealm(String realm) { - this.realm = realm; + protected KeycloakApi(String baseUrlWithRealm) { + this.baseUrlWithRealm = baseUrlWithRealm; } - protected KeycloakApi() { + public static KeycloakApi instance() { + return instance("http://localhost:8080/", "master"); } - private static class InstanceHolder { - private static final KeycloakApi INSTANCE = new KeycloakApi(); + public static KeycloakApi instance(String baseUrl, String realm) { + final String defaultBaseUrlWithRealm = composeBaseUrlWithRealm(baseUrl, realm); + + //java8: switch to ConcurrentMap::computeIfAbsent + KeycloakApi api = INSTANCES.get(defaultBaseUrlWithRealm); + if (api == null) { + api = new KeycloakApi(defaultBaseUrlWithRealm); + INSTANCES.putIfAbsent(defaultBaseUrlWithRealm, api); + } + return api; } - public static KeycloakApi instance() { - return KeycloakApi.InstanceHolder.INSTANCE; + protected static String composeBaseUrlWithRealm(String baseUrl, String realm) { + return baseUrl + (baseUrl.endsWith("/") ? "" : "/") + "auth/realms/" + realm; } @Override public String getAccessTokenEndpoint() { - return baseUrl + "auth/realms/" + realm + "/protocol/openid-connect/token"; + return baseUrlWithRealm + "/protocol/openid-connect/token"; } @Override protected String getAuthorizationBaseUrl() { - return baseUrl + "auth/realms/" + realm + "/protocol/openid-connect/auth"; + return baseUrlWithRealm + "/protocol/openid-connect/auth"; } @Override diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java index de3202431..65ca53825 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java @@ -27,14 +27,11 @@ public static void main(String... args) throws IOException, InterruptedException // Replace these with your own api key and secret final String apiKey = "TEST_SP"; final String apiSecret = "a8fe62c9-c3a1-4545-81ca-fda5df1c032b"; - final KeycloakApi keyloackApi = KeycloakApi.instance(); - keyloackApi.setBaseUrl(BASE_URL); - keyloackApi.setRealm(REALM); final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .scope("openid") .callback("http://najdi.si") - .build(keyloackApi); + .build(KeycloakApi.instance(BASE_URL, REALM)); final Scanner in = new Scanner(System.in); System.out.println("=== Keyloack's OAuth Workflow ==="); From 70c4d35f39f8926c552c530fd5cbf851d3320a48 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 15 Oct 2018 15:43:47 +0300 Subject: [PATCH 135/481] add new API Keycloak (https://www.keycloak.org/) (thanks to https://github.com/JureZelic) --- README.md | 1 + changelog | 3 ++ .../github/scribejava/apis/KeycloakApi.java | 9 ++-- .../github/scribejava/apis/ExampleUtils.java | 52 +++++++++++++++++++ .../apis/examples/KeycloakExample.java | 26 +++++----- 5 files changed, 75 insertions(+), 16 deletions(-) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java diff --git a/README.md b/README.md index 2cc181033..f57ede33f 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ ScribeJava support out-of-box several HTTP clients: * HiOrg-Server (https://www.hiorg-server.de/) * Imgur (http://imgur.com/) * Kaixin 开心网 (http://www.kaixin001.com/) +* Keycloak (https://www.keycloak.org/) * LinkedIn (https://www.linkedin.com/) * Microsoft Azure Active Directory (Azure AD) (http://azure.microsoft.com/) * Microsoft Live (https://login.live.com/) diff --git a/changelog b/changelog index 81c5e188d..fe95b1173 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * add new API Keycloak (https://www.keycloak.org/) (thanks to https://github.com/JureZelic) + [6.0.0] * make redirect_uri optional while Access Token requesting on OAuth 2.0 (thanks to https://github.com/computerlove) * switch to java 9+ (from java 7 only) for compilation. Runtime is still java 7+. Complement README with links and RFC descriptions. diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java index 1e24c482f..ed713b4d0 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KeycloakApi.java @@ -10,10 +10,10 @@ public class KeycloakApi extends DefaultApi20 { - private final String baseUrlWithRealm; - private static final ConcurrentMap INSTANCES = new ConcurrentHashMap<>(); + private final String baseUrlWithRealm; + protected KeycloakApi(String baseUrlWithRealm) { this.baseUrlWithRealm = baseUrlWithRealm; } @@ -29,7 +29,10 @@ public static KeycloakApi instance(String baseUrl, String realm) { KeycloakApi api = INSTANCES.get(defaultBaseUrlWithRealm); if (api == null) { api = new KeycloakApi(defaultBaseUrlWithRealm); - INSTANCES.putIfAbsent(defaultBaseUrlWithRealm, api); + final KeycloakApi alreadyCreatedApi = INSTANCES.putIfAbsent(defaultBaseUrlWithRealm, api); + if (alreadyCreatedApi != null) { + return alreadyCreatedApi; + } } return api; } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java new file mode 100644 index 000000000..195729b3c --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java @@ -0,0 +1,52 @@ +package com.github.scribejava.apis; + +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.X509Certificate; +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; + +public class ExampleUtils { + + private ExampleUtils() { + } + + public static void turnOfSSl() { + try { + final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() { + @Override + public java.security.cert.X509Certificate[] getAcceptedIssuers() { + return null; + } + + @Override + public void checkClientTrusted(X509Certificate[] certs, String authType) { + } + + @Override + public void checkServerTrusted(X509Certificate[] certs, String authType) { + } + } + }; + + final SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, trustAllCerts, new java.security.SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + + final HostnameVerifier allHostsValid = new HostnameVerifier() { + @Override + public boolean verify(String hostname, SSLSession session) { + return true; + } + }; + + HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); + } catch (NoSuchAlgorithmException | KeyManagementException e) { + throw new RuntimeException(e); + } + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java index 65ca53825..57fa12c4f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java @@ -12,26 +12,26 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class KeycloakExample { - - private static final String BASE_URL = "https://sicas.setcce.si"; - - private static final String REALM = "TEST_SP"; - - private static final String PROTECTED_RESOURCE_URL = BASE_URL + "/auth/realms/" + REALM + "/protocol/openid-connect/userinfo"; +public class KeycloakExample { private KeycloakExample() { } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - // Replace these with your own api key and secret - final String apiKey = "TEST_SP"; - final String apiSecret = "a8fe62c9-c3a1-4545-81ca-fda5df1c032b"; + // Replace these with your own api key, secret, callback, base url and realm + final String apiKey = "your_api_key"; + final String apiSecret = "your_api_secret"; + final String callback = "your_callback"; + final String baseUrl = "your_base_url"; + final String realm = "your_realm"; + + final String protectedResourceUrl = baseUrl + "/auth/realms/" + realm + "/protocol/openid-connect/userinfo"; + final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .scope("openid") - .callback("http://najdi.si") - .build(KeycloakApi.instance(BASE_URL, REALM)); + .callback(callback) + .build(KeycloakApi.instance(baseUrl, realm)); final Scanner in = new Scanner(System.in); System.out.println("=== Keyloack's OAuth Workflow ==="); @@ -57,7 +57,7 @@ public static void main(String... args) throws IOException, InterruptedException // Now let's go and ask for a protected resource! System.out.println("Now we're going to access a protected resource..."); - final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + final OAuthRequest request = new OAuthRequest(Verb.GET, protectedResourceUrl); service.signRequest(accessToken, request); final Response response = service.execute(request); System.out.println("Got it! Lets see what we found..."); From dc3b98a66967a3416916a3e2e317822c22e7b572 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 15 Oct 2018 16:03:43 +0300 Subject: [PATCH 136/481] add links to the examples on README.md --- README.md | 94 +++++++++++++++++++++++++++---------------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index f57ede33f..1903d478e 100644 --- a/README.md +++ b/README.md @@ -51,54 +51,54 @@ ScribeJava support out-of-box several HTTP clients: ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box -* Automatic (https://www.automatic.com/) -* AWeber (http://www.aweber.com/) -* Box (https://www.box.com/) -* Dataporten (https://docs.dataporten.no/) -* Digg (http://digg.com/) +* Automatic (https://www.automatic.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java) +* AWeber (http://www.aweber.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java) +* Box (https://www.box.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java) +* Dataporten (https://docs.dataporten.no/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java) +* Digg (http://digg.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java) * Доктор на работе (https://www.doktornarabote.ru/) -* Etsy (https://www.etsy.com/) -* Facebook (https://www.facebook.com/) -* Fitbit (https://www.fitbit.com/) -* Flickr (https://www.flickr.com/) -* Foursquare (https://foursquare.com/) -* Frappe (https://github.com/frappe/frappe) -* Freelancer (https://www.freelancer.com/) -* Genius (http://genius.com/) -* GitHub (https://github.com/) -* Google (https://www.google.com/) -* HeadHunter ХэдХантер (https://hh.ru/) -* HiOrg-Server (https://www.hiorg-server.de/) -* Imgur (http://imgur.com/) -* Kaixin 开心网 (http://www.kaixin001.com/) -* Keycloak (https://www.keycloak.org/) -* LinkedIn (https://www.linkedin.com/) -* Microsoft Azure Active Directory (Azure AD) (http://azure.microsoft.com/) -* Microsoft Live (https://login.live.com/) -* Misfit (http://misfit.com/) -* Mail.Ru (https://mail.ru/) -* MediaWiki (https://www.mediawiki.org/) -* Meetup (http://www.meetup.com/) -* NAVER (http://www.naver.com/) -* Odnoklassniki Одноклассники (http://ok.ru/) -* Pinterest (https://www.pinterest.com/) -* 500px (https://500px.com/) -* Renren (http://renren.com/) -* Salesforce (https://www.salesforce.com/) -* Sina (http://www.sina.com.cn/ http://weibo.com/login.php) -* Skyrock (http://skyrock.com/) -* StackExchange (http://stackexchange.com/) -* The Things Network (v1-staging and v2-preview) (https://www.thethingsnetwork.org/) -* Trello (https://trello.com/) -* Tumblr (https://www.tumblr.com/) -* TUT.BY (http://www.tut.by/) -* Twitter (https://twitter.com/) -* uCoz (https://www.ucoz.com/) -* Viadeo (http://viadeo.com/) -* VK ВКонтакте (http://vk.com/) -* Wunderlist (https://www.wunderlist.com/) -* XING (https://www.xing.com/) -* Yahoo (https://www.yahoo.com/) +* Etsy (https://www.etsy.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java) +* Facebook (https://www.facebook.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java) [example with Async Apache HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java) [example with Async Ning HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java) +* Fitbit (https://www.fitbit.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java) +* Flickr (https://www.flickr.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java) +* Foursquare (https://foursquare.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java) +* Frappe (https://github.com/frappe/frappe) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java) +* Freelancer (https://www.freelancer.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java) +* Genius (http://genius.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java) +* GitHub (https://github.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java) [example with OkHttp HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java) +* Google (https://www.google.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java) [example with Async Http Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java) [example Revoke](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java) [example with PKCEE](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) +* HeadHunter ХэдХантер (https://hh.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java) +* HiOrg-Server (https://www.hiorg-server.de/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java) +* Imgur (http://imgur.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java) +* Kaixin 开心网 (http://www.kaixin001.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java) +* Keycloak (https://www.keycloak.org/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java) +* LinkedIn (https://www.linkedin.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java) [example with custom scopes](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java) +* Mail.Ru (https://mail.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java) [example with Async Ning HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java) +* MediaWiki (https://www.mediawiki.org/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java) +* Meetup (http://www.meetup.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java) +* Microsoft Azure Active Directory (Azure AD) (http://azure.microsoft.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java) +* Microsoft Live (https://login.live.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java) +* Misfit (http://misfit.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java) +* NAVER (http://www.naver.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java) +* Odnoklassniki Одноклассники (http://ok.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java) +* Pinterest (https://www.pinterest.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java) +* 500px (https://500px.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java) +* Renren (http://renren.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java) +* Salesforce (https://www.salesforce.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java) [example with Async Ning HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java) +* Sina (http://www.sina.com.cn/ http://weibo.com/login.php) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java) +* Skyrock (http://skyrock.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java) +* StackExchange (http://stackexchange.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java) +* The Things Network (v1-staging and v2-preview) (https://www.thethingsnetwork.org/) [example v1](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java) [example v2 preview](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java) +* Trello (https://trello.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java) +* Tumblr (https://www.tumblr.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java) +* TUT.BY (http://www.tut.by/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java) +* Twitter (https://twitter.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java) +* uCoz (https://www.ucoz.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java) +* Viadeo (http://viadeo.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java) +* VK ВКонтакте (http://vk.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java) [example Client Credentials Grant](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java) [example with External HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java) +* Wunderlist (https://www.wunderlist.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java) +* XING (https://www.xing.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java) +* Yahoo (https://www.yahoo.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java) * check the [examples folder](https://github.com/scribejava/scribejava/tree/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples) ### Small and modular From debbbbd25472b16ef3532f0f29a0adbdb868e920 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 15 Oct 2018 16:06:26 +0300 Subject: [PATCH 137/481] format README.md --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 1903d478e..fabbd06cc 100644 --- a/README.md +++ b/README.md @@ -58,22 +58,22 @@ ScribeJava support out-of-box several HTTP clients: * Digg (http://digg.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java) * Доктор на работе (https://www.doktornarabote.ru/) * Etsy (https://www.etsy.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java) -* Facebook (https://www.facebook.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java) [example with Async Apache HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java) [example with Async Ning HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java) +* Facebook (https://www.facebook.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java), [example with Async Apache HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java), [example with Async Ning HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java) * Fitbit (https://www.fitbit.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java) * Flickr (https://www.flickr.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java) -* Foursquare (https://foursquare.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java) +* Foursquare (https://foursquare.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java) * Frappe (https://github.com/frappe/frappe) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java) * Freelancer (https://www.freelancer.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java) * Genius (http://genius.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java) -* GitHub (https://github.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java) [example with OkHttp HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java) -* Google (https://www.google.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java) [example with Async Http Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java) [example Revoke](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java) [example with PKCEE](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) +* GitHub (https://github.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java), [example with OkHttp HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java) +* Google (https://www.google.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java), [example with Async Http Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java), [example Revoke](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java), [example with PKCEE](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) * HeadHunter ХэдХантер (https://hh.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java) * HiOrg-Server (https://www.hiorg-server.de/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java) * Imgur (http://imgur.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java) * Kaixin 开心网 (http://www.kaixin001.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java) * Keycloak (https://www.keycloak.org/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java) -* LinkedIn (https://www.linkedin.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java) [example with custom scopes](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java) -* Mail.Ru (https://mail.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java) [example with Async Ning HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java) +* LinkedIn (https://www.linkedin.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java), [example with custom scopes](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java) +* Mail.Ru (https://mail.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java), [example with Async Ning HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java) * MediaWiki (https://www.mediawiki.org/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java) * Meetup (http://www.meetup.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java) * Microsoft Azure Active Directory (Azure AD) (http://azure.microsoft.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java) @@ -84,21 +84,21 @@ ScribeJava support out-of-box several HTTP clients: * Pinterest (https://www.pinterest.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java) * 500px (https://500px.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java) * Renren (http://renren.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java) -* Salesforce (https://www.salesforce.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java) [example with Async Ning HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java) -* Sina (http://www.sina.com.cn/ http://weibo.com/login.php) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java) +* Salesforce (https://www.salesforce.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java), [example with Async Ning HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java) +* Sina (http://www.sina.com.cn/ http://weibo.com/login.php) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java) * Skyrock (http://skyrock.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java) * StackExchange (http://stackexchange.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java) -* The Things Network (v1-staging and v2-preview) (https://www.thethingsnetwork.org/) [example v1](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java) [example v2 preview](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java) +* The Things Network (v1-staging and v2-preview) (https://www.thethingsnetwork.org/) [example v1](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java), [example v2 preview](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java) * Trello (https://trello.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java) * Tumblr (https://www.tumblr.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java) * TUT.BY (http://www.tut.by/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java) * Twitter (https://twitter.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java) * uCoz (https://www.ucoz.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java) * Viadeo (http://viadeo.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java) -* VK ВКонтакте (http://vk.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java) [example Client Credentials Grant](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java) [example with External HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java) +* VK ВКонтакте (http://vk.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java), [example Client Credentials Grant](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java), [example with External HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java) * Wunderlist (https://www.wunderlist.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java) * XING (https://www.xing.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java) -* Yahoo (https://www.yahoo.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java) +* Yahoo (https://www.yahoo.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java) * check the [examples folder](https://github.com/scribejava/scribejava/tree/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples) ### Small and modular From d854c786805aeaf04ff754f21a7578a743e3f444 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 6 Nov 2018 14:18:36 +0300 Subject: [PATCH 138/481] add new API Discord (https://discordapp.com/) (thanks to https://github.com/Jokuni) --- README.md | 2 +- changelog | 1 + .../github/scribejava/apis/DiscordApi.java | 15 ------------ .../apis/imgur/ImgurOAuthService.java | 3 ++- .../apis/service/DiscordService.java | 23 ------------------- .../apis/examples/DiscordExample.java | 2 +- ...natureAuthorizationRequestHeaderField.java | 3 ++- 7 files changed, 7 insertions(+), 42 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/service/DiscordService.java diff --git a/README.md b/README.md index 00457c51e..150bd6e41 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ ScribeJava support out-of-box several HTTP clients: * Box (https://www.box.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java) * Dataporten (https://docs.dataporten.no/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java) * Digg (http://digg.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java) -* Discord (https://discordapp.com/) +* Discord (https://discordapp.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java) * Доктор на работе (https://www.doktornarabote.ru/) * Etsy (https://www.etsy.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java) * Facebook (https://www.facebook.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java), [example with Async Apache HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java), [example with Async Ning HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java) diff --git a/changelog b/changelog index fe95b1173..ea0fe2eb2 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * add new API Keycloak (https://www.keycloak.org/) (thanks to https://github.com/JureZelic) + * add new API Discord (https://discordapp.com/) (thanks to https://github.com/Jokuni) [6.0.0] * make redirect_uri optional while Access Token requesting on OAuth 2.0 (thanks to https://github.com/computerlove) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DiscordApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiscordApi.java index 96a3c31bf..0583b6dc5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DiscordApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DiscordApi.java @@ -1,12 +1,6 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.service.DiscordService; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.oauth.OAuth20Service; - -import java.io.OutputStream; public class DiscordApi extends DefaultApi20 { @@ -35,13 +29,4 @@ public String getRevokeTokenEndpoint() { public String getAccessTokenEndpoint() { return "https://discordapp.com/api/oauth2/token"; } - - @Override - public OAuth20Service createService(String apiKey, String apiSecret, String callback, - String scope, OutputStream debugStream, String state, - String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new DiscordService(this, apiKey, apiSecret, callback, scope, state, responseType, - userAgent, httpClientConfig, httpClient); - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java index f37dfab95..b1c934a9a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java @@ -35,6 +35,7 @@ protected OAuthRequest createAccessTokenRequest(String oauthVerifier) { @Override public void signRequest(String accessToken, OAuthRequest request) { - request.addHeader("Authorization", accessToken == null ? "Client-ID " + getApiKey() : "Bearer " + accessToken); + request.addHeader(OAuthConstants.HEADER, + accessToken == null ? "Client-ID " + getApiKey() : "Bearer " + accessToken); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DiscordService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DiscordService.java deleted file mode 100644 index c97c10d7d..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/service/DiscordService.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.scribejava.apis.service; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.OAuth20Service; - -public class DiscordService extends OAuth20Service { - public DiscordService(DefaultApi20 api, String apiKey, String apiSecret, String callback, - String scope, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - - @Override - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { - request.addHeader(OAuthConstants.HEADER, accessToken.getTokenType() + ' ' + accessToken.getAccessToken()); - } - -} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java index cad56cd73..41c5be42b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java @@ -13,7 +13,7 @@ import java.util.Scanner; import java.util.concurrent.ExecutionException; -public final class DiscordExample { +public class DiscordExample { private static final String NETWORK_NAME = "Discord"; private static final String PROTECTED_RESOURCE_URL = "https://discordapp.com/api/users/@me"; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureAuthorizationRequestHeaderField.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureAuthorizationRequestHeaderField.java index 72ab0cbd2..98196a708 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureAuthorizationRequestHeaderField.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/bearersignature/BearerSignatureAuthorizationRequestHeaderField.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.oauth2.bearersignature; +import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; /** @@ -23,6 +24,6 @@ public static BearerSignatureAuthorizationRequestHeaderField instance() { @Override public void signRequest(String accessToken, OAuthRequest request) { - request.addHeader("Authorization", "Bearer " + accessToken); + request.addHeader(OAuthConstants.HEADER, "Bearer " + accessToken); } } From 001f2f5afecbca89baa83606c6c0a71918180846 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 6 Nov 2018 14:33:07 +0300 Subject: [PATCH 139/481] update deps --- pom.xml | 6 +++--- scribejava-httpclient-ahc/pom.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 85f930caf..2c9030940 100644 --- a/pom.xml +++ b/pom.xml @@ -78,7 +78,7 @@ org.apache.felix maven-bundle-plugin - 4.0.0 + 4.1.0 bundle-manifest @@ -107,7 +107,7 @@ com.puppycrawl.tools checkstyle - 8.13 + 8.14 @@ -122,7 +122,7 @@ org.apache.maven.plugins maven-surefire-plugin - 2.22.0 + 2.22.1 org.apache.maven.plugins diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index a8826d0d1..119aa998b 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.5.4 + 2.6.0 com.github.scribejava From 92c97d8d64562c9d49a4ade82b1c74b812469114 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 14 Nov 2018 17:28:27 +0300 Subject: [PATCH 140/481] prepare v6.1.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 150bd6e41..2736a6a34 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.0.0 + 6.1.0 ``` @@ -134,7 +134,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.0.0 + 6.1.0 ``` diff --git a/changelog b/changelog index ea0fe2eb2..7a2ba2cd3 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.1.0] * add new API Keycloak (https://www.keycloak.org/) (thanks to https://github.com/JureZelic) * add new API Discord (https://discordapp.com/) (thanks to https://github.com/Jokuni) From 944c350540944dd2aebce4d072e2a5656f8a45ca Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 14 Nov 2018 17:29:44 +0300 Subject: [PATCH 141/481] [maven-release-plugin] prepare release scribejava-6.1.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 2c9030940..5c79f48da 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.0.1-SNAPSHOT + 6.1.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.1.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index c96f2850c..397e981c8 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.1-SNAPSHOT + 6.1.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 5924eab0d..b0dc43311 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.1-SNAPSHOT + 6.1.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 119aa998b..826709b08 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.1-SNAPSHOT + 6.1.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 41694af95..e772ec917 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.1-SNAPSHOT + 6.1.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 7226faaea..00f7b9272 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.1-SNAPSHOT + 6.1.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index b93300259..0e511cb87 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.0.1-SNAPSHOT + 6.1.0 ../pom.xml From c6f060c4234658277bbaf8f9780fc2c30eba8ad7 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 14 Nov 2018 17:29:50 +0300 Subject: [PATCH 142/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 5c79f48da..eb4a7e86a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.1.0 + 6.1.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.1.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 397e981c8..51ce2ae29 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.0 + 6.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index b0dc43311..184a6f0b9 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.0 + 6.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 826709b08..19a4e8716 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.0 + 6.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index e772ec917..0e7e85cb0 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.0 + 6.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 00f7b9272..550c0a3dc 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.0 + 6.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 0e511cb87..fdd3a0a14 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.0 + 6.1.1-SNAPSHOT ../pom.xml From 0a8ce3cb36a9b9cecca23eaee8266f309b5febc4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 21 Nov 2018 17:52:47 +0300 Subject: [PATCH 143/481] add new API Microsoft Azure Active Directory (Azure AD) 2.0 (thanks to https://github.com/rzukow and https://github.com/dgrudenic) --- README.md | 1 + changelog | 3 + .../MicrosoftAzureActiveDirectory20Api.java | 28 ++++++++ .../MicrosoftAzureActiveDirectoryApi.java | 38 ++-------- .../BaseMicrosoftAzureActiveDirectoryApi.java | 69 +++++++++++++++++++ ...ftAzureActiveDirectoryBearerSignature.java | 20 ++++++ ...AzureActiveDirectory20BearerSignature.java | 18 +++++ ...ftAzureActiveDirectoryBearerSignature.java | 14 +--- ...icrosoftAzureActiveDirectory20Example.java | 62 +++++++++++++++++ 9 files changed, 208 insertions(+), 45 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectory20Api.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryBearerSignature.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectory20BearerSignature.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java diff --git a/README.md b/README.md index 2736a6a34..8c5d54c29 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ ScribeJava support out-of-box several HTTP clients: * MediaWiki (https://www.mediawiki.org/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java) * Meetup (http://www.meetup.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java) * Microsoft Azure Active Directory (Azure AD) (http://azure.microsoft.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java) +* Microsoft Azure Active Directory (Azure AD) 2.0 (http://azure.microsoft.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java) * Microsoft Live (https://login.live.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java) * Misfit (http://misfit.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java) * NAVER (http://www.naver.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java) diff --git a/changelog b/changelog index 7a2ba2cd3..02fa06cfe 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * add new API Microsoft Azure Active Directory (Azure AD) 2.0 (thanks to https://github.com/rzukow and https://github.com/dgrudenic) + [6.1.0] * add new API Keycloak (https://www.keycloak.org/) (thanks to https://github.com/JureZelic) * add new API Discord (https://discordapp.com/) (thanks to https://github.com/Jokuni) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectory20Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectory20Api.java new file mode 100644 index 000000000..71b0a005e --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectory20Api.java @@ -0,0 +1,28 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.microsoftazureactivedirectory.BaseMicrosoftAzureActiveDirectoryApi; + +/** + * Microsoft Azure Active Directory Api v 2.0 + * + * @see + * Understand the OAuth 2.0 authorization code flow in Azure AD | Microsoft Docs + * @see + * Microsoft Graph REST API v1.0 reference + * @see https://portal.azure.com + */ +public class MicrosoftAzureActiveDirectory20Api extends BaseMicrosoftAzureActiveDirectoryApi { + + protected MicrosoftAzureActiveDirectory20Api() { + super(MicrosoftAzureActiveDirectoryVersion.V_2_0); + } + + private static class InstanceHolder { + + private static final MicrosoftAzureActiveDirectory20Api INSTANCE = new MicrosoftAzureActiveDirectory20Api(); + } + + public static MicrosoftAzureActiveDirectory20Api instance() { + return InstanceHolder.INSTANCE; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java index 6817cc686..31250be3f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java @@ -1,10 +1,6 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.microsoftazureactivedirectory.MicrosoftAzureActiveDirectoryBearerSignature; -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; -import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; -import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; +import com.github.scribejava.apis.microsoftazureactivedirectory.BaseMicrosoftAzureActiveDirectoryApi; /** * Microsoft Azure Active Directory Api @@ -18,15 +14,11 @@ * Azure AD Graph API Operations on the Signed-in User * @see https://portal.azure.com */ -public class MicrosoftAzureActiveDirectoryApi extends DefaultApi20 { +public class MicrosoftAzureActiveDirectoryApi extends BaseMicrosoftAzureActiveDirectoryApi { - private static final String MSFT_GRAPH_URL = "https://graph.windows.net"; - - private static final String MSFT_LOGIN_URL = "https://login.microsoftonline.com"; - private static final String SLASH = "/"; - private static final String COMMON = "common"; - private static final String TOKEN_URI = "oauth2/token"; - private static final String AUTH_URI = "oauth2/authorize?resource=" + MSFT_GRAPH_URL; + protected MicrosoftAzureActiveDirectoryApi() { + super(MicrosoftAzureActiveDirectoryVersion.V_1_0); + } private static class InstanceHolder { @@ -36,24 +28,4 @@ private static class InstanceHolder { public static MicrosoftAzureActiveDirectoryApi instance() { return InstanceHolder.INSTANCE; } - - @Override - public String getAccessTokenEndpoint() { - return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + TOKEN_URI; - } - - @Override - protected String getAuthorizationBaseUrl() { - return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + AUTH_URI; - } - - @Override - public ClientAuthentication getClientAuthentication() { - return RequestBodyAuthenticationScheme.instance(); - } - - @Override - public BearerSignature getBearerSignature() { - return MicrosoftAzureActiveDirectoryBearerSignature.instance(); - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java new file mode 100644 index 000000000..bc813e398 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java @@ -0,0 +1,69 @@ +package com.github.scribejava.apis.microsoftazureactivedirectory; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; + +public abstract class BaseMicrosoftAzureActiveDirectoryApi extends DefaultApi20 { + + private static final String MSFT_LOGIN_URL = "https://login.microsoftonline.com"; + private static final String SLASH = "/"; + private static final String COMMON = "common"; + private static final String TOKEN_URI = "oauth2/token"; + private final String resource; + private final BaseMicrosoftAzureActiveDirectoryBearerSignature bearerSignature; + + protected BaseMicrosoftAzureActiveDirectoryApi(String resource, + BaseMicrosoftAzureActiveDirectoryBearerSignature bearerSignature) { + this.resource = resource; + this.bearerSignature = bearerSignature; + } + + protected BaseMicrosoftAzureActiveDirectoryApi(MicrosoftAzureActiveDirectoryVersion version) { + this.resource = version.getResource(); + this.bearerSignature = version.getBearerSignature(); + } + + @Override + public String getAccessTokenEndpoint() { + return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + TOKEN_URI; + } + + @Override + protected String getAuthorizationBaseUrl() { + return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + "oauth2/authorize?resource=" + resource; + } + + @Override + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); + } + + @Override + public BearerSignature getBearerSignature() { + return bearerSignature; + } + + protected enum MicrosoftAzureActiveDirectoryVersion { + V_1_0("https://graph.windows.net", MicrosoftAzureActiveDirectoryBearerSignature.instance()), + V_2_0("https://graph.microsoft.com", MicrosoftAzureActiveDirectory20BearerSignature.instance()); + + private final String resource; + private final BaseMicrosoftAzureActiveDirectoryBearerSignature bearerSignature; + + MicrosoftAzureActiveDirectoryVersion(String resource, + BaseMicrosoftAzureActiveDirectoryBearerSignature bearerSignature) { + this.resource = resource; + this.bearerSignature = bearerSignature; + } + + protected String getResource() { + return resource; + } + + protected BaseMicrosoftAzureActiveDirectoryBearerSignature getBearerSignature() { + return bearerSignature; + } + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryBearerSignature.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryBearerSignature.java new file mode 100644 index 000000000..ab85674af --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryBearerSignature.java @@ -0,0 +1,20 @@ +package com.github.scribejava.apis.microsoftazureactivedirectory; + +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureAuthorizationRequestHeaderField; + +public abstract class BaseMicrosoftAzureActiveDirectoryBearerSignature + extends BearerSignatureAuthorizationRequestHeaderField { + + private final String acceptedFormat; + + protected BaseMicrosoftAzureActiveDirectoryBearerSignature(String acceptedFormat) { + this.acceptedFormat = acceptedFormat; + } + + @Override + public void signRequest(String accessToken, OAuthRequest request) { + super.signRequest(accessToken, request); + request.addHeader("Accept", acceptedFormat); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectory20BearerSignature.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectory20BearerSignature.java new file mode 100644 index 000000000..c554beeff --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectory20BearerSignature.java @@ -0,0 +1,18 @@ +package com.github.scribejava.apis.microsoftazureactivedirectory; + +public class MicrosoftAzureActiveDirectory20BearerSignature extends BaseMicrosoftAzureActiveDirectoryBearerSignature { + + protected MicrosoftAzureActiveDirectory20BearerSignature() { + super("application/json"); + } + + private static class InstanceHolder { + + private static final MicrosoftAzureActiveDirectory20BearerSignature INSTANCE + = new MicrosoftAzureActiveDirectory20BearerSignature(); + } + + public static MicrosoftAzureActiveDirectory20BearerSignature instance() { + return InstanceHolder.INSTANCE; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectoryBearerSignature.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectoryBearerSignature.java index dddf62d50..bfddd523a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectoryBearerSignature.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/MicrosoftAzureActiveDirectoryBearerSignature.java @@ -1,13 +1,9 @@ package com.github.scribejava.apis.microsoftazureactivedirectory; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureAuthorizationRequestHeaderField; - -public class MicrosoftAzureActiveDirectoryBearerSignature extends BearerSignatureAuthorizationRequestHeaderField { - private static final String ACCEPTED_FORMAT - = "application/json; odata=minimalmetadata; streaming=true; charset=utf-8"; +public class MicrosoftAzureActiveDirectoryBearerSignature extends BaseMicrosoftAzureActiveDirectoryBearerSignature { protected MicrosoftAzureActiveDirectoryBearerSignature() { + super("application/json; odata=minimalmetadata; streaming=true; charset=utf-8"); } private static class InstanceHolder { @@ -19,10 +15,4 @@ private static class InstanceHolder { public static MicrosoftAzureActiveDirectoryBearerSignature instance() { return InstanceHolder.INSTANCE; } - - @Override - public void signRequest(String accessToken, OAuthRequest request) { - super.signRequest(accessToken, request); - request.addHeader("Accept", ACCEPTED_FORMAT); - } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java new file mode 100644 index 000000000..c0bd6f88a --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java @@ -0,0 +1,62 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.MicrosoftAzureActiveDirectory20Api; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.IOException; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public class MicrosoftAzureActiveDirectory20Example { + + private static final String NETWORK_NAME = "Microsoft Azure Active Directory"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.microsoft.com/v1.0/me"; + + private MicrosoftAzureActiveDirectory20Example() { + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "client id here"; + final String clientSecret = "client secret here"; + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .scope("openid") + .callback("http://www.example.com/oauth_callback/") + .build(MicrosoftAzureActiveDirectory20Api.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} From 935bdf42204a5c97cfc919db53cad430da8ecb1b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 11 Dec 2018 11:19:09 +0300 Subject: [PATCH 144/481] update OkHTTP --- pom.xml | 4 ++-- scribejava-httpclient-okhttp/pom.xml | 4 ++-- .../com/github/scribejava/httpclient/okhttp/MockCall.java | 6 ++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index eb4a7e86a..73ece612e 100644 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,7 @@ com.squareup.okhttp3 mockwebserver - 3.11.0 + 3.12.0 test @@ -107,7 +107,7 @@ com.puppycrawl.tools checkstyle - 8.14 + 8.15 diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index fdd3a0a14..e1eab50a3 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -8,7 +8,7 @@ 6.1.1-SNAPSHOT ../pom.xml - + com.github.scribejava scribejava-httpclient-okhttp ScribeJava Async OkHttp Client support @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 3.11.0 + 3.12.0 com.github.scribejava diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java index 967d96c4a..c6dabd4c2 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java @@ -8,6 +8,7 @@ import okhttp3.Callback; import okhttp3.Request; import okhttp3.Response; +import okio.Timeout; public class MockCall implements Call { @@ -51,4 +52,9 @@ public boolean isExecuted() { public Call clone() { throw new UnsupportedOperationException("Not supported yet."); } + + @Override + public Timeout timeout() { + throw new UnsupportedOperationException("Not supported yet."); + } } From 239ddc30cd301323aa38d29eae6116dfda828f2c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 11 Dec 2018 11:39:37 +0300 Subject: [PATCH 145/481] prepare v6.2.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8c5d54c29..9d8162a93 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.1.0 + 6.2.0 ``` @@ -135,7 +135,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.1.0 + 6.2.0 ``` diff --git a/changelog b/changelog index 02fa06cfe..96dfb8e84 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.2.0] * add new API Microsoft Azure Active Directory (Azure AD) 2.0 (thanks to https://github.com/rzukow and https://github.com/dgrudenic) [6.1.0] From a952ef04cf276a4b02eb1f572fe0bac0768e2315 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 11 Dec 2018 11:41:28 +0300 Subject: [PATCH 146/481] [maven-release-plugin] prepare release scribejava-6.2.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 73ece612e..eace26e6e 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.1.1-SNAPSHOT + 6.2.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.2.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 51ce2ae29..07e05a009 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.1-SNAPSHOT + 6.2.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 184a6f0b9..511bdf4ec 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.1-SNAPSHOT + 6.2.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 19a4e8716..d492bf29c 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.1-SNAPSHOT + 6.2.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 0e7e85cb0..c3de9f1c0 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.1-SNAPSHOT + 6.2.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 550c0a3dc..f91dbf444 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.1-SNAPSHOT + 6.2.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index e1eab50a3..1be3a8a04 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.1.1-SNAPSHOT + 6.2.0 ../pom.xml From b4f2cf8b676582f8ec2305e66a103ab69ae7d95d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 11 Dec 2018 11:41:41 +0300 Subject: [PATCH 147/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index eace26e6e..09aaf9fa1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.2.0 + 6.2.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.2.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 07e05a009..39202c69b 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.0 + 6.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 511bdf4ec..7da4f7cf5 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.0 + 6.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index d492bf29c..46e58e129 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.0 + 6.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index c3de9f1c0..5b6ffd268 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.0 + 6.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index f91dbf444..7b43aaf1b 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.0 + 6.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 1be3a8a04..701ba6109 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.0 + 6.2.1-SNAPSHOT ../pom.xml From eccb3a1ac684ad62c145f42e7b6db8b70af4bf24 Mon Sep 17 00:00:00 2001 From: Joe Stazak Date: Wed, 2 Jan 2019 14:15:51 -0500 Subject: [PATCH 148/481] Adding Asana OAuth 2.0 integration + example --- .../com/github/scribejava/apis/Asana20.java | 33 +++++++ .../apis/examples/AsanaExample.java | 87 +++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20.java new file mode 100644 index 000000000..b46151a35 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20.java @@ -0,0 +1,33 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; + +public class Asana20 extends DefaultApi20 { + protected Asana20() { + } + + private static class InstanceHolder { + private static final Asana20 INSTANCE = new Asana20(); + } + + public static Asana20 instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://app.asana.com/-/oauth_token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://app.asana.com/-/oauth_authorize"; + } + + @Override + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java new file mode 100644 index 000000000..5ae120df6 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java @@ -0,0 +1,87 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.Asana20; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Random; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public class AsanaExample { + + private static final String PROTECTED_RESOURCE_URL = "https://app.asana.com/api/1.0/users/me"; + + private AsanaExample() { + + } + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + final String apiKey = "your client id"; + final String apiSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder(apiKey) + .apiSecret(apiSecret) + .callback("https://localhost/") + .build(Asana20.instance()); + final Scanner in = new Scanner(System.in); + + // Obtain Auth URL + System.out.println("Fetching the Authorication URL..."); + System.out.println("Got the Authorization URL!"); + final Map additionalParams = new HashMap<>(); + additionalParams.put("access_type", "offline"); + final String authorizationUrl = service.getAuthorizationUrl(additionalParams); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + // Trade the Request Token and Verfier for the Access Token + System.out.println("Trading the Request Token for an Access Token..."); + OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + System.out.println("Refreshing the Access Token..."); + accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); + System.out.println("Refreshed the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } + +} From a44f6dcaa011104f77a9855a9feae8fddb10d5fb Mon Sep 17 00:00:00 2001 From: Joe Stazak Date: Wed, 2 Jan 2019 14:21:39 -0500 Subject: [PATCH 149/481] Updating authorization_url method in example --- .../com/github/scribejava/apis/examples/AsanaExample.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java index 5ae120df6..9165fc1b8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java @@ -36,9 +36,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain Auth URL System.out.println("Fetching the Authorication URL..."); System.out.println("Got the Authorization URL!"); - final Map additionalParams = new HashMap<>(); - additionalParams.put("access_type", "offline"); - final String authorizationUrl = service.getAuthorizationUrl(additionalParams); + final String authorizationUrl = service.getAuthorizationUrl(); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); From b29892c816453d12279d62421671820f0d3fcb80 Mon Sep 17 00:00:00 2001 From: Joe Stazak Date: Wed, 2 Jan 2019 14:24:42 -0500 Subject: [PATCH 150/481] Updating README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9d8162a93..314065569 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ ScribeJava support out-of-box several HTTP clients: ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box +* Asana (https://app.asana.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java) * Automatic (https://www.automatic.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java) * AWeber (http://www.aweber.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java) * Box (https://www.box.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java) From fac5e70bee6d2bcd7865feb90cef3aeea648b91f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 17 Jan 2019 18:49:26 +0300 Subject: [PATCH 151/481] * fix Muplipart request model and implement it for a jdk HTTP client (thanks to https://github.com/NTPape) --- changelog | 3 + pom.xml | 6 +- .../AbstractAsyncOnlyHttpClient.java | 13 + .../core/httpclient/BodyPartPayload.java | 56 +++- .../core/httpclient/HttpClient.java | 40 +++ .../core/httpclient/MultipartPayload.java | 82 ++++-- .../core/httpclient/jdk/JDKHttpClient.java | 144 ++++++++-- .../httpclient/multipart/BodyPartPayload.java | 26 ++ .../multipart/ByteArrayBodyPartPayload.java | 26 ++ .../FileByteArrayBodyPartPayload.java | 52 ++++ .../multipart/MultipartPayload.java | 173 +++++++++++ .../scribejava/core/model/OAuthRequest.java | 179 +++++++++++- .../scribejava/core/oauth/OAuthService.java | 3 + .../httpclient/jdk/JDKHttpClientTest.java | 268 ++++++++++++++++++ .../multipart/MultipartPayloadTest.java | 121 ++++++++ .../httpclient/ahc/AhcHttpClient.java | 14 +- .../httpclient/apache/ApacheHttpClient.java | 14 +- .../httpclient/ning/NingHttpClient.java | 14 +- scribejava-httpclient-okhttp/pom.xml | 2 +- .../httpclient/okhttp/OkHttpHttpClient.java | 26 +- 20 files changed, 1203 insertions(+), 59 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/BodyPartPayload.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/ByteArrayBodyPartPayload.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/FileByteArrayBodyPartPayload.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java diff --git a/changelog b/changelog index 96dfb8e84..fa676453f 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * fix Muplipart request model and implement it for a jdk HTTP client (thanks to https://github.com/NTPape) + [6.2.0] * add new API Microsoft Azure Active Directory (Azure AD) 2.0 (thanks to https://github.com/rzukow and https://github.com/dgrudenic) diff --git a/pom.xml b/pom.xml index 09aaf9fa1..1fac89595 100644 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,7 @@ com.squareup.okhttp3 mockwebserver - 3.12.0 + 3.12.1 test @@ -92,7 +92,7 @@ org.apache.maven.plugins maven-jar-plugin - 3.1.0 + 3.1.1 ${project.build.outputDirectory}/META-INF/MANIFEST.MF @@ -107,7 +107,7 @@ com.puppycrawl.tools checkstyle - 8.15 + 8.16 diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java index 6f75ee6c1..a54e51a58 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java @@ -18,7 +18,11 @@ public Response execute(String userAgent, Map headers, Verb http (OAuthRequest.ResponseConverter) null).get(); } + /** + * @deprecated {@inheritDoc} + */ @Override + @Deprecated public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents) throws InterruptedException, ExecutionException, IOException { @@ -26,6 +30,15 @@ public Response execute(String userAgent, Map headers, Verb http (OAuthRequest.ResponseConverter) null).get(); } + @Override + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + com.github.scribejava.core.httpclient.multipart.MultipartPayload bodyContents) + throws InterruptedException, ExecutionException, IOException { + + return executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, null, + (OAuthRequest.ResponseConverter) null).get(); + } + @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents) throws InterruptedException, ExecutionException, IOException { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java index 3e8c6d47e..2b349d666 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java @@ -1,27 +1,69 @@ package com.github.scribejava.core.httpclient; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * @deprecated use {@link com.github.scribejava.core.httpclient.multipart.ByteArrayBodyPartPayload} + */ +@Deprecated public class BodyPartPayload { - private final String contentDisposition; - private final String contentType; + private final Map headers; private final byte[] payload; - public BodyPartPayload(String contentDisposition, String contentType, byte[] payload) { - this.contentDisposition = contentDisposition; - this.contentType = contentType; + public BodyPartPayload(Map headers, byte[] payload) { + this.headers = headers; this.payload = payload; } + public BodyPartPayload(String contentDisposition, String contentType, byte[] payload) { + this(createHeadersMap(contentDisposition, contentType), payload); + } + + public BodyPartPayload(String contentDisposition, byte[] payload) { + this(contentDisposition, null, payload); + } + + public Map getHeaders() { + return headers; + } + + /** + * @return return + * @deprecated use {@link #getHeaders() } and then get("Content-Disposition") + */ + @Deprecated public String getContentDisposition() { - return contentDisposition; + return headers.get("Content-Disposition"); } + /** + * @return return + * @deprecated use {@link #getHeaders() } and then get("Content-Type") + */ + @Deprecated public String getContentType() { - return contentType; + return headers.get(HttpClient.CONTENT_TYPE); } public byte[] getPayload() { return payload; } + private static Map createHeadersMap(String contentDisposition, String contentType) { + if (contentDisposition == null && contentType == null) { + return Collections.emptyMap(); + } + + final Map headers = new HashMap<>(); + if (contentDisposition != null) { + headers.put("Content-Disposition", contentDisposition); + } + if (contentType != null) { + headers.put(HttpClient.CONTENT_TYPE, contentType); + } + return headers; + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java index 40f9663f5..4217ac717 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.httpclient; +import com.github.scribejava.core.httpclient.multipart.MultipartPayload; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; @@ -20,6 +21,27 @@ public interface HttpClient extends Closeable { Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter); + /** + * @param T + * @param userAgent userAgent + * @param headers headers + * @param httpVerb httpVerb + * @param completeUrl completeUrl + * @param bodyContents bodyContents + * @param callback callback + * @param converter converter + * @return return + * + * @deprecated use {@link #executeAsync(java.lang.String, java.util.Map, com.github.scribejava.core.model.Verb, + * java.lang.String, com.github.scribejava.core.httpclient.multipart.MultipartPayload, + * com.github.scribejava.core.model.OAuthAsyncRequestCallback, + * com.github.scribejava.core.model.OAuthRequest.ResponseConverter)} + */ + @Deprecated + Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter); + Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter); @@ -33,6 +55,24 @@ Future executeAsync(String userAgent, Map headers, Verb h Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents) throws InterruptedException, ExecutionException, IOException; + /** + * @param userAgent userAgent + * @param headers headers + * @param httpVerb httpVerb + * @param completeUrl completeUrl + * @param bodyContents bodyContents + * @return return + * @throws InterruptedException InterruptedException + * @throws ExecutionException ExecutionException + * @throws IOException IOException + * @deprecated use {@link #execute(java.lang.String, java.util.Map, com.github.scribejava.core.model.Verb, + * java.lang.String, com.github.scribejava.core.httpclient.multipart.MultipartPayload)} + */ + @Deprecated + Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + com.github.scribejava.core.httpclient.MultipartPayload bodyContents) + throws InterruptedException, ExecutionException, IOException; + Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents) throws InterruptedException, ExecutionException, IOException; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java index 71d67f508..3d4016ea1 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java @@ -1,47 +1,80 @@ package com.github.scribejava.core.httpclient; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Map; /** * The class containing more than one payload of multipart/form-data request + * + * @deprecated use {@link com.github.scribejava.core.httpclient.multipart.MultipartPayload} */ +@Deprecated public class MultipartPayload { + private static final String DEFAULT_SUBTYPE = "form-data"; + private final String boundary; + private final Map headers; private final List bodyParts = new ArrayList<>(); public MultipartPayload(String boundary) { this.boundary = boundary; + headers = Collections.singletonMap(HttpClient.CONTENT_TYPE, + "multipart/" + DEFAULT_SUBTYPE + "; boundary=\"" + boundary + '"'); } + /** + * @param bodyPart bodyPart + * @return return + * @deprecated no replace for that. implement yourself. See code here + * {@link com.github.scribejava.core.httpclient.jdk.JDKHttpClient + * #getPayload(com.github.scribejava.core.httpclient.MultipartPayload)} + */ + @Deprecated public byte[] getStartBoundary(BodyPartPayload bodyPart) { - return ("--" + boundary + "\r\n" - + "Content-Disposition: " + bodyPart.getContentDisposition() + "\r\n" - + (bodyPart.getContentType() == null - ? "" : HttpClient.CONTENT_TYPE + ": " + bodyPart.getContentType() + "\r\n") - + "\r\n").getBytes(); + final StringBuilder startBoundary = new StringBuilder(); + startBoundary.append("\r\n--") + .append(boundary) + .append("\r\n"); + + for (Map.Entry header : bodyPart.getHeaders().entrySet()) { + startBoundary.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + return startBoundary.append("\r\n").toString().getBytes(); } + /** + * @return return + * @deprecated no replace for that. implement yourself. See code here + * {@link com.github.scribejava.core.httpclient.jdk.JDKHttpClient + * #getPayload(com.github.scribejava.core.httpclient.MultipartPayload)} + */ + @Deprecated public byte[] getEndBoundary() { return ("\r\n--" + boundary + "--\r\n").getBytes(); } + /** + * @return return + * @deprecated no replace for that. implement yourself. See code here + * {@link com.github.scribejava.core.httpclient.jdk.JDKHttpClient + * #getPayload(com.github.scribejava.core.httpclient.MultipartPayload)} + */ + @Deprecated public int getContentLength() { int contentLength = 0; + for (BodyPartPayload bodyPart : bodyParts) { - contentLength += bodyPart.getPayload().length - + bodyPart.getContentDisposition().length(); - if (bodyPart.getContentType() != null) { - contentLength += 16 //length of constant portions of contentType header - + bodyPart.getContentType().length(); - } + contentLength += getStartBoundary(bodyPart).length + bodyPart.getPayload().length; + } + if (!bodyParts.isEmpty()) { + contentLength += getEndBoundary().length; } - - contentLength += (37 //length of constant portions of contentDisposition header, - //see getStartBoundary and getEndBoundary methods - + boundary.length() * 2 //twice. start and end parts - ) * bodyParts.size(); //for every part return contentLength; } @@ -52,4 +85,21 @@ public List getBodyParts() { public void addMultipartPayload(String contentDisposition, String contentType, byte[] payload) { bodyParts.add(new BodyPartPayload(contentDisposition, contentType, payload)); } + + /** + * @return return + * @deprecated use {@link #getHeaders() } and then get("Content-Type") + */ + @Deprecated + public String getContentType() { + return headers.get(HttpClient.CONTENT_TYPE); + } + + public Map getHeaders() { + return headers; + } + + public String getBoundary() { + return boundary; + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 7e87dba0b..b13186603 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -1,14 +1,16 @@ package com.github.scribejava.core.httpclient.jdk; import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.httpclient.BodyPartPayload; +import com.github.scribejava.core.httpclient.multipart.BodyPartPayload; import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.MultipartPayload; +import com.github.scribejava.core.httpclient.multipart.ByteArrayBodyPartPayload; +import com.github.scribejava.core.httpclient.multipart.MultipartPayload; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.OutputStream; @@ -45,6 +47,19 @@ public Future executeAsync(String userAgent, Map headers, converter); } + /** + * @deprecated {@inheritDoc} + */ + @Override + @Deprecated + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.OLD_MULTIPART, bodyContents, callback, + converter); + } + @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, @@ -99,6 +114,17 @@ public Response execute(String userAgent, Map headers, Verb http return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.MULTIPART, multipartPayloads); } + /** + * @deprecated {@inheritDoc} + */ + @Override + @Deprecated + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + com.github.scribejava.core.httpclient.MultipartPayload multipartPayloads) + throws InterruptedException, ExecutionException, IOException { + return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.OLD_MULTIPART, multipartPayloads); + } + @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents) throws InterruptedException, ExecutionException, IOException { @@ -145,6 +171,13 @@ void setBody(HttpURLConnection connection, Object bodyContents, boolean requires addBody(connection, (byte[]) bodyContents, requiresBody); } }, + OLD_MULTIPART { + @Override + void setBody(HttpURLConnection connection, Object bodyContents, boolean requiresBody) throws IOException { + addBody(connection, (com.github.scribejava.core.httpclient.MultipartPayload) bodyContents, + requiresBody); + } + }, MULTIPART { @Override void setBody(HttpURLConnection connection, Object bodyContents, boolean requiresBody) throws IOException { @@ -187,29 +220,109 @@ private static void addHeaders(HttpURLConnection connection, Map } } - /** - * Multipart implementation supporting more than one payload - */ + private static void addBody(HttpURLConnection connection, byte[] content, boolean requiresBody) throws IOException { + final int contentLength = content.length; + if (requiresBody || contentLength > 0) { + prepareConnectionForBodyAndGetOutputStream(connection, contentLength).write(content); + } + } + + private static void addBody(HttpURLConnection connection, + com.github.scribejava.core.httpclient.MultipartPayload multipartPayload, boolean requiresBody) + throws IOException { + + for (Map.Entry header : multipartPayload.getHeaders().entrySet()) { + connection.setRequestProperty(header.getKey(), header.getValue()); + } + + if (requiresBody) { + final ByteArrayOutputStream os = getPayload(multipartPayload); + + if (os.size() > 0) { + os.writeTo(prepareConnectionForBodyAndGetOutputStream(connection, os.size())); + } + } + } + private static void addBody(HttpURLConnection connection, MultipartPayload multipartPayload, boolean requiresBody) throws IOException { - final int contentLength = multipartPayload.getContentLength(); - if (requiresBody || contentLength > 0) { - final OutputStream os = prepareConnectionForBodyAndGetOutputStream(connection, contentLength); + for (Map.Entry header : multipartPayload.getHeaders().entrySet()) { + connection.setRequestProperty(header.getKey(), header.getValue()); + } - for (BodyPartPayload bodyPart : multipartPayload.getBodyParts()) { - os.write(multipartPayload.getStartBoundary(bodyPart)); + if (requiresBody) { + final ByteArrayOutputStream os = getPayload(multipartPayload); + + if (os.size() > 0) { + os.writeTo(prepareConnectionForBodyAndGetOutputStream(connection, os.size())); + } + } + } + + private static ByteArrayOutputStream getPayload( + com.github.scribejava.core.httpclient.MultipartPayload multipartPayload) throws IOException { + final ByteArrayOutputStream os = new ByteArrayOutputStream(); + final List bodyParts = multipartPayload.getBodyParts(); + if (!bodyParts.isEmpty()) { + final String boundary = multipartPayload.getBoundary(); + final byte[] startBoundary = ("\r\n--" + boundary + "\r\n").getBytes(); + + for (com.github.scribejava.core.httpclient.BodyPartPayload bodyPart : bodyParts) { + os.write(startBoundary); + + for (Map.Entry header : bodyPart.getHeaders().entrySet()) { + os.write((header.getKey() + ": " + header.getValue() + "\r\n").getBytes()); + } + os.write("\r\n".getBytes()); os.write(bodyPart.getPayload()); - os.write(multipartPayload.getEndBoundary()); } + + os.write(("\r\n--" + boundary + "--\r\n").getBytes()); } + return os; } - private static void addBody(HttpURLConnection connection, byte[] content, boolean requiresBody) throws IOException { - final int contentLength = content.length; - if (requiresBody || contentLength > 0) { - prepareConnectionForBodyAndGetOutputStream(connection, contentLength).write(content); + static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload) throws IOException { + final ByteArrayOutputStream os = new ByteArrayOutputStream(); + + final String preamble = multipartPayload.getPreamble(); + if (preamble != null) { + os.write(preamble.getBytes()); } + final List bodyParts = multipartPayload.getBodyParts(); + if (!bodyParts.isEmpty()) { + final String boundary = multipartPayload.getBoundary(); + final byte[] startBoundary = ("\r\n--" + boundary + "\r\n").getBytes(); + + for (BodyPartPayload bodyPart : bodyParts) { + os.write(startBoundary); + + final Map bodyPartHeaders = bodyPart.getHeaders(); + if (bodyPartHeaders != null) { + for (Map.Entry header : bodyPartHeaders.entrySet()) { + os.write((header.getKey() + ": " + header.getValue() + "\r\n").getBytes()); + } + } + + if (bodyPart instanceof MultipartPayload) { + getPayload((MultipartPayload) bodyPart).writeTo(os); + } else if (bodyPart instanceof ByteArrayBodyPartPayload) { + os.write("\r\n".getBytes()); + os.write(((ByteArrayBodyPartPayload) bodyPart).getPayload()); + } else { + throw new AssertionError(bodyPart.getClass()); + } + } + + os.write(("\r\n--" + boundary + "--\r\n").getBytes()); + final String epilogue = multipartPayload.getEpilogue(); + if (epilogue != null) { + os.write((epilogue + "\r\n").getBytes()); + } + + } + return os; } private static OutputStream prepareConnectionForBodyAndGetOutputStream(HttpURLConnection connection, @@ -218,7 +331,6 @@ private static OutputStream prepareConnectionForBodyAndGetOutputStream(HttpURLCo connection.setRequestProperty(CONTENT_LENGTH, String.valueOf(contentLength)); if (connection.getRequestProperty(CONTENT_TYPE) == null) { connection.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); - } connection.setDoOutput(true); return connection.getOutputStream(); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/BodyPartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/BodyPartPayload.java new file mode 100644 index 000000000..ee426176b --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/BodyPartPayload.java @@ -0,0 +1,26 @@ +package com.github.scribejava.core.httpclient.multipart; + +import com.github.scribejava.core.httpclient.HttpClient; +import java.util.Collections; +import java.util.Map; + +public abstract class BodyPartPayload { + + private final Map headers; + + public BodyPartPayload() { + this((Map) null); + } + + public BodyPartPayload(String contentType) { + this(contentType == null ? null : Collections.singletonMap(HttpClient.CONTENT_TYPE, contentType)); + } + + public BodyPartPayload(Map headers) { + this.headers = headers; + } + + public Map getHeaders() { + return headers; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/ByteArrayBodyPartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/ByteArrayBodyPartPayload.java new file mode 100644 index 000000000..7fd0d6d98 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/ByteArrayBodyPartPayload.java @@ -0,0 +1,26 @@ +package com.github.scribejava.core.httpclient.multipart; + +import java.util.Map; + +public class ByteArrayBodyPartPayload extends BodyPartPayload { + + private final byte[] payload; + + public ByteArrayBodyPartPayload(byte[] payload) { + this.payload = payload; + } + + public ByteArrayBodyPartPayload(byte[] payload, String contentType) { + super(contentType); + this.payload = payload; + } + + public ByteArrayBodyPartPayload(byte[] payload, Map headers) { + super(headers); + this.payload = payload; + } + + public byte[] getPayload() { + return payload; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/FileByteArrayBodyPartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/FileByteArrayBodyPartPayload.java new file mode 100644 index 000000000..524977819 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/FileByteArrayBodyPartPayload.java @@ -0,0 +1,52 @@ +package com.github.scribejava.core.httpclient.multipart; + +import com.github.scribejava.core.httpclient.HttpClient; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public class FileByteArrayBodyPartPayload extends ByteArrayBodyPartPayload { + + public FileByteArrayBodyPartPayload(byte[] payload) { + this(payload, null); + } + + public FileByteArrayBodyPartPayload(byte[] payload, String name) { + this(payload, name, null); + } + + public FileByteArrayBodyPartPayload(byte[] payload, String name, String filename) { + this(null, payload, name, filename); + } + + public FileByteArrayBodyPartPayload(String contentType, byte[] payload) { + this(contentType, payload, null); + } + + public FileByteArrayBodyPartPayload(String contentType, byte[] payload, String name) { + this(contentType, payload, name, null); + } + + public FileByteArrayBodyPartPayload(String contentType, byte[] payload, String name, String filename) { + super(payload, composeHeaders(contentType, name, filename)); + } + + private static Map composeHeaders(String contentType, String name, String filename) { + + String contentDispositionHeader = "form-data"; + if (name != null) { + contentDispositionHeader += "; name=\"" + name + '"'; + } + if (filename != null) { + contentDispositionHeader += "; filename=\"" + filename + '"'; + } + if (contentType == null) { + return Collections.singletonMap("Content-Disposition", contentDispositionHeader); + } else { + final Map headers = new HashMap<>(); + headers.put(HttpClient.CONTENT_TYPE, contentType); + headers.put("Content-Disposition", contentDispositionHeader); + return headers; + } + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java new file mode 100644 index 000000000..5c9282272 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java @@ -0,0 +1,173 @@ +package com.github.scribejava.core.httpclient.multipart; + +import com.github.scribejava.core.httpclient.HttpClient; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class MultipartPayload extends BodyPartPayload { + private static final String B_CHARS_NO_SPACE_PATTERN = "0-9a-zA-Z'()+_,-./:=?"; + private static final String B_CHARS_PATTERN = B_CHARS_NO_SPACE_PATTERN + " "; + private static final String BOUNDARY_PATTERN = '[' + B_CHARS_PATTERN + "]{0,69}[" + B_CHARS_NO_SPACE_PATTERN + ']'; + private static final Pattern BOUNDARY_REGEXP = Pattern.compile(BOUNDARY_PATTERN); + private static final Pattern BOUNDARY_FROM_HEADER_REGEXP + = Pattern.compile("; boundary=\"?(" + BOUNDARY_PATTERN + ")\"?"); + + private static final String DEFAULT_SUBTYPE = "form-data"; + + private final String boundary; + private String preamble; + private final List bodyParts = new ArrayList<>(); + private String epilogue; + + public MultipartPayload() { + this(null, generateDefaultBoundary(), null); + } + + public MultipartPayload(String boundary) { + this(null, boundary, null); + } + + public MultipartPayload(String subtype, String boundary) { + this(subtype, boundary, null); + } + + public MultipartPayload(Map headers) { + this(null, parseOrGenerateBoundary(headers), headers); + } + + public MultipartPayload(String boundary, Map headers) { + this(null, boundary, headers); + } + + public MultipartPayload(String subtype, String boundary, Map headers) { + super(composeHeaders(subtype, boundary, headers)); + this.boundary = boundary; + } + + private static Map composeHeaders(String subtype, String boundary, Map headersIn) + throws IllegalArgumentException { + checkBoundarySyntax(boundary); + final Map headersOut; + String contentTypeHeader = headersIn == null ? null : headersIn.get(HttpClient.CONTENT_TYPE); + if (contentTypeHeader == null) { + contentTypeHeader = "multipart/" + (subtype == null ? DEFAULT_SUBTYPE : subtype) + + "; boundary=\"" + boundary + '"'; + if (headersIn == null) { + headersOut = Collections.singletonMap(HttpClient.CONTENT_TYPE, contentTypeHeader); + } else { + headersOut = headersIn; + headersOut.put(HttpClient.CONTENT_TYPE, contentTypeHeader); + } + } else { + headersOut = headersIn; + final String parsedBoundary = parseBoundaryFromHeader(contentTypeHeader); + if (parsedBoundary == null) { + headersOut.put(HttpClient.CONTENT_TYPE, contentTypeHeader + "; boundary=\"" + boundary + '"'); + } else if (!parsedBoundary.equals(boundary)) { + throw new IllegalArgumentException( + "Different boundaries was passed in constructors. One as argument, second as header"); + } + } + return headersOut; + } + + static void checkBoundarySyntax(String boundary) { + if (boundary == null || !BOUNDARY_REGEXP.matcher(boundary).matches()) { + throw new IllegalArgumentException("{'boundary'='" + boundary + "'} has invaid syntax. Should be '" + + BOUNDARY_PATTERN + "'."); + } + } + + private static String parseOrGenerateBoundary(Map headers) { + final String parsedBoundary = parseBoundaryFromHeader(headers.get(HttpClient.CONTENT_TYPE)); + return parsedBoundary == null ? generateDefaultBoundary() : parsedBoundary; + } + + private static String generateDefaultBoundary() { + return "----ScribeJava----" + System.currentTimeMillis(); + } + + static String parseBoundaryFromHeader(String contentTypeHeader) { + if (contentTypeHeader == null) { + return null; + } + final Matcher matcher = BOUNDARY_FROM_HEADER_REGEXP.matcher(contentTypeHeader); + return matcher.find() ? matcher.group(1) : null; + } + + public void addFileBodyPart(byte[] fileContent) { + addBodyPart(new FileByteArrayBodyPartPayload(fileContent)); + } + + public void addFileBodyPart(byte[] fileContent, String name) { + addBodyPart(new FileByteArrayBodyPartPayload(fileContent, name)); + } + + public void addFileBodyPart(byte[] fileContent, String name, String filename) { + addBodyPart(new FileByteArrayBodyPartPayload(fileContent, name, filename)); + } + + public void addFileBodyPart(String contentType, byte[] fileContent) { + addBodyPart(new FileByteArrayBodyPartPayload(contentType, fileContent)); + } + + public void addFileBodyPart(String contentType, byte[] fileContent, String name) { + addBodyPart(new FileByteArrayBodyPartPayload(contentType, fileContent, name)); + } + + public void addFileBodyPart(String contentType, byte[] fileContent, String name, String filename) { + addBodyPart(new FileByteArrayBodyPartPayload(contentType, fileContent, name, filename)); + } + + public void addBodyPart(BodyPartPayload bodyPartPayload) { + bodyParts.add(bodyPartPayload); + } + + public void addBodyPart(MultipartPayload multipartPayload) { + if (multipartPayload.getBoundary().equals(boundary)) { + throw new IllegalArgumentException("{'boundary'}={'" + boundary + + "'} is the same for parent MultipartPayload and child"); + } + bodyParts.add(multipartPayload); + } + + public void addBodyPart(byte[] bodyPartPayload) { + addBodyPart(new ByteArrayBodyPartPayload(bodyPartPayload)); + } + + public void addBodyPart(byte[] bodyPartPayload, String contentType) { + addBodyPart(new ByteArrayBodyPartPayload(bodyPartPayload, contentType)); + } + + public void addBodyPart(byte[] bodyPartPayload, Map headers) { + addBodyPart(new ByteArrayBodyPartPayload(bodyPartPayload, headers)); + } + + public List getBodyParts() { + return bodyParts; + } + + public String getBoundary() { + return boundary; + } + + public String getPreamble() { + return preamble; + } + + public void setPreamble(String preamble) { + this.preamble = preamble; + } + + public String getEpilogue() { + return epilogue; + } + + public void setEpilogue(String epilogue) { + this.epilogue = epilogue; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index 87ace27bc..606577fbb 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -1,7 +1,8 @@ package com.github.scribejava.core.model; import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.httpclient.MultipartPayload; +import com.github.scribejava.core.httpclient.multipart.FileByteArrayBodyPartPayload; +import com.github.scribejava.core.httpclient.multipart.MultipartPayload; import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -30,6 +31,7 @@ public class OAuthRequest { private String stringPayload; private byte[] byteArrayPayload; private File filePayload; + private com.github.scribejava.core.httpclient.MultipartPayload oldMultipartPayload; private MultipartPayload multipartPayload; private final Map oauthParameters = new HashMap<>(); @@ -128,43 +130,190 @@ public void addParameter(String key, String value) { } /** - * Set boundary of multipart request - * - * @param boundary can be any string + * @param boundary boundary + * @deprecated create {@link #initMultipartPayload(java.lang.String) } */ + @Deprecated public void initMultipartBoundary(String boundary) { - multipartPayload = new MultipartPayload(boundary == null + oldMultipartPayload = new com.github.scribejava.core.httpclient.MultipartPayload(boundary == null ? Long.toString(System.currentTimeMillis()) : boundary); } /** - * init boundary of multipart request with default boundary + * @deprecated use {@link #initMultipartPayload()} */ + @Deprecated public void initMultipartBoundary() { initMultipartBoundary(null); } /** - * you can invoke {@link #initMultipartBoundary(java.lang.String) } to set custom boundary * @param contentDisposition contentDisposition * @param contentType contentType * @param payload payload + * @deprecated use {@link #addFileByteArrayBodyPartPayloadInMultipartPayload(java.lang.String, byte[], + * java.lang.String, java.lang.String)} */ + @Deprecated public void addMultipartPayload(String contentDisposition, String contentType, byte[] payload) { - if (multipartPayload == null) { + if (oldMultipartPayload == null) { initMultipartBoundary(); } - multipartPayload.addMultipartPayload(contentDisposition, contentType, payload); + oldMultipartPayload.addMultipartPayload(contentDisposition, contentType, payload); } + public MultipartPayload getMultipartPayload() { + return multipartPayload; + } + + /** + * @param contentDisposition contentDisposition + * @param contentType contentType + * @param payload payload + * @deprecated use {@link #setFileByteArrayBodyPartPayloadInMultipartPayload(java.lang.String, byte[], + * java.lang.String, java.lang.String)} + */ + @Deprecated public void setMultipartPayload(String contentDisposition, String contentType, byte[] payload) { setMultipartPayload(null, contentDisposition, contentType, payload); } + /** + * @param boundary boundary + * @param contentDisposition contentDisposition + * @param contentType contentType + * @param payload payload + * @deprecated use {@link #initMultipartPayload(java.lang.String) } + * and then {@link #setFileByteArrayBodyPartPayloadInMultipartPayload(java.lang.String, byte[], java.lang.String, + * java.lang.String)} + */ + @Deprecated public void setMultipartPayload(String boundary, String contentDisposition, String contentType, byte[] payload) { initMultipartBoundary(boundary); - multipartPayload.addMultipartPayload(contentDisposition, contentType, payload); + oldMultipartPayload.addMultipartPayload(contentDisposition, contentType, payload); + } + + public void setMultipartPayload(MultipartPayload multipartPayload) { + this.multipartPayload = multipartPayload; + } + + public void initMultipartPayload() { + this.multipartPayload = new MultipartPayload(); + } + + public void initMultipartPayload(String boundary) { + this.multipartPayload = new MultipartPayload(boundary); + } + + public void initMultipartPayload(String subtype, String boundary) { + this.multipartPayload = new MultipartPayload(subtype, boundary); + } + + public void initMultipartPayload(Map headers) { + this.multipartPayload = new MultipartPayload(headers); + } + + public void initMultipartPayload(String boundary, Map headers) { + this.multipartPayload = new MultipartPayload(boundary, headers); + } + + public void initMultipartPayload(String subtype, String boundary, Map headers) { + this.multipartPayload = new MultipartPayload(subtype, boundary, headers); + } + + public void setByteArrayBodyPartPayloadInMultipartPayload(byte[] bodyPartPayload) { + initMultipartPayload(); + addByteArrayBodyPartPayloadInMultipartPayload(bodyPartPayload); + } + + public void setByteArrayBodyPartPayloadInMultipartPayload(byte[] bodyPartPayload, String contentType) { + initMultipartPayload(); + addByteArrayBodyPartPayloadInMultipartPayload(bodyPartPayload, contentType); + } + + public void setByteArrayBodyPartPayloadInMultipartPayload(byte[] bodyPartPayload, Map headers) { + initMultipartPayload(); + addByteArrayBodyPartPayloadInMultipartPayload(bodyPartPayload, headers); + } + + public void addByteArrayBodyPartPayloadInMultipartPayload(byte[] bodyPartPayload) { + multipartPayload.addBodyPart(bodyPartPayload); + } + + public void addByteArrayBodyPartPayloadInMultipartPayload(byte[] bodyPartPayload, String contentType) { + multipartPayload.addBodyPart(bodyPartPayload, contentType); + } + + public void addByteArrayBodyPartPayloadInMultipartPayload(byte[] bodyPartPayload, Map headers) { + multipartPayload.addBodyPart(bodyPartPayload, headers); + } + + public void setFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent) { + initMultipartPayload(); + addFileByteArrayBodyPartPayloadInMultipartPayload(fileContent); + } + + public void setFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent) { + initMultipartPayload(); + addFileByteArrayBodyPartPayloadInMultipartPayload(contentType, fileContent); + } + + public void setFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent, String name) { + initMultipartPayload(); + addFileByteArrayBodyPartPayloadInMultipartPayload(fileContent, name); + } + + public void setFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent, String name) { + initMultipartPayload(); + addFileByteArrayBodyPartPayloadInMultipartPayload(contentType, fileContent, name); + } + + public void setFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent, String name, String filename) { + initMultipartPayload(); + addFileByteArrayBodyPartPayloadInMultipartPayload(fileContent, name, filename); + } + + public void setFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent, String name, + String filename) { + initMultipartPayload(); + addFileByteArrayBodyPartPayloadInMultipartPayload(contentType, fileContent, name, filename); + } + + public void setFileByteArrayBodyPartPayloadInMultipartPayload( + FileByteArrayBodyPartPayload fileByteArrayBodyPartPayload) { + initMultipartPayload(); + addFileByteArrayBodyPartPayloadInMultipartPayload(fileByteArrayBodyPartPayload); + } + + public void addFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent) { + multipartPayload.addFileBodyPart(fileContent); + } + + public void addFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent) { + multipartPayload.addFileBodyPart(contentType, fileContent); + } + + public void addFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent, String name) { + multipartPayload.addFileBodyPart(fileContent, name); + } + + public void addFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent, String name) { + multipartPayload.addFileBodyPart(contentType, fileContent, name); + } + + public void addFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent, String name, String filename) { + multipartPayload.addFileBodyPart(fileContent, name, filename); + } + + public void addFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent, String name, + String filename) { + multipartPayload.addFileBodyPart(contentType, fileContent, name, filename); + } + + public void addFileByteArrayBodyPartPayloadInMultipartPayload( + FileByteArrayBodyPartPayload fileByteArrayBodyPartPayload) { + multipartPayload.addBodyPart(fileByteArrayBodyPartPayload); } /** @@ -202,6 +351,7 @@ private void resetPayload() { stringPayload = null; byteArrayPayload = null; filePayload = null; + oldMultipartPayload = null; multipartPayload = null; } @@ -281,8 +431,13 @@ public byte[] getByteArrayPayload() { } } - public MultipartPayload getMultipartPayloads() { - return multipartPayload; + /** + * @return return + * @deprecated use {@link #getMultipartPayload() } + */ + @Deprecated + public com.github.scribejava.core.httpclient.MultipartPayload getMultipartPayloads() { + return oldMultipartPayload; } public File getFilePayload() { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 9f331a4ba..94aaa4c38 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -110,6 +110,9 @@ public Response execute(OAuthRequest request) throws InterruptedException, Execu } else if (request.getStringPayload() != null) { return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), request.getStringPayload()); + } else if (request.getMultipartPayload() != null) { + return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), + request.getMultipartPayload()); } else if (request.getMultipartPayloads() != null) { return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), request.getMultipartPayloads()); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java index 6ac1070fa..79a4a23f0 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java @@ -2,6 +2,15 @@ import com.github.scribejava.core.AbstractClientTest; import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.multipart.ByteArrayBodyPartPayload; +import com.github.scribejava.core.httpclient.multipart.FileByteArrayBodyPartPayload; +import com.github.scribejava.core.httpclient.multipart.MultipartPayload; +import java.io.IOException; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; +import org.junit.Assert; +import org.junit.Test; public class JDKHttpClientTest extends AbstractClientTest { @@ -9,4 +18,263 @@ public class JDKHttpClientTest extends AbstractClientTest { protected HttpClient createNewClient() { return new JDKHttpClient(); } + + @Test + public void testEmptyMultipartPayload() throws IOException { + final MultipartPayload mP = new MultipartPayload(); + + final StringBuilder sb = new StringBuilder(); + for (Map.Entry header : mP.getHeaders().entrySet()) { + sb.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + + sb.append("\r\n").append(JDKHttpClient.getPayload(mP).toString()); + Assert.assertEquals("Content-Type: multipart/form-data; boundary=\"" + mP.getBoundary() + "\"\r\n\r\n", + sb.toString()); + } + + @Test + public void testSimpleMultipartPayload() throws IOException { + final Map headers = new LinkedHashMap<>(); + headers.put("X-Header", "X-Value"); + headers.put("Content-Disposition", "Content-Disposition-Value"); + final MultipartPayload mP = new MultipartPayload("mixed", "simple boundary", headers); + mP.setPreamble("This is the preamble. It is to be ignored, though it\n" + + "is a handy place for composition agents to include an\n" + + "explanatory note to non-MIME conformant readers."); + + mP.addBodyPart(("This is implicitly typed plain US-ASCII text.\n" + + "It does NOT end with a linebreak.").getBytes()); + + final ByteArrayBodyPartPayload bP = new ByteArrayBodyPartPayload( + ("This is explicitly typed plain US-ASCII text.\n" + + "It DOES end with a linebreak.\n").getBytes(), + Collections.singletonMap(HttpClient.CONTENT_TYPE, "text/plain; charset=us-ascii")); + mP.addBodyPart(bP); + + mP.setEpilogue("This is the epilogue. It is also to be ignored."); + + final StringBuilder sb = new StringBuilder(); + for (Map.Entry header : mP.getHeaders().entrySet()) { + sb.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + sb.append("\r\n").append(JDKHttpClient.getPayload(mP).toString()); + Assert.assertEquals("X-Header: X-Value\r\n" + + "Content-Disposition: Content-Disposition-Value\r\n" + + "Content-Type: multipart/mixed; boundary=\"simple boundary\"\r\n" + + "\r\n" + + "This is the preamble. It is to be ignored, though it\n" + + "is a handy place for composition agents to include an\n" + + "explanatory note to non-MIME conformant readers." + + "\r\n" + + "--simple boundary\r\n" + + "\r\n" + + "This is implicitly typed plain US-ASCII text.\n" + + "It does NOT end with a linebreak." + + "\r\n" + + "--simple boundary\r\n" + + "Content-Type: text/plain; charset=us-ascii\r\n" + + "\r\n" + + "This is explicitly typed plain US-ASCII text.\n" + + "It DOES end with a linebreak.\n" + + "\r\n" + + "--simple boundary--\r\n" + + "This is the epilogue. It is also to be ignored.\r\n", + sb.toString()); + } + + @Test + public void testCRLFMultipartPayload() throws IOException { + final MultipartPayload mP = new MultipartPayload("simple-boundary"); + mP.addBodyPart("It does NOT end with a linebreak.".getBytes()); + mP.addBodyPart("It does end with a \\r linebreak.\r".getBytes()); + mP.addBodyPart("It does end with a \\n linebreak.\n".getBytes()); + mP.addBodyPart("It does end with a \\r\\n linebreak.\r\n".getBytes()); + mP.addBodyPart("the last one".getBytes()); + + final StringBuilder sb = new StringBuilder(); + for (Map.Entry header : mP.getHeaders().entrySet()) { + sb.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + sb.append("\r\n").append(JDKHttpClient.getPayload(mP).toString()); + Assert.assertEquals("Content-Type: multipart/form-data; boundary=\"simple-boundary\"\r\n" + + "\r\n" + + "\r\n" + + "--simple-boundary\r\n" + + "\r\n" + + "It does NOT end with a linebreak." + + "\r\n" + + "--simple-boundary\r\n" + + "\r\n" + + "It does end with a \\r linebreak.\r" + + "\r\n" + + "--simple-boundary\r\n" + + "\r\n" + + "It does end with a \\n linebreak.\n" + + "\r\n" + + "--simple-boundary\r\n" + + "\r\n" + + "It does end with a \\r\\n linebreak.\r\n" + + "\r\n" + + "--simple-boundary\r\n" + + "\r\n" + + "the last one" + + "\r\n" + + "--simple-boundary--\r\n", + sb.toString()); + } + + @Test + public void testFileByteArrayBodyPartPayloadMultipartPayload() throws IOException { + final MultipartPayload mP = new MultipartPayload("testFileByteArrayBodyPartPayloadMultipartPayload boundary"); + mP.addBodyPart(new FileByteArrayBodyPartPayload("fileContent".getBytes(), "name", "filename.ext")); + + final StringBuilder sb = new StringBuilder(); + for (Map.Entry header : mP.getHeaders().entrySet()) { + sb.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + + sb.append("\r\n").append(JDKHttpClient.getPayload(mP).toString()); + Assert.assertEquals("Content-Type: multipart/form-data; " + + "boundary=\"testFileByteArrayBodyPartPayloadMultipartPayload boundary\"\r\n" + + "\r\n" + + "\r\n" + + "--testFileByteArrayBodyPartPayloadMultipartPayload boundary\r\n" + + "Content-Disposition: form-data; name=\"name\"; filename=\"filename.ext\"\r\n" + + "\r\n" + + "fileContent" + + "\r\n" + + "--testFileByteArrayBodyPartPayloadMultipartPayload boundary--\r\n", + sb.toString() + ); + } + + @Test + public void testComplexMultipartPayload() throws IOException { + final MultipartPayload mP = new MultipartPayload("mixed", "unique-boundary-1"); + + mP.setPreamble("This is the preamble area of a multipart message.\n" + + "Mail readers that understand multipart format\n" + + "should ignore this preamble.\n" + + "\n" + + "If you are reading this text, you might want to\n" + + "consider changing to a mail reader that understands\n" + + "how to properly display multipart messages.\n"); + + mP.addBodyPart("... Some text appears here ...".getBytes()); + + mP.addBodyPart(("This could have been part of the previous part, but\n" + + "illustrates explicit versus implicit typing of body\n" + + "parts.\n").getBytes(), "text/plain; charset=US-ASCII"); + + final MultipartPayload innerMP = new MultipartPayload("parallel", "unique-boundary-2"); + mP.addBodyPart(innerMP); + + final Map audioHeaders = new LinkedHashMap<>(); + audioHeaders.put("Content-Type", "audio/basic"); + audioHeaders.put("Content-Transfer-Encoding", "base64"); + innerMP.addBodyPart(("... base64-encoded 8000 Hz single-channel\n" + + " mu-law-format audio data goes here ...").getBytes(), audioHeaders); + + final Map imageHeaders = new LinkedHashMap<>(); + imageHeaders.put("Content-Type", "image/jpeg"); + imageHeaders.put("Content-Transfer-Encoding", "base64"); + innerMP.addBodyPart("... base64-encoded image data goes here ...".getBytes(), imageHeaders); + + mP.addBodyPart(("This is enriched.\n" + + "as defined in RFC 1896\n" + + "\n" + + "Isn't it\n" + + "cool?\n").getBytes(), "text/enriched"); + + mP.addBodyPart(("From: (mailbox in US-ASCII)\n" + + "To: (address in US-ASCII)\n" + + "Subject: (subject in US-ASCII)\n" + + "Content-Type: Text/plain; charset=ISO-8859-1\n" + + "Content-Transfer-Encoding: Quoted-printable\n" + + "\n" + + "... Additional text in ISO-8859-1 goes here ...\n").getBytes(), "message/rfc822"); + + final StringBuilder sb = new StringBuilder(); + for (Map.Entry header : mP.getHeaders().entrySet()) { + sb.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + sb.append("\r\n").append(JDKHttpClient.getPayload(mP).toString()); + Assert.assertEquals("Content-Type: multipart/mixed; boundary=\"unique-boundary-1\"\r\n" + + "\r\n" + + "This is the preamble area of a multipart message.\n" + + "Mail readers that understand multipart format\n" + + "should ignore this preamble.\n" + + "\n" + + "If you are reading this text, you might want to\n" + + "consider changing to a mail reader that understands\n" + + "how to properly display multipart messages.\n" + + "\r\n" + + "--unique-boundary-1\r\n" + + "\r\n" + + "... Some text appears here ..." + + "\r\n" + + "--unique-boundary-1\r\n" + + "Content-Type: text/plain; charset=US-ASCII\r\n" + + "\r\n" + + "This could have been part of the previous part, but\n" + + "illustrates explicit versus implicit typing of body\n" + + "parts.\n" + + "\r\n" + + "--unique-boundary-1\r\n" + + "Content-Type: multipart/parallel; boundary=\"unique-boundary-2\"\r\n" + + "\r\n" + + "--unique-boundary-2\r\n" + + "Content-Type: audio/basic\r\n" + + "Content-Transfer-Encoding: base64\r\n" + + "\r\n" + + "... base64-encoded 8000 Hz single-channel\n" + + " mu-law-format audio data goes here ..." + + "\r\n" + + "--unique-boundary-2\r\n" + + "Content-Type: image/jpeg\r\n" + + "Content-Transfer-Encoding: base64\r\n" + + "\r\n" + + "... base64-encoded image data goes here ..." + + "\r\n" + + "--unique-boundary-2--\r\n" + + "\r\n" + + "--unique-boundary-1\r\n" + + "Content-Type: text/enriched\r\n" + + "\r\n" + + "This is enriched.\n" + + "as defined in RFC 1896\n" + + "\n" + + "Isn't it\n" + + "cool?\n" + + "\r\n" + + "--unique-boundary-1\r\n" + + "Content-Type: message/rfc822\r\n" + + "\r\n" + + "From: (mailbox in US-ASCII)\n" + + "To: (address in US-ASCII)\n" + + "Subject: (subject in US-ASCII)\n" + + "Content-Type: Text/plain; charset=ISO-8859-1\n" + + "Content-Transfer-Encoding: Quoted-printable\n" + + "\n" + + "... Additional text in ISO-8859-1 goes here ...\n" + + "\r\n" + + "--unique-boundary-1--\r\n", + sb.toString()); + } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java new file mode 100644 index 000000000..a7989a01e --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java @@ -0,0 +1,121 @@ +package com.github.scribejava.core.httpclient.multipart; + +import org.hamcrest.core.StringStartsWith; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class MultipartPayloadTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void testValidCheckBoundarySyntax() { + MultipartPayload.checkBoundarySyntax("0aA'()+_,-./:=?"); + MultipartPayload.checkBoundarySyntax("0aA'()+_,- ./:=?"); + MultipartPayload.checkBoundarySyntax(" 0aA'()+_,-./:=?"); + MultipartPayload.checkBoundarySyntax("1234567890123456789012345678901234567890123456789012345678901234567890"); + } + + @Test + public void testNonValidLastWhiteSpaceCheckBoundarySyntax() { + final String boundary = "0aA'()+_,-./:=? "; + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage( + StringStartsWith.startsWith("{'boundary'='" + boundary + "'} has invaid syntax. Should be '")); + MultipartPayload.checkBoundarySyntax(boundary); + } + + @Test + public void testNonValidEmptyCheckBoundarySyntax() { + final String boundary = ""; + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage( + StringStartsWith.startsWith("{'boundary'='" + boundary + "'} has invaid syntax. Should be '")); + MultipartPayload.checkBoundarySyntax(boundary); + } + + @Test + public void testNonValidIllegalSymbolCheckBoundarySyntax() { + final String boundary = "0aA'()+_;,-./:=? "; + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage( + StringStartsWith.startsWith("{'boundary'='" + boundary + "'} has invaid syntax. Should be '")); + MultipartPayload.checkBoundarySyntax(boundary); + } + + @Test + public void testNonValidTooLongCheckBoundarySyntax() { + final String boundary = "12345678901234567890123456789012345678901234567890123456789012345678901"; + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage( + StringStartsWith.startsWith("{'boundary'='" + boundary + "'} has invaid syntax. Should be '")); + MultipartPayload.checkBoundarySyntax(boundary); + } + + @Test + public void testNonValidNullCheckBoundarySyntax() { + final String boundary = null; + thrown.expect(IllegalArgumentException.class); + thrown.expectMessage( + StringStartsWith.startsWith("{'boundary'='" + boundary + "'} has invaid syntax. Should be '")); + MultipartPayload.checkBoundarySyntax(boundary); + } + + @Test + public void testParseBoundaryFromHeader() { + assertNull(MultipartPayload.parseBoundaryFromHeader(null)); + + assertEquals("0aA'()+_,-./:=?", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_,-./:=?\"")); + + assertEquals("0aA'()+_, -./:=?", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_, -./:=?\"")); + + assertEquals("0aA'()+_, -./:=?", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_, -./:=? \"")); + + assertEquals("0aA'()+_,-./:=?", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_,-./:=?")); + + assertEquals("0aA'()+_, -./:=?", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_, -./:=?")); + + assertEquals("0aA'()+_, -./:=?", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_, -./:=? ")); + + assertEquals(" 0aA'()+_, -./:=?", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary= 0aA'()+_, -./:=?")); + + assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundar=0aA'()+_, -./:=? ")); + assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; ")); + assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype;")); + assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype")); + assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=")); + + assertEquals("0aA'()+_,", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_,; -./:=? ")); + + assertEquals("0aA'()+_, -./:=?", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_, -./:=?")); + + assertEquals("0aA'()+_, -./:=?", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_, -./:=?\"")); + + assertEquals("1234567890123456789012345678901234567890123456789012345678901234567890", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; " + + "boundary=1234567890123456789012345678901234567890123456789012345678901234567890")); + + assertEquals("1234567890123456789012345678901234567890123456789012345678901234567890", + MultipartPayload.parseBoundaryFromHeader("multipart/subtype; " + + "boundary=12345678901234567890123456789012345678901234567890123456789012345678901")); + + assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=")); + assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"\"")); + assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=;123")); + assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"\"123")); + } +} diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java index ebe551571..877d1e1f2 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java @@ -1,7 +1,7 @@ package com.github.scribejava.httpclient.ahc; import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; -import com.github.scribejava.core.httpclient.MultipartPayload; +import com.github.scribejava.core.httpclient.multipart.MultipartPayload; import com.github.scribejava.core.java8.Consumer; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; @@ -48,6 +48,18 @@ public Future executeAsync(String userAgent, Map headers, converter); } + /** + * @deprecated {@inheritDoc} + */ + @Override + @Deprecated + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + + throw new UnsupportedOperationException("AhcHttpClient does not support MultipartPayload yet."); + } + @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java index dc5a3607b..168376604 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java @@ -1,7 +1,7 @@ package com.github.scribejava.httpclient.apache; import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; -import com.github.scribejava.core.httpclient.MultipartPayload; +import com.github.scribejava.core.httpclient.multipart.MultipartPayload; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; @@ -54,6 +54,18 @@ public Future executeAsync(String userAgent, Map headers, return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, entity, callback, converter); } + /** + * @deprecated {@inheritDoc} + */ + @Override + @Deprecated + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + + throw new UnsupportedOperationException("ApacheHttpClient does not support MultipartPayload yet."); + } + @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java index 4463ea9e1..6b065a4db 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java @@ -1,7 +1,7 @@ package com.github.scribejava.httpclient.ning; import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; -import com.github.scribejava.core.httpclient.MultipartPayload; +import com.github.scribejava.core.httpclient.multipart.MultipartPayload; import com.github.scribejava.core.java8.Consumer; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; @@ -54,6 +54,18 @@ public Future executeAsync(String userAgent, Map headers, converter); } + /** + * @deprecated {@inheritDoc} + */ + @Override + @Deprecated + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + + throw new UnsupportedOperationException("NingHttpClient does not support MultipartPayload yet."); + } + @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 701ba6109..956c762da 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 3.12.0 + 3.12.1 com.github.scribejava diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 8436f11ed..18ae14b13 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -1,7 +1,7 @@ package com.github.scribejava.httpclient.okhttp; import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.MultipartPayload; +import com.github.scribejava.core.httpclient.multipart.MultipartPayload; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; @@ -60,6 +60,18 @@ public Future executeAsync(String userAgent, Map headers, converter); } + /** + * @deprecated {@inheritDoc} + */ + @Override + @Deprecated + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + + throw new UnsupportedOperationException("OKHttpClient does not support Multipart payload for the moment"); + } + @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, @@ -107,6 +119,18 @@ public Response execute(String userAgent, Map headers, Verb http throw new UnsupportedOperationException("OKHttpClient does not support Multipart payload for the moment"); } + /** + * @deprecated {@inheritDoc} + */ + @Override + @Deprecated + public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, + com.github.scribejava.core.httpclient.MultipartPayload bodyContents) + throws InterruptedException, ExecutionException, IOException { + + throw new UnsupportedOperationException("OKHttpClient does not support Multipart payload for the moment"); + } + @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents) throws InterruptedException, ExecutionException, IOException { From 6ccc5f4bcad5b6c7dbbabee252025ba60fc2c23a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 6 Feb 2019 15:19:30 +0300 Subject: [PATCH 152/481] update deps --- pom.xml | 4 ++-- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 4 ++-- scribejava-httpclient-okhttp/pom.xml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 1fac89595..c1d6db3fb 100644 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,7 @@ com.squareup.okhttp3 mockwebserver - 3.12.1 + 3.13.1 test @@ -107,7 +107,7 @@ com.puppycrawl.tools checkstyle - 8.16 + 8.17 diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 46e58e129..5b7c743f2 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.6.0 + 2.7.0 com.github.scribejava diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 5b6ffd268..3c59ef366 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -8,7 +8,7 @@ 6.2.1-SNAPSHOT ../pom.xml - + com.github.scribejava scribejava-httpclient-apache ScribeJava Apache HttpComponents HttpClient support @@ -23,7 +23,7 @@ org.apache.httpcomponents httpclient - 4.5.6 + 4.5.7 org.apache.httpcomponents diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 956c762da..0c2ed23f1 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 3.12.1 + 3.13.1 com.github.scribejava From 584080faf09ecf801568e77285e8e821ac0a0179 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 6 Feb 2019 15:45:11 +0300 Subject: [PATCH 153/481] remove any Google+ mention (switch to clean Google OAuth2) (thanks to https://github.com/fvasco) --- changelog | 1 + .../scribejava/apis/examples/Google20AsyncAHCExample.java | 4 ++-- .../com/github/scribejava/apis/examples/Google20Example.java | 4 ++-- .../scribejava/apis/examples/Google20RevokeExample.java | 4 ++-- .../scribejava/apis/examples/Google20WithPKCEExample.java | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/changelog b/changelog index fa676453f..2f417fc56 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * fix Muplipart request model and implement it for a jdk HTTP client (thanks to https://github.com/NTPape) + * remove any Google+ mention (switch to clean Google OAuth2) (thanks to https://github.com/fvasco) [6.2.0] * add new API Microsoft Azure Active Directory (Azure AD) 2.0 (thanks to https://github.com/rzukow and https://github.com/dgrudenic) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index d815edce3..d2d8260df 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -19,8 +19,8 @@ public class Google20AsyncAHCExample { - private static final String NETWORK_NAME = "G+ Async"; - private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; + private static final String NETWORK_NAME = "Google Async"; + private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/oauth2/v3/userinfo"; private Google20AsyncAHCExample() { } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 0cce9f250..8fe8a37d1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -16,8 +16,8 @@ public class Google20Example { - private static final String NETWORK_NAME = "G+"; - private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; + private static final String NETWORK_NAME = "Google"; + private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/oauth2/v3/userinfo"; private Google20Example() { } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java index f65b07c39..61f44501e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java @@ -16,8 +16,8 @@ public class Google20RevokeExample { - private static final String NETWORK_NAME = "G+"; - private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; + private static final String NETWORK_NAME = "Google"; + private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/oauth2/v3/userinfo"; private Google20RevokeExample() { } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java index 54a359291..6c8b3a66a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java @@ -17,8 +17,8 @@ public class Google20WithPKCEExample { - private static final String NETWORK_NAME = "G+"; - private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/plus/v1/people/me"; + private static final String NETWORK_NAME = "Google"; + private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/oauth2/v3/userinfo"; private Google20WithPKCEExample() { } From 7042b4c9c078abeca668a27bc25c0d5c03795e64 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 6 Feb 2019 16:25:22 +0300 Subject: [PATCH 154/481] add links to RFCs in the Readme and info about refreshing token support --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9d8162a93..5d782bdf7 100644 --- a/README.md +++ b/README.md @@ -42,12 +42,13 @@ ScribeJava support out-of-box several HTTP clients: ### Supports many flows and additional features - * RFC 6749 The OAuth 2.0 Authorization Framework, Authorization Code Authorization Grant [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java) - * RFC 6749 The OAuth 2.0 Authorization Framework, Client Credentials Authorization Grant [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java) - * RFC 6749 The OAuth 2.0 Authorization Framework, Resource Owner Password Credentials Authorization Grant - * RFC 6750 The OAuth 2.0 Authorization Framework: Bearer Token Usage - * RFC 7636 Proof Key for Code Exchange by OAuth Public Clients (PKCE) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) - * RFC 7009 OAuth 2.0 Token Revocation [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java) + * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Authorization Code Authorization Grant](https://tools.ietf.org/html/rfc6749#section-4.1) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java) + * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Client Credentials Authorization Grant](https://tools.ietf.org/html/rfc6749#section-4.4) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java) + * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Resource Owner Password Credentials Authorization Grant](https://tools.ietf.org/html/rfc6749#section-4.3) + * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Refreshing an Access Token](https://tools.ietf.org/html/rfc6749#section-6) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java#L77) + * [RFC 6750](https://tools.ietf.org/html/rfc6750) The OAuth 2.0 Authorization Framework: Bearer Token Usage + * [RFC 7636](https://tools.ietf.org/html/rfc7636) Proof Key for Code Exchange by OAuth Public Clients (PKCE) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) + * [RFC 7009](https://tools.ietf.org/html/rfc7009) OAuth 2.0 Token Revocation [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java) ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box From ea8e48d610b958759fb3f1866678a13d9e9745a0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 6 Feb 2019 17:54:02 +0300 Subject: [PATCH 155/481] fix Microsoft Azure AD v1.0 and v2.0 (thanks to https://github.com/kenpusney and https://github.com/oscararias) --- changelog | 1 + .../MicrosoftAzureActiveDirectory20Api.java | 22 +++++++- .../MicrosoftAzureActiveDirectoryApi.java | 35 +++++++++++- .../BaseMicrosoftAzureActiveDirectoryApi.java | 54 +++++-------------- 4 files changed, 69 insertions(+), 43 deletions(-) diff --git a/changelog b/changelog index 2f417fc56..240862f7e 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * fix Muplipart request model and implement it for a jdk HTTP client (thanks to https://github.com/NTPape) * remove any Google+ mention (switch to clean Google OAuth2) (thanks to https://github.com/fvasco) + * fix Microsoft Azure AD v1.0 and v2.0 (thanks to https://github.com/kenpusney and https://github.com/oscararias) [6.2.0] * add new API Microsoft Azure Active Directory (Azure AD) 2.0 (thanks to https://github.com/rzukow and https://github.com/dgrudenic) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectory20Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectory20Api.java index 71b0a005e..399cf54c9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectory20Api.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectory20Api.java @@ -1,6 +1,8 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.microsoftazureactivedirectory.BaseMicrosoftAzureActiveDirectoryApi; +import com.github.scribejava.apis.microsoftazureactivedirectory.MicrosoftAzureActiveDirectory20BearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; /** * Microsoft Azure Active Directory Api v 2.0 @@ -14,7 +16,11 @@ public class MicrosoftAzureActiveDirectory20Api extends BaseMicrosoftAzureActiveDirectoryApi { protected MicrosoftAzureActiveDirectory20Api() { - super(MicrosoftAzureActiveDirectoryVersion.V_2_0); + this(COMMON_TENANT); + } + + protected MicrosoftAzureActiveDirectory20Api(String tenant) { + super(tenant); } private static class InstanceHolder { @@ -25,4 +31,18 @@ private static class InstanceHolder { public static MicrosoftAzureActiveDirectory20Api instance() { return InstanceHolder.INSTANCE; } + + public static MicrosoftAzureActiveDirectory20Api custom(String tenant) { + return new MicrosoftAzureActiveDirectory20Api(tenant); + } + + @Override + public BearerSignature getBearerSignature() { + return MicrosoftAzureActiveDirectory20BearerSignature.instance(); + } + + @Override + protected String getEndpointVersionPath() { + return "/v2.0"; + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java index 31250be3f..9ab4aa291 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MicrosoftAzureActiveDirectoryApi.java @@ -1,6 +1,8 @@ package com.github.scribejava.apis; import com.github.scribejava.apis.microsoftazureactivedirectory.BaseMicrosoftAzureActiveDirectoryApi; +import com.github.scribejava.apis.microsoftazureactivedirectory.MicrosoftAzureActiveDirectoryBearerSignature; +import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; /** * Microsoft Azure Active Directory Api @@ -16,8 +18,15 @@ */ public class MicrosoftAzureActiveDirectoryApi extends BaseMicrosoftAzureActiveDirectoryApi { + private final String resource; + protected MicrosoftAzureActiveDirectoryApi() { - super(MicrosoftAzureActiveDirectoryVersion.V_1_0); + this(COMMON_TENANT, null); + } + + protected MicrosoftAzureActiveDirectoryApi(String tenant, String resource) { + super(tenant); + this.resource = resource; } private static class InstanceHolder { @@ -28,4 +37,28 @@ private static class InstanceHolder { public static MicrosoftAzureActiveDirectoryApi instance() { return InstanceHolder.INSTANCE; } + + public static MicrosoftAzureActiveDirectoryApi customTenant(String tenant) { + return new MicrosoftAzureActiveDirectoryApi(tenant, null); + } + + public static MicrosoftAzureActiveDirectoryApi customResource(String resource) { + return new MicrosoftAzureActiveDirectoryApi(COMMON_TENANT, resource); + } + + public static MicrosoftAzureActiveDirectoryApi custom(String tenant, String resource) { + return new MicrosoftAzureActiveDirectoryApi(tenant, resource); + } + + @Override + protected String getAuthorizationBaseUrl() { + final String authorizationBaseUrl = super.getAuthorizationBaseUrl(); + return resource == null || resource.isEmpty() ? authorizationBaseUrl + : authorizationBaseUrl + "?resource=" + resource; + } + + @Override + public BearerSignature getBearerSignature() { + return MicrosoftAzureActiveDirectoryBearerSignature.instance(); + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java index bc813e398..4eefb1d6f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java @@ -1,38 +1,33 @@ package com.github.scribejava.apis.microsoftazureactivedirectory; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; public abstract class BaseMicrosoftAzureActiveDirectoryApi extends DefaultApi20 { - private static final String MSFT_LOGIN_URL = "https://login.microsoftonline.com"; - private static final String SLASH = "/"; - private static final String COMMON = "common"; - private static final String TOKEN_URI = "oauth2/token"; - private final String resource; - private final BaseMicrosoftAzureActiveDirectoryBearerSignature bearerSignature; + protected static final String COMMON_TENANT = "common"; - protected BaseMicrosoftAzureActiveDirectoryApi(String resource, - BaseMicrosoftAzureActiveDirectoryBearerSignature bearerSignature) { - this.resource = resource; - this.bearerSignature = bearerSignature; + private static final String MSFT_LOGIN_URL = "https://login.microsoftonline.com/"; + private static final String TOKEN_URI = "/oauth2/token"; + private final String tenant; + + protected BaseMicrosoftAzureActiveDirectoryApi() { + this(COMMON_TENANT); } - protected BaseMicrosoftAzureActiveDirectoryApi(MicrosoftAzureActiveDirectoryVersion version) { - this.resource = version.getResource(); - this.bearerSignature = version.getBearerSignature(); + protected BaseMicrosoftAzureActiveDirectoryApi(String tenant) { + this.tenant = tenant == null || tenant.isEmpty() ? COMMON_TENANT : tenant; } @Override public String getAccessTokenEndpoint() { - return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + TOKEN_URI; + return MSFT_LOGIN_URL + tenant + TOKEN_URI; } @Override protected String getAuthorizationBaseUrl() { - return MSFT_LOGIN_URL + SLASH + COMMON + SLASH + "oauth2/authorize?resource=" + resource; + return MSFT_LOGIN_URL + tenant + getEndpointVersionPath() + "/oauth2/authorize"; } @Override @@ -40,30 +35,7 @@ public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } - @Override - public BearerSignature getBearerSignature() { - return bearerSignature; - } - - protected enum MicrosoftAzureActiveDirectoryVersion { - V_1_0("https://graph.windows.net", MicrosoftAzureActiveDirectoryBearerSignature.instance()), - V_2_0("https://graph.microsoft.com", MicrosoftAzureActiveDirectory20BearerSignature.instance()); - - private final String resource; - private final BaseMicrosoftAzureActiveDirectoryBearerSignature bearerSignature; - - MicrosoftAzureActiveDirectoryVersion(String resource, - BaseMicrosoftAzureActiveDirectoryBearerSignature bearerSignature) { - this.resource = resource; - this.bearerSignature = bearerSignature; - } - - protected String getResource() { - return resource; - } - - protected BaseMicrosoftAzureActiveDirectoryBearerSignature getBearerSignature() { - return bearerSignature; - } + protected String getEndpointVersionPath() { + return ""; } } From 1f024918d17e02331dc5a94ca5925a398834629d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 7 Feb 2019 12:10:52 +0300 Subject: [PATCH 156/481] typo fix for MicrosoftAzureActiveDirectoryApi --- .../BaseMicrosoftAzureActiveDirectoryApi.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java index 4eefb1d6f..5e4891164 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java @@ -9,7 +9,7 @@ public abstract class BaseMicrosoftAzureActiveDirectoryApi extends DefaultApi20 protected static final String COMMON_TENANT = "common"; private static final String MSFT_LOGIN_URL = "https://login.microsoftonline.com/"; - private static final String TOKEN_URI = "/oauth2/token"; + private static final String OAUTH_2 = "/oauth2"; private final String tenant; protected BaseMicrosoftAzureActiveDirectoryApi() { @@ -22,12 +22,12 @@ protected BaseMicrosoftAzureActiveDirectoryApi(String tenant) { @Override public String getAccessTokenEndpoint() { - return MSFT_LOGIN_URL + tenant + TOKEN_URI; + return MSFT_LOGIN_URL + tenant + OAUTH_2 + getEndpointVersionPath() + "/token"; } @Override protected String getAuthorizationBaseUrl() { - return MSFT_LOGIN_URL + tenant + getEndpointVersionPath() + "/oauth2/authorize"; + return MSFT_LOGIN_URL + tenant + OAUTH_2 + getEndpointVersionPath() + "/authorize"; } @Override From e2ecdac1b68940513b2004209ee453256fde1279 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 7 Feb 2019 13:51:46 +0300 Subject: [PATCH 157/481] add new API Asana (https://asana.com/) (thanks to https://github.com/joestazak) --- README.md | 2 +- changelog | 1 + .../com/github/scribejava/apis/Asana20.java | 33 ------------------- .../github/scribejava/apis/Asana20Api.java | 27 +++++++++++++++ .../apis/examples/AsanaExample.java | 9 ++--- 5 files changed, 32 insertions(+), 40 deletions(-) delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20Api.java diff --git a/README.md b/README.md index 5ee83f11c..d8c736e79 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ ScribeJava support out-of-box several HTTP clients: ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box -* Asana (https://app.asana.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java) +* Asana (https://asana.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java) * Automatic (https://www.automatic.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java) * AWeber (http://www.aweber.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java) * Box (https://www.box.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java) diff --git a/changelog b/changelog index 240862f7e..4918c596b 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * fix Muplipart request model and implement it for a jdk HTTP client (thanks to https://github.com/NTPape) * remove any Google+ mention (switch to clean Google OAuth2) (thanks to https://github.com/fvasco) * fix Microsoft Azure AD v1.0 and v2.0 (thanks to https://github.com/kenpusney and https://github.com/oscararias) + * add new API Asana (https://asana.com/) (thanks to https://github.com/joestazak) [6.2.0] * add new API Microsoft Azure Active Directory (Azure AD) 2.0 (thanks to https://github.com/rzukow and https://github.com/dgrudenic) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20.java deleted file mode 100644 index b46151a35..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; -import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; - -public class Asana20 extends DefaultApi20 { - protected Asana20() { - } - - private static class InstanceHolder { - private static final Asana20 INSTANCE = new Asana20(); - } - - public static Asana20 instance() { - return InstanceHolder.INSTANCE; - } - - @Override - public String getAccessTokenEndpoint() { - return "https://app.asana.com/-/oauth_token"; - } - - @Override - protected String getAuthorizationBaseUrl() { - return "https://app.asana.com/-/oauth_authorize"; - } - - @Override - public ClientAuthentication getClientAuthentication() { - return RequestBodyAuthenticationScheme.instance(); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20Api.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20Api.java new file mode 100644 index 000000000..5e769aab8 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/Asana20Api.java @@ -0,0 +1,27 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; + +public class Asana20Api extends DefaultApi20 { + + protected Asana20Api() { + } + + private static class InstanceHolder { + private static final Asana20Api INSTANCE = new Asana20Api(); + } + + public static Asana20Api instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://app.asana.com/-/oauth_token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://app.asana.com/-/oauth_authorize"; + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java index 9165fc1b8..3907bdc2b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java @@ -1,6 +1,6 @@ package com.github.scribejava.apis.examples; -import com.github.scribejava.apis.Asana20; +import com.github.scribejava.apis.Asana20Api; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; @@ -9,8 +9,6 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; import java.util.Random; import java.util.Scanner; import java.util.concurrent.ExecutionException; @@ -20,7 +18,6 @@ public class AsanaExample { private static final String PROTECTED_RESOURCE_URL = "https://app.asana.com/api/1.0/users/me"; private AsanaExample() { - } public static void main(String... args) throws IOException, InterruptedException, ExecutionException { @@ -30,7 +27,8 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .callback("https://localhost/") - .build(Asana20.instance()); + .state(secretState) + .build(Asana20Api.instance()); final Scanner in = new Scanner(System.in); // Obtain Auth URL @@ -81,5 +79,4 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } - } From 872af9aa4919900a94cf6e33774f2e081f15f89f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 7 Feb 2019 15:49:52 +0300 Subject: [PATCH 158/481] fix MicrosoftAzureActiveDirectory20Example (add MS permission to OAuth2 scope) --- .../apis/examples/MicrosoftAzureActiveDirectory20Example.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java index c0bd6f88a..9a8ac4f1e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java @@ -25,7 +25,7 @@ public static void main(String... args) throws IOException, InterruptedException final String clientSecret = "client secret here"; final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .scope("openid") + .scope("openid User.Read") .callback("http://www.example.com/oauth_callback/") .build(MicrosoftAzureActiveDirectory20Api.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); From 784bb6e1e571482e5fc8854fc1cf1980408554cc Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 8 Feb 2019 14:04:33 +0300 Subject: [PATCH 159/481] state param should be used only for authorization url generation, for v2 only, for Authorization Code Grant only, and it should be set per request, not per created OAuthService --- README.md | 10 +-- changelog | 2 + .../github/scribejava/apis/FacebookApi.java | 23 ++++++ .../com/github/scribejava/apis/ImgurApi.java | 23 ++++++ .../com/github/scribejava/apis/MailruApi.java | 23 ++++++ .../scribejava/apis/OdnoklassnikiApi.java | 23 ++++++ .../github/scribejava/apis/WunderlistAPI.java | 23 ++++++ .../apis/facebook/FacebookService.java | 19 +++++ .../apis/imgur/ImgurOAuthService.java | 19 +++++ .../apis/mailru/MailruOAuthService.java | 19 +++++ .../OdnoklassnikiOAuthService.java | 19 +++++ .../wunderlist/WunderlistOAuthService.java | 19 +++++ .../apis/examples/AsanaExample.java | 3 +- .../apis/examples/AutomaticExample.java | 3 +- .../apis/examples/Box20Example.java | 3 +- .../apis/examples/DataportenExample.java | 3 +- .../apis/examples/DiscordExample.java | 3 +- .../examples/FacebookAsyncApacheExample.java | 3 +- .../examples/FacebookAsyncNingExample.java | 3 +- .../apis/examples/FacebookExample.java | 3 +- .../apis/examples/FitbitApi20Example.java | 3 +- .../apis/examples/GeniusExample.java | 3 +- .../examples/GitHubAsyncOkHttpExample.java | 3 +- .../apis/examples/GitHubExample.java | 3 +- .../examples/Google20AsyncAHCExample.java | 6 +- .../apis/examples/Google20Example.java | 3 +- .../apis/examples/Google20RevokeExample.java | 3 +- .../examples/Google20WithPKCEExample.java | 4 +- .../apis/examples/HiOrgServerExample.java | 3 +- .../apis/examples/LinkedIn20Example.java | 3 +- .../apis/examples/NaverExample.java | 3 +- .../apis/examples/StackExchangeExample.java | 3 +- .../TheThingsNetworkV1StagingExample.java | 3 +- .../TheThingsNetworkV2PreviewExample.java | 3 +- .../apis/examples/WunderlistExample.java | 3 +- .../core/builder/ServiceBuilder.java | 10 ++- .../scribejava/core/builder/api/BaseApi.java | 18 +++++ .../core/builder/api/DefaultApi10a.java | 25 +++++++ .../core/builder/api/DefaultApi20.java | 23 ++++++ .../scribejava/core/oauth/OAuth20Service.java | 73 +++++++++++++++++-- .../scribejava/core/AbstractClientTest.java | 3 +- .../scribejava/core/oauth/OAuth20ApiUnit.java | 6 +- .../core/oauth/OAuth20ServiceTest.java | 2 - .../core/oauth/OAuth20ServiceUnit.java | 4 +- 44 files changed, 388 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index d8c736e79..360a8411d 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ ScribeJava support out-of-box several HTTP clients: ### Supports many flows and additional features - * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Authorization Code Authorization Grant](https://tools.ietf.org/html/rfc6749#section-4.1) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java) - * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Client Credentials Authorization Grant](https://tools.ietf.org/html/rfc6749#section-4.4) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java) + * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Authorization Code Authorization Grant](https://tools.ietf.org/html/rfc6749#section-4.1), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java) * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Resource Owner Password Credentials Authorization Grant](https://tools.ietf.org/html/rfc6749#section-4.3) - * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Refreshing an Access Token](https://tools.ietf.org/html/rfc6749#section-6) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java#L77) + * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Client Credentials Authorization Grant](https://tools.ietf.org/html/rfc6749#section-4.4), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java) + * [RFC 6749](https://tools.ietf.org/html/rfc6749) The OAuth 2.0 Authorization Framework, [Refreshing an Access Token](https://tools.ietf.org/html/rfc6749#section-6), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java#L77) * [RFC 6750](https://tools.ietf.org/html/rfc6750) The OAuth 2.0 Authorization Framework: Bearer Token Usage - * [RFC 7636](https://tools.ietf.org/html/rfc7636) Proof Key for Code Exchange by OAuth Public Clients (PKCE) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) - * [RFC 7009](https://tools.ietf.org/html/rfc7009) OAuth 2.0 Token Revocation [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java) + * [RFC 7636](https://tools.ietf.org/html/rfc7636) Proof Key for Code Exchange by OAuth Public Clients (PKCE), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) + * [RFC 7009](https://tools.ietf.org/html/rfc7009) OAuth 2.0 Token Revocation, [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java) ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box diff --git a/changelog b/changelog index 4918c596b..03ba4e7ad 100644 --- a/changelog +++ b/changelog @@ -3,6 +3,8 @@ * remove any Google+ mention (switch to clean Google OAuth2) (thanks to https://github.com/fvasco) * fix Microsoft Azure AD v1.0 and v2.0 (thanks to https://github.com/kenpusney and https://github.com/oscararias) * add new API Asana (https://asana.com/) (thanks to https://github.com/joestazak) + * state param should be used only for authorization url generation, for v2 only, for Authorization Code Grant only, + and it should be set per request, not per created OAuthService [6.2.0] * add new API Microsoft Azure Active Directory (Azure AD) 2.0 (thanks to https://github.com/rzukow and https://github.com/dgrudenic) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index 6418d8964..da1acce63 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -70,6 +70,21 @@ public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param debugStream debugStream + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return return + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated @Override public FacebookService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, @@ -77,4 +92,12 @@ public FacebookService createService(String apiKey, String apiSecret, String cal return new FacebookService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } + + @Override + public FacebookService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, + httpClientConfig, httpClient); + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index f04736880..59d7e3e8d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -54,6 +54,21 @@ protected String getAuthorizationBaseUrl() { throw new UnsupportedOperationException("use getAuthorizationUrl instead"); } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param debugStream debugStream + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return return + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated @Override public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, @@ -62,6 +77,14 @@ public ImgurOAuthService createService(String apiKey, String apiSecret, String c httpClientConfig, httpClient); } + @Override + public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, + httpClientConfig, httpClient); + } + public static boolean isOob(String callback) { return OAuthConstants.OOB.equals(callback); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index 3835fff49..83419dace 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -29,6 +29,21 @@ protected String getAuthorizationBaseUrl() { return "https://connect.mail.ru/oauth/authorize"; } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param debugStream debugStream + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return return + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated @Override public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, @@ -36,4 +51,12 @@ public MailruOAuthService createService(String apiKey, String apiSecret, String return new MailruOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } + + @Override + public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, + httpClientConfig, httpClient); + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index f0d873b71..2e47b007c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -33,6 +33,21 @@ protected String getAuthorizationBaseUrl() { return "https://connect.ok.ru/oauth/authorize"; } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param debugStream debugStream + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return return + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated @Override public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, @@ -41,6 +56,14 @@ public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, httpClientConfig, httpClient); } + @Override + public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, + httpClientConfig, httpClient); + } + @Override public BearerSignature getBearerSignature() { return BearerSignatureURIQueryParameter.instance(); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java index e8eb92111..1c6b18e74 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java @@ -48,6 +48,29 @@ public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } + @Override + public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, + httpClientConfig, httpClient); + } + + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param debugStream debugStream + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return return + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated @Override public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java index 6aa4419e1..97354456e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java @@ -13,12 +13,31 @@ public class FacebookService extends OAuth20Service { + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } + public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); + } + @Override public void signRequest(String accessToken, OAuthRequest request) { super.signRequest(accessToken, request); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java index b1c934a9a..f05abfbbf 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java @@ -10,12 +10,31 @@ public class ImgurOAuthService extends OAuth20Service { + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } + public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); + } + @Override protected OAuthRequest createAccessTokenRequest(String oauthVerifier) { final DefaultApi20 api = getApi(); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java index f17a922a1..99955bf64 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java @@ -16,12 +16,31 @@ public class MailruOAuthService extends OAuth20Service { + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } + public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); + } + @Override public void signRequest(String accessToken, OAuthRequest request) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java index 16a9f10a5..d0901f533 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java @@ -19,12 +19,31 @@ public class OdnoklassnikiOAuthService extends OAuth20Service { + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } + public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); + } + @Override public void signRequest(String accessToken, OAuthRequest request) { //sig = lower(md5( sorted_request_params_composed_string + md5(access_token + application_secret_key))) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java index e5a5b07a7..66766d7e2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java @@ -8,12 +8,31 @@ public class WunderlistOAuthService extends OAuth20Service { + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); } + public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, String scope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); + } + @Override public void signRequest(String accessToken, OAuthRequest request) { super.signRequest(accessToken, request); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java index 3907bdc2b..c851a9e22 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java @@ -27,14 +27,13 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .callback("https://localhost/") - .state(secretState) .build(Asana20Api.instance()); final Scanner in = new Scanner(System.in); // Obtain Auth URL System.out.println("Fetching the Authorication URL..."); System.out.println("Got the Authorization URL!"); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); System.out.println("And paste the authorization code here"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java index 665a5552f..ed7ccd7ec 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java @@ -28,7 +28,6 @@ public static void main(String... args) throws IOException, InterruptedException final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback("http://www.example.com/oauth_callback/") .scope("scope:user:profile").debug() .build(AutomaticAPI.instance()); @@ -39,7 +38,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index 7f82c9222..4931f097b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -29,7 +29,6 @@ public static void main(String... args) throws IOException, InterruptedException final String secretState = "security_token" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback("https://example.com/callback") .build(BoxApi20.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); @@ -44,7 +43,7 @@ public static void main(String... args) throws IOException, InterruptedException additionalParams.put("access_type", "offline"); //force to reget refresh token (if usera are asked not the first time) additionalParams.put("prompt", "consent"); - final String authorizationUrl = service.getAuthorizationUrl(additionalParams); + final String authorizationUrl = service.getAuthorizationUrl(secretState, additionalParams); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java index fc0f4d3e2..c24a596fb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java @@ -27,7 +27,6 @@ public static void main(String... args) throws IOException, InterruptedException final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback("http://www.example.com/oauth_callback/") .build(DataportenApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); @@ -37,7 +36,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java index 41c5be42b..70714a16c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java @@ -29,7 +29,6 @@ public static void main(String... args) throws IOException, ExecutionException, final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("identify") // replace with desired scope - .state(secretState) .callback("http://example.com/callback") .userAgent("ScribeJava") .build(DiscordApi.instance()); @@ -40,7 +39,7 @@ public static void main(String... args) throws IOException, ExecutionException, // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java index bf7c6f2ee..c98c00eba 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java @@ -29,7 +29,6 @@ public static void main(String... args) throws InterruptedException, ExecutionEx try (OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback("http://www.example.com/oauth_callback/") .httpClientConfig(ApacheHttpClientConfig.defaultConfig()) .build(FacebookApi.instance())) { @@ -40,7 +39,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index 81d1dd53a..1d7e38576 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -37,7 +37,6 @@ public static void main(String... args) throws InterruptedException, ExecutionEx try (OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback("http://www.example.com/oauth_callback/") .httpClientConfig(clientConfig) .build(FacebookApi.instance())) { @@ -48,7 +47,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index 7a0ba726a..071a979a3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -27,7 +27,6 @@ public static void main(String... args) throws IOException, InterruptedException final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback("http://www.example.com/oauth_callback/") .build(FacebookApi.instance()); @@ -38,7 +37,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java index 9c17e9054..955c1289f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java @@ -30,7 +30,6 @@ public static void main(String... args) throws Exception { .scope("activity profile") // replace with desired scope //your callback URL to store and handle the authorization code sent by Fitbit .callback("http://www.example.com/oauth_callback/") - .state("some_params") .build(FitbitApi20.instance()); final Scanner in = new Scanner(System.in); @@ -39,7 +38,7 @@ public static void main(String... args) throws Exception { // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl("some_params"); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java index 8f269657e..d6726c2d1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java @@ -28,7 +28,6 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("me") - .state(secretState) .callback("com.scribejavatest://callback") .userAgent("ScribeJava") .build(GeniusApi.instance()); @@ -38,7 +37,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java index bc05042bf..eb4f5ee2e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java @@ -29,7 +29,6 @@ public static void main(String... args) throws IOException, ExecutionException, final String secretState = "secret" + new Random().nextInt(999_999); try (OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback("http://www.example.com/oauth_callback/") .httpClientConfig(OkHttpHttpClientConfig.defaultConfig()) .build(GitHubApi.instance())) { @@ -40,7 +39,7 @@ public static void main(String... args) throws IOException, ExecutionException, // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index 6d60957a3..d48d7abfd 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -27,7 +27,6 @@ public static void main(String... args) throws IOException, InterruptedException final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback("http://www.example.com/oauth_callback/") .build(GitHubApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); @@ -37,7 +36,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index d2d8260df..4bf0522c5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -40,9 +40,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx try (OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("profile") // replace with desired scope - .state(secretState) - .callback("http://example.com/callback") - .httpClientConfig(clientConfig) + .callback("http://example.com/callback") .httpClientConfig(clientConfig) .build(GoogleApi20.instance())) { final Scanner in = new Scanner(System.in, "UTF-8"); @@ -57,7 +55,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx additionalParams.put("access_type", "offline"); //force to reget refresh token (if usera are asked not the first time) additionalParams.put("prompt", "consent"); - final String authorizationUrl = service.getAuthorizationUrl(additionalParams); + final String authorizationUrl = service.getAuthorizationUrl(secretState, additionalParams); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 8fe8a37d1..de7e2e041 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -30,7 +30,6 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("profile") // replace with desired scope - .state(secretState) .callback("http://example.com/callback") .build(GoogleApi20.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); @@ -46,7 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException additionalParams.put("access_type", "offline"); //force to reget refresh token (if usera are asked not the first time) additionalParams.put("prompt", "consent"); - final String authorizationUrl = service.getAuthorizationUrl(additionalParams); + final String authorizationUrl = service.getAuthorizationUrl(secretState, additionalParams); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java index 61f44501e..f44a972a2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java @@ -30,7 +30,6 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("profile") // replace with desired scope - .state(secretState) .callback("http://example.com/callback") .build(GoogleApi20.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); @@ -46,7 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException additionalParams.put("access_type", "offline"); //force to reget refresh token (if usera are asked not the first time) additionalParams.put("prompt", "consent"); - final String authorizationUrl = service.getAuthorizationUrl(additionalParams); + final String authorizationUrl = service.getAuthorizationUrl(secretState, additionalParams); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java index 6c8b3a66a..377d52e6a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java @@ -31,7 +31,6 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("profile") // replace with desired scope - .state(secretState) .callback("http://example.com/callback") .build(GoogleApi20.instance()); @@ -49,7 +48,8 @@ public static void main(String... args) throws IOException, InterruptedException //force to reget refresh token (if usera are asked not the first time) additionalParams.put("prompt", "consent"); - final AuthorizationUrlWithPKCE authUrlWithPKCE = service.getAuthorizationUrlWithPKCE(additionalParams); + final AuthorizationUrlWithPKCE authUrlWithPKCE + = service.getAuthorizationUrlWithPKCE(secretState, additionalParams); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java index 6055af753..5ab81d8bc 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java @@ -31,7 +31,6 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("basic eigenedaten") - .state(secretState) .callback(CALLBACK_URL) .build(HiOrgServerApi20.instance()); @@ -42,7 +41,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java index d76acb856..825cf1ac2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java @@ -27,7 +27,6 @@ public static void main(String... args) throws IOException, InterruptedException .apiSecret(clientSecret) .scope("r_basicprofile r_emailaddress") // replace with desired scope .callback("http://example.com/callback") - .state("some_params") .build(LinkedInApi20.instance()); final Scanner in = new Scanner(System.in); @@ -36,7 +35,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl("some_params"); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java index bf359c547..ec3e79db8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java @@ -28,7 +28,6 @@ public static void main(String... args) throws IOException, InterruptedException final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback("http://www.example.com/oauth_callback/") .build(NaverApi.instance()); @@ -39,7 +38,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index 39350cd14..e179799e4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -32,7 +32,6 @@ public static void main(String... args) throws IOException, InterruptedException final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback("http://www.example.com/oauth_callback/") .build(StackExchangeApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); @@ -42,7 +41,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java index 427b83f2c..6c88f7434 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java @@ -31,7 +31,6 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback(redirectURI) .build(TheThingsNetworkV1StagingApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); @@ -41,7 +40,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java index 19cc96331..57aacac05 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java @@ -31,7 +31,6 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .state(secretState) .callback(redirectURI) .build(TheThingsNetworkV2PreviewApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); @@ -41,7 +40,7 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java index 91bb5f523..630df1c47 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java @@ -31,7 +31,6 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .callback(callbackUrl) - .state(secretState) .debug() .build(WunderlistAPI.instance()); @@ -41,7 +40,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index 8c70c4319..afcb8a347 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -3,6 +3,7 @@ import com.github.scribejava.core.builder.api.BaseApi; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.core.utils.Preconditions; @@ -78,11 +79,14 @@ public ServiceBuilder scope(String scope) { } /** + * /** * Configures the anti forgery session state. This is available in some APIs (like Google's). * * @param state The OAuth state * @return the {@link ServiceBuilder} instance for method chaining + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} */ + @Deprecated public ServiceBuilder state(String state) { Preconditions.checkEmptyString(state, "Invalid OAuth state"); this.state = state; @@ -136,7 +140,11 @@ public ServiceBuilder debug() { * @return fully configured {@link OAuthService} */ public S build(BaseApi api) { - return api.createService(apiKey, apiSecret, callback, scope, debugStream, state, responseType, userAgent, + final S service = api.createService(apiKey, apiSecret, callback, scope, debugStream, responseType, userAgent, httpClientConfig, httpClient); + if (service instanceof OAuth20Service) { + ((OAuth20Service) service).setState(state); + } + return service; } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java index bce6192dc..2ba40e7e1 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java @@ -7,7 +7,25 @@ public interface BaseApi { + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param debugStream debugStream + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return return + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated T createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient); + + T createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index 67bbd181e..315ab9470 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -143,6 +143,23 @@ public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return parameters.appendTo(getAuthorizationBaseUrl()); } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param debugStream debugStream + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return return + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override public OAuth10aService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, @@ -151,6 +168,14 @@ public OAuth10aService createService(String apiKey, String apiSecret, String cal httpClient); } + @Override + public OAuth10aService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, + httpClientConfig, httpClient); + } + /** * http://tools.ietf.org/html/rfc5849 says that "The client MAY omit the empty "oauth_token" protocol parameter from * the request", but not all oauth servers are good boys. diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index d12f4844c..64d64cba1 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -106,6 +106,29 @@ public String getAuthorizationUrl(String responseType, String apiKey, String cal return parameters.appendTo(getAuthorizationBaseUrl()); } + @Override + public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, + httpClientConfig, httpClient); + } + + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param debugStream debugStream + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return return + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated @Override public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String state, String responseType, String userAgent, diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index f7564ff1d..d3fe22912 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -27,14 +27,33 @@ public class OAuth20Service extends OAuthService { private static final PKCEService PKCE_SERVICE = new PKCEService(); private final DefaultApi20 api; private final String responseType; - private final String state; + private String state; + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param state state + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + this(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); + this.state = state; + } + + public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(apiKey, apiSecret, callback, scope, userAgent, httpClientConfig, httpClient); this.responseType = responseType; - this.state = state; this.api = api; } @@ -262,12 +281,20 @@ public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { } public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE() { - return getAuthorizationUrlWithPKCE(null); + return getAuthorizationUrlWithPKCE(getState()); + } + + public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state) { + return getAuthorizationUrlWithPKCE(state, null); } public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(Map additionalParams) { + return getAuthorizationUrlWithPKCE(getState(), additionalParams); + } + + public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state, Map additionalParams) { final PKCE pkce = PKCE_SERVICE.generatePKCE(); - return new AuthorizationUrlWithPKCE(pkce, getAuthorizationUrl(additionalParams, pkce)); + return new AuthorizationUrlWithPKCE(pkce, getAuthorizationUrl(state, additionalParams, pkce)); } /** @@ -276,7 +303,11 @@ public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(Map * @return the URL where you should redirect your users */ public String getAuthorizationUrl() { - return getAuthorizationUrl(null, null); + return getAuthorizationUrl(getState()); + } + + public String getAuthorizationUrl(String state) { + return getAuthorizationUrl(state, null, null); } /** @@ -286,14 +317,26 @@ public String getAuthorizationUrl() { * @return the URL where you should redirect your users */ public String getAuthorizationUrl(Map additionalParams) { - return getAuthorizationUrl(additionalParams, null); + return getAuthorizationUrl(getState(), additionalParams); + } + + public String getAuthorizationUrl(String state, Map additionalParams) { + return getAuthorizationUrl(state, additionalParams, null); } public String getAuthorizationUrl(PKCE pkce) { - return getAuthorizationUrl(null, pkce); + return getAuthorizationUrl(getState(), pkce); + } + + public String getAuthorizationUrl(String state, PKCE pkce) { + return getAuthorizationUrl(state, null, pkce); } public String getAuthorizationUrl(Map additionalParams, PKCE pkce) { + return getAuthorizationUrl(getState(), additionalParams, pkce); + } + + public String getAuthorizationUrl(String state, Map additionalParams, PKCE pkce) { final Map params; if (pkce == null) { params = additionalParams; @@ -301,7 +344,7 @@ public String getAuthorizationUrl(Map additionalParams, PKCE pkc params = additionalParams == null ? new HashMap() : new HashMap<>(additionalParams); params.putAll(pkce.getAuthorizationUrlParams()); } - return api.getAuthorizationUrl(getResponseType(), getApiKey(), getCallback(), getScope(), getState(), params); + return api.getAuthorizationUrl(getResponseType(), getApiKey(), getCallback(), getScope(), state, params); } public DefaultApi20 getApi() { @@ -389,7 +432,21 @@ public String getResponseType() { return responseType; } + /** + * @return state + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated public String getState() { return state; } + + /** + * @param state state + * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} + */ + @Deprecated + public void setState(String state) { + this.state = state; + } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java index 58c4664de..ac4705974 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java @@ -44,8 +44,7 @@ public Response getResponse() { @Before public void setUp() { - oAuthService = new OAuth20Service(null, "test", "test", null, null, null, null, null, null, - createNewClient()); + oAuthService = new OAuth20Service(null, "test", "test", null, null, null, null, null, createNewClient()); } @After diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java index 8d7777f86..141be05d5 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java @@ -21,9 +21,9 @@ protected String getAuthorizationBaseUrl() { @Override public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OAuth20ServiceUnit(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, + OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return new OAuth20ServiceUnit(this, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java index c74e0ea57..1f1983092 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java @@ -34,7 +34,6 @@ public void shouldProduceCorrectRequestSync() throws IOException, InterruptedExc final Map map = json.fromJson(token.getRawResponse(), new TypeTokenImpl().getType()); assertEquals(OAuth20ServiceUnit.TOKEN, map.get(OAuthConstants.ACCESS_TOKEN)); - assertEquals(OAuth20ServiceUnit.STATE, map.get(OAuthConstants.STATE)); assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); final String authorize = base64Encoder.encodeToString( @@ -61,7 +60,6 @@ public void shouldProduceCorrectRequestAsync() throws ExecutionException, Interr final Map map = json.fromJson(token.getRawResponse(), new TypeTokenImpl().getType()); assertEquals(OAuth20ServiceUnit.TOKEN, map.get(OAuthConstants.ACCESS_TOKEN)); - assertEquals(OAuth20ServiceUnit.STATE, map.get(OAuthConstants.STATE)); assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); final String authorize = base64Encoder.encodeToString( diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index a5cbf9763..0bcc766ad 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -20,9 +20,9 @@ class OAuth20ServiceUnit extends OAuth20Service { static final String STATE = "123"; static final String EXPIRES = "3600"; - OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String state, + OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); + super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); } @Override From 0508595e87f4b30e26e6a952213837a0749b0c99 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 8 Feb 2019 14:11:13 +0300 Subject: [PATCH 160/481] formatting typo --- .../scribejava/apis/examples/Google20AsyncAHCExample.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index 4bf0522c5..3c20eb9bf 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -40,7 +40,8 @@ public static void main(String... args) throws InterruptedException, ExecutionEx try (OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .scope("profile") // replace with desired scope - .callback("http://example.com/callback") .httpClientConfig(clientConfig) + .callback("http://example.com/callback") + .httpClientConfig(clientConfig) .build(GoogleApi20.instance())) { final Scanner in = new Scanner(System.in, "UTF-8"); From 0d33279f3497f0e2e13abb5f2696e1b652a2c9e8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 8 Feb 2019 14:24:22 +0300 Subject: [PATCH 161/481] prepare v6.3.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 360a8411d..e0e5cc2dd 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.2.0 + 6.3.0 ``` @@ -137,7 +137,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.2.0 + 6.3.0 ``` diff --git a/changelog b/changelog index 03ba4e7ad..89a311974 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.3.0] * fix Muplipart request model and implement it for a jdk HTTP client (thanks to https://github.com/NTPape) * remove any Google+ mention (switch to clean Google OAuth2) (thanks to https://github.com/fvasco) * fix Microsoft Azure AD v1.0 and v2.0 (thanks to https://github.com/kenpusney and https://github.com/oscararias) From ba0aa3d05c9041d3902aadd1bdfba4b31f6beac2 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 8 Feb 2019 14:26:08 +0300 Subject: [PATCH 162/481] [maven-release-plugin] prepare release scribejava-6.3.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index c1d6db3fb..4daddcfe0 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.2.1-SNAPSHOT + 6.3.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.3.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 39202c69b..90732e5af 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.1-SNAPSHOT + 6.3.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 7da4f7cf5..854e714ea 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.1-SNAPSHOT + 6.3.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 5b7c743f2..4c02aaa24 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.1-SNAPSHOT + 6.3.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 3c59ef366..33b8c2de1 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.1-SNAPSHOT + 6.3.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 7b43aaf1b..218c7757c 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.1-SNAPSHOT + 6.3.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 0c2ed23f1..b2164ad3e 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.2.1-SNAPSHOT + 6.3.0 ../pom.xml From 8b5dca9f91bdd09a857ef1e8b00d6e33fef5cf40 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 8 Feb 2019 14:26:19 +0300 Subject: [PATCH 163/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 4daddcfe0..b9c60a7cc 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.3.0 + 6.3.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.3.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 90732e5af..81ac6e17b 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.0 + 6.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 854e714ea..4252ba944 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.0 + 6.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 4c02aaa24..9c9f5c226 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.0 + 6.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 33b8c2de1..a01b769d9 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.0 + 6.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 218c7757c..33fb12bf8 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.0 + 6.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index b2164ad3e..bfc65c303 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.0 + 6.3.1-SNAPSHOT ../pom.xml From c270cefcfcd6105338c349fcd5429ce12996385b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 8 Feb 2019 15:23:00 +0300 Subject: [PATCH 164/481] cleanup deprecated methods --- .../github/scribejava/apis/FacebookApi.java | 27 +---- .../com/github/scribejava/apis/ImgurApi.java | 25 +---- .../com/github/scribejava/apis/MailruApi.java | 25 +---- .../scribejava/apis/OdnoklassnikiApi.java | 25 +---- .../github/scribejava/apis/WunderlistAPI.java | 25 +---- .../apis/facebook/FacebookService.java | 20 ---- .../apis/imgur/ImgurOAuthService.java | 20 ---- .../apis/mailru/MailruOAuthService.java | 21 ---- .../OdnoklassnikiOAuthService.java | 20 ---- .../wunderlist/WunderlistOAuthService.java | 20 ---- .../core/builder/ServiceBuilder.java | 23 +--- .../scribejava/core/builder/api/BaseApi.java | 19 ---- .../core/builder/api/DefaultApi10a.java | 29 +---- .../core/builder/api/DefaultApi20.java | 27 +---- .../AbstractAsyncOnlyHttpClient.java | 12 -- .../core/httpclient/BodyPartPayload.java | 69 ------------ .../core/httpclient/HttpClient.java | 39 ------- .../core/httpclient/MultipartPayload.java | 105 ------------------ .../core/httpclient/jdk/JDKHttpClient.java | 71 ------------ .../scribejava/core/model/OAuthRequest.java | 72 ------------ .../scribejava/core/oauth/OAuth20Service.java | 52 +-------- .../scribejava/core/oauth/OAuthService.java | 3 - .../httpclient/ahc/AhcHttpClient.java | 12 -- .../httpclient/apache/ApacheHttpClient.java | 12 -- .../httpclient/ning/NingHttpClient.java | 12 -- .../httpclient/okhttp/OkHttpHttpClient.java | 24 ---- 26 files changed, 17 insertions(+), 792 deletions(-) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index da1acce63..4b2df428e 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -70,34 +70,11 @@ public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param debugStream debugStream - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return return - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - @Override - public FacebookService createService(String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new FacebookService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, - httpClientConfig, httpClient); - } - @Override public FacebookService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, - httpClientConfig, httpClient); + return new FacebookService(this, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, + httpClient); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index 59d7e3e8d..3e2eddb50 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -54,34 +54,11 @@ protected String getAuthorizationBaseUrl() { throw new UnsupportedOperationException("use getAuthorizationUrl instead"); } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param debugStream debugStream - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return return - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - @Override - public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new ImgurOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, - httpClientConfig, httpClient); - } - @Override public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, + return new ImgurOAuthService(this, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index 83419dace..2235301ba 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -29,34 +29,11 @@ protected String getAuthorizationBaseUrl() { return "https://connect.mail.ru/oauth/authorize"; } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param debugStream debugStream - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return return - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - @Override - public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new MailruOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, - httpClientConfig, httpClient); - } - @Override public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, + return new MailruOAuthService(this, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index 2e47b007c..1d03bf1af 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -33,34 +33,11 @@ protected String getAuthorizationBaseUrl() { return "https://connect.ok.ru/oauth/authorize"; } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param debugStream debugStream - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return return - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - @Override - public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OdnoklassnikiOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, - httpClientConfig, httpClient); - } - @Override public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, + return new OdnoklassnikiOAuthService(this, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java index 1c6b18e74..6bdcfdf7c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java @@ -52,30 +52,7 @@ public ClientAuthentication getClientAuthentication() { public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, - httpClientConfig, httpClient); - } - - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param debugStream debugStream - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return return - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - @Override - public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new WunderlistOAuthService(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, + return new WunderlistOAuthService(this, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java index 97354456e..9ec9c0ceb 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java @@ -13,26 +13,6 @@ public class FacebookService extends OAuth20Service { - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java index f05abfbbf..4c8da3c82 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java @@ -10,26 +10,6 @@ public class ImgurOAuthService extends OAuth20Service { - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java index 99955bf64..37fcab964 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java @@ -16,32 +16,11 @@ public class MailruOAuthService extends OAuth20Service { - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); } - @Override public void signRequest(String accessToken, OAuthRequest request) { // sig = md5(params + secret_key) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java index d0901f533..f8cb1e3f5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java @@ -19,26 +19,6 @@ public class OdnoklassnikiOAuthService extends OAuth20Service { - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java index 66766d7e2..b46a0870f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java @@ -8,26 +8,6 @@ public class WunderlistOAuthService extends OAuth20Service { - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, state, responseType, userAgent, httpClientConfig, httpClient); - } - public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, String scope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index afcb8a347..254b46e5f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -3,7 +3,6 @@ import com.github.scribejava.core.builder.api.BaseApi; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.core.utils.Preconditions; @@ -18,7 +17,6 @@ public class ServiceBuilder { private String apiKey; private String apiSecret; private String scope; - private String state; private OutputStream debugStream; private String responseType = "code"; private String userAgent; @@ -78,21 +76,6 @@ public ServiceBuilder scope(String scope) { return this; } - /** - * /** - * Configures the anti forgery session state. This is available in some APIs (like Google's). - * - * @param state The OAuth state - * @return the {@link ServiceBuilder} instance for method chaining - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - public ServiceBuilder state(String state) { - Preconditions.checkEmptyString(state, "Invalid OAuth state"); - this.state = state; - return this; - } - public ServiceBuilder debugStream(OutputStream debugStream) { Preconditions.checkNotNull(debugStream, "debug stream can't be null"); this.debugStream = debugStream; @@ -140,11 +123,7 @@ public ServiceBuilder debug() { * @return fully configured {@link OAuthService} */ public S build(BaseApi api) { - final S service = api.createService(apiKey, apiSecret, callback, scope, debugStream, responseType, userAgent, + return api.createService(apiKey, apiSecret, callback, scope, debugStream, responseType, userAgent, httpClientConfig, httpClient); - if (service instanceof OAuth20Service) { - ((OAuth20Service) service).setState(state); - } - return service; } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java index 2ba40e7e1..0ce3377d6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java @@ -7,25 +7,6 @@ public interface BaseApi { - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param debugStream debugStream - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return return - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - T createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient); - T createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index 315ab9470..7ef8b572d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -143,37 +143,12 @@ public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return parameters.appendTo(getAuthorizationBaseUrl()); } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param debugStream debugStream - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return return - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public OAuth10aService createService(String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OAuth10aService(this, apiKey, apiSecret, callback, scope, debugStream, userAgent, httpClientConfig, - httpClient); - } - @Override public OAuth10aService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, - httpClientConfig, httpClient); + return new OAuth10aService(this, apiKey, apiSecret, callback, scope, debugStream, userAgent, httpClientConfig, + httpClient); } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 64d64cba1..e998cde81 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -110,31 +110,8 @@ public String getAuthorizationUrl(String responseType, String apiKey, String cal public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, scope, debugStream, null, responseType, userAgent, - httpClientConfig, httpClient); - } - - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param debugStream debugStream - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return return - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - @Override - public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String state, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OAuth20Service(this, apiKey, apiSecret, callback, scope, state, responseType, userAgent, - httpClientConfig, httpClient); + return new OAuth20Service(this, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, + httpClient); } public BearerSignature getBearerSignature() { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java index a54e51a58..48917eb60 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java @@ -18,18 +18,6 @@ public Response execute(String userAgent, Map headers, Verb http (OAuthRequest.ResponseConverter) null).get(); } - /** - * @deprecated {@inheritDoc} - */ - @Override - @Deprecated - public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, - MultipartPayload bodyContents) throws InterruptedException, ExecutionException, IOException { - - return executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, null, - (OAuthRequest.ResponseConverter) null).get(); - } - @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, com.github.scribejava.core.httpclient.multipart.MultipartPayload bodyContents) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java deleted file mode 100644 index 2b349d666..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/BodyPartPayload.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.github.scribejava.core.httpclient; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -/** - * @deprecated use {@link com.github.scribejava.core.httpclient.multipart.ByteArrayBodyPartPayload} - */ -@Deprecated -public class BodyPartPayload { - - private final Map headers; - private final byte[] payload; - - public BodyPartPayload(Map headers, byte[] payload) { - this.headers = headers; - this.payload = payload; - } - - public BodyPartPayload(String contentDisposition, String contentType, byte[] payload) { - this(createHeadersMap(contentDisposition, contentType), payload); - } - - public BodyPartPayload(String contentDisposition, byte[] payload) { - this(contentDisposition, null, payload); - } - - public Map getHeaders() { - return headers; - } - - /** - * @return return - * @deprecated use {@link #getHeaders() } and then get("Content-Disposition") - */ - @Deprecated - public String getContentDisposition() { - return headers.get("Content-Disposition"); - } - - /** - * @return return - * @deprecated use {@link #getHeaders() } and then get("Content-Type") - */ - @Deprecated - public String getContentType() { - return headers.get(HttpClient.CONTENT_TYPE); - } - - public byte[] getPayload() { - return payload; - } - - private static Map createHeadersMap(String contentDisposition, String contentType) { - if (contentDisposition == null && contentType == null) { - return Collections.emptyMap(); - } - - final Map headers = new HashMap<>(); - if (contentDisposition != null) { - headers.put("Content-Disposition", contentDisposition); - } - if (contentType != null) { - headers.put(HttpClient.CONTENT_TYPE, contentType); - } - return headers; - } -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java index 4217ac717..821c9b194 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/HttpClient.java @@ -21,27 +21,6 @@ public interface HttpClient extends Closeable { Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter); - /** - * @param T - * @param userAgent userAgent - * @param headers headers - * @param httpVerb httpVerb - * @param completeUrl completeUrl - * @param bodyContents bodyContents - * @param callback callback - * @param converter converter - * @return return - * - * @deprecated use {@link #executeAsync(java.lang.String, java.util.Map, com.github.scribejava.core.model.Verb, - * java.lang.String, com.github.scribejava.core.httpclient.multipart.MultipartPayload, - * com.github.scribejava.core.model.OAuthAsyncRequestCallback, - * com.github.scribejava.core.model.OAuthRequest.ResponseConverter)} - */ - @Deprecated - Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter); - Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter); @@ -55,24 +34,6 @@ Future executeAsync(String userAgent, Map headers, Verb h Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents) throws InterruptedException, ExecutionException, IOException; - /** - * @param userAgent userAgent - * @param headers headers - * @param httpVerb httpVerb - * @param completeUrl completeUrl - * @param bodyContents bodyContents - * @return return - * @throws InterruptedException InterruptedException - * @throws ExecutionException ExecutionException - * @throws IOException IOException - * @deprecated use {@link #execute(java.lang.String, java.util.Map, com.github.scribejava.core.model.Verb, - * java.lang.String, com.github.scribejava.core.httpclient.multipart.MultipartPayload)} - */ - @Deprecated - Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, - com.github.scribejava.core.httpclient.MultipartPayload bodyContents) - throws InterruptedException, ExecutionException, IOException; - Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents) throws InterruptedException, ExecutionException, IOException; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java deleted file mode 100644 index 3d4016ea1..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/MultipartPayload.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.github.scribejava.core.httpclient; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * The class containing more than one payload of multipart/form-data request - * - * @deprecated use {@link com.github.scribejava.core.httpclient.multipart.MultipartPayload} - */ -@Deprecated -public class MultipartPayload { - - private static final String DEFAULT_SUBTYPE = "form-data"; - - private final String boundary; - private final Map headers; - private final List bodyParts = new ArrayList<>(); - - public MultipartPayload(String boundary) { - this.boundary = boundary; - headers = Collections.singletonMap(HttpClient.CONTENT_TYPE, - "multipart/" + DEFAULT_SUBTYPE + "; boundary=\"" + boundary + '"'); - } - - /** - * @param bodyPart bodyPart - * @return return - * @deprecated no replace for that. implement yourself. See code here - * {@link com.github.scribejava.core.httpclient.jdk.JDKHttpClient - * #getPayload(com.github.scribejava.core.httpclient.MultipartPayload)} - */ - @Deprecated - public byte[] getStartBoundary(BodyPartPayload bodyPart) { - final StringBuilder startBoundary = new StringBuilder(); - startBoundary.append("\r\n--") - .append(boundary) - .append("\r\n"); - - for (Map.Entry header : bodyPart.getHeaders().entrySet()) { - startBoundary.append(header.getKey()) - .append(": ") - .append(header.getValue()) - .append("\r\n"); - } - return startBoundary.append("\r\n").toString().getBytes(); - } - - /** - * @return return - * @deprecated no replace for that. implement yourself. See code here - * {@link com.github.scribejava.core.httpclient.jdk.JDKHttpClient - * #getPayload(com.github.scribejava.core.httpclient.MultipartPayload)} - */ - @Deprecated - public byte[] getEndBoundary() { - return ("\r\n--" + boundary + "--\r\n").getBytes(); - } - - /** - * @return return - * @deprecated no replace for that. implement yourself. See code here - * {@link com.github.scribejava.core.httpclient.jdk.JDKHttpClient - * #getPayload(com.github.scribejava.core.httpclient.MultipartPayload)} - */ - @Deprecated - public int getContentLength() { - int contentLength = 0; - - for (BodyPartPayload bodyPart : bodyParts) { - contentLength += getStartBoundary(bodyPart).length + bodyPart.getPayload().length; - } - if (!bodyParts.isEmpty()) { - contentLength += getEndBoundary().length; - } - return contentLength; - } - - public List getBodyParts() { - return bodyParts; - } - - public void addMultipartPayload(String contentDisposition, String contentType, byte[] payload) { - bodyParts.add(new BodyPartPayload(contentDisposition, contentType, payload)); - } - - /** - * @return return - * @deprecated use {@link #getHeaders() } and then get("Content-Type") - */ - @Deprecated - public String getContentType() { - return headers.get(HttpClient.CONTENT_TYPE); - } - - public Map getHeaders() { - return headers; - } - - public String getBoundary() { - return boundary; - } -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index b13186603..ee459cf51 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -47,19 +47,6 @@ public Future executeAsync(String userAgent, Map headers, converter); } - /** - * @deprecated {@inheritDoc} - */ - @Override - @Deprecated - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodyType.OLD_MULTIPART, bodyContents, callback, - converter); - } - @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, @@ -114,17 +101,6 @@ public Response execute(String userAgent, Map headers, Verb http return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.MULTIPART, multipartPayloads); } - /** - * @deprecated {@inheritDoc} - */ - @Override - @Deprecated - public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, - com.github.scribejava.core.httpclient.MultipartPayload multipartPayloads) - throws InterruptedException, ExecutionException, IOException { - return doExecute(userAgent, headers, httpVerb, completeUrl, BodyType.OLD_MULTIPART, multipartPayloads); - } - @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents) throws InterruptedException, ExecutionException, IOException { @@ -171,13 +147,6 @@ void setBody(HttpURLConnection connection, Object bodyContents, boolean requires addBody(connection, (byte[]) bodyContents, requiresBody); } }, - OLD_MULTIPART { - @Override - void setBody(HttpURLConnection connection, Object bodyContents, boolean requiresBody) throws IOException { - addBody(connection, (com.github.scribejava.core.httpclient.MultipartPayload) bodyContents, - requiresBody); - } - }, MULTIPART { @Override void setBody(HttpURLConnection connection, Object bodyContents, boolean requiresBody) throws IOException { @@ -227,23 +196,6 @@ private static void addBody(HttpURLConnection connection, byte[] content, boolea } } - private static void addBody(HttpURLConnection connection, - com.github.scribejava.core.httpclient.MultipartPayload multipartPayload, boolean requiresBody) - throws IOException { - - for (Map.Entry header : multipartPayload.getHeaders().entrySet()) { - connection.setRequestProperty(header.getKey(), header.getValue()); - } - - if (requiresBody) { - final ByteArrayOutputStream os = getPayload(multipartPayload); - - if (os.size() > 0) { - os.writeTo(prepareConnectionForBodyAndGetOutputStream(connection, os.size())); - } - } - } - private static void addBody(HttpURLConnection connection, MultipartPayload multipartPayload, boolean requiresBody) throws IOException { @@ -260,29 +212,6 @@ private static void addBody(HttpURLConnection connection, MultipartPayload multi } } - private static ByteArrayOutputStream getPayload( - com.github.scribejava.core.httpclient.MultipartPayload multipartPayload) throws IOException { - final ByteArrayOutputStream os = new ByteArrayOutputStream(); - final List bodyParts = multipartPayload.getBodyParts(); - if (!bodyParts.isEmpty()) { - final String boundary = multipartPayload.getBoundary(); - final byte[] startBoundary = ("\r\n--" + boundary + "\r\n").getBytes(); - - for (com.github.scribejava.core.httpclient.BodyPartPayload bodyPart : bodyParts) { - os.write(startBoundary); - - for (Map.Entry header : bodyPart.getHeaders().entrySet()) { - os.write((header.getKey() + ": " + header.getValue() + "\r\n").getBytes()); - } - os.write("\r\n".getBytes()); - os.write(bodyPart.getPayload()); - } - - os.write(("\r\n--" + boundary + "--\r\n").getBytes()); - } - return os; - } - static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload) throws IOException { final ByteArrayOutputStream os = new ByteArrayOutputStream(); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index 606577fbb..ca6a32bf0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -31,7 +31,6 @@ public class OAuthRequest { private String stringPayload; private byte[] byteArrayPayload; private File filePayload; - private com.github.scribejava.core.httpclient.MultipartPayload oldMultipartPayload; private MultipartPayload multipartPayload; private final Map oauthParameters = new HashMap<>(); @@ -129,71 +128,10 @@ public void addParameter(String key, String value) { } } - /** - * @param boundary boundary - * @deprecated create {@link #initMultipartPayload(java.lang.String) } - */ - @Deprecated - public void initMultipartBoundary(String boundary) { - oldMultipartPayload = new com.github.scribejava.core.httpclient.MultipartPayload(boundary == null - ? Long.toString(System.currentTimeMillis()) - : boundary); - } - - /** - * @deprecated use {@link #initMultipartPayload()} - */ - @Deprecated - public void initMultipartBoundary() { - initMultipartBoundary(null); - } - - /** - * @param contentDisposition contentDisposition - * @param contentType contentType - * @param payload payload - * @deprecated use {@link #addFileByteArrayBodyPartPayloadInMultipartPayload(java.lang.String, byte[], - * java.lang.String, java.lang.String)} - */ - @Deprecated - public void addMultipartPayload(String contentDisposition, String contentType, byte[] payload) { - if (oldMultipartPayload == null) { - initMultipartBoundary(); - } - oldMultipartPayload.addMultipartPayload(contentDisposition, contentType, payload); - } - public MultipartPayload getMultipartPayload() { return multipartPayload; } - /** - * @param contentDisposition contentDisposition - * @param contentType contentType - * @param payload payload - * @deprecated use {@link #setFileByteArrayBodyPartPayloadInMultipartPayload(java.lang.String, byte[], - * java.lang.String, java.lang.String)} - */ - @Deprecated - public void setMultipartPayload(String contentDisposition, String contentType, byte[] payload) { - setMultipartPayload(null, contentDisposition, contentType, payload); - } - - /** - * @param boundary boundary - * @param contentDisposition contentDisposition - * @param contentType contentType - * @param payload payload - * @deprecated use {@link #initMultipartPayload(java.lang.String) } - * and then {@link #setFileByteArrayBodyPartPayloadInMultipartPayload(java.lang.String, byte[], java.lang.String, - * java.lang.String)} - */ - @Deprecated - public void setMultipartPayload(String boundary, String contentDisposition, String contentType, byte[] payload) { - initMultipartBoundary(boundary); - oldMultipartPayload.addMultipartPayload(contentDisposition, contentType, payload); - } - public void setMultipartPayload(MultipartPayload multipartPayload) { this.multipartPayload = multipartPayload; } @@ -351,7 +289,6 @@ private void resetPayload() { stringPayload = null; byteArrayPayload = null; filePayload = null; - oldMultipartPayload = null; multipartPayload = null; } @@ -431,15 +368,6 @@ public byte[] getByteArrayPayload() { } } - /** - * @return return - * @deprecated use {@link #getMultipartPayload() } - */ - @Deprecated - public com.github.scribejava.core.httpclient.MultipartPayload getMultipartPayloads() { - return oldMultipartPayload; - } - public File getFilePayload() { return filePayload; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index d3fe22912..9c2a1aef3 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -27,28 +27,6 @@ public class OAuth20Service extends OAuthService { private static final PKCEService PKCE_SERVICE = new PKCEService(); private final DefaultApi20 api; private final String responseType; - private String state; - - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param state state - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - String state, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); - this.state = state; - } public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { @@ -281,7 +259,7 @@ public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { } public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE() { - return getAuthorizationUrlWithPKCE(getState()); + return getAuthorizationUrlWithPKCE(null, null); } public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state) { @@ -289,7 +267,7 @@ public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state) { } public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(Map additionalParams) { - return getAuthorizationUrlWithPKCE(getState(), additionalParams); + return getAuthorizationUrlWithPKCE(null, additionalParams); } public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state, Map additionalParams) { @@ -303,7 +281,7 @@ public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state, Map additionalParams) { - return getAuthorizationUrl(getState(), additionalParams); + return getAuthorizationUrl(null, additionalParams); } public String getAuthorizationUrl(String state, Map additionalParams) { @@ -325,7 +303,7 @@ public String getAuthorizationUrl(String state, Map additionalPa } public String getAuthorizationUrl(PKCE pkce) { - return getAuthorizationUrl(getState(), pkce); + return getAuthorizationUrl(null, null, pkce); } public String getAuthorizationUrl(String state, PKCE pkce) { @@ -333,7 +311,7 @@ public String getAuthorizationUrl(String state, PKCE pkce) { } public String getAuthorizationUrl(Map additionalParams, PKCE pkce) { - return getAuthorizationUrl(getState(), additionalParams, pkce); + return getAuthorizationUrl(null, additionalParams, pkce); } public String getAuthorizationUrl(String state, Map additionalParams, PKCE pkce) { @@ -431,22 +409,4 @@ public OAuth2Authorization extractAuthorization(String redirectLocation) { public String getResponseType() { return responseType; } - - /** - * @return state - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - public String getState() { - return state; - } - - /** - * @param state state - * @deprecated use one of getAuthorizationUrl method in {@link com.github.scribejava.core.oauth.OAuth20Service} - */ - @Deprecated - public void setState(String state) { - this.state = state; - } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 94aaa4c38..cc9d7ad09 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -113,9 +113,6 @@ public Response execute(OAuthRequest request) throws InterruptedException, Execu } else if (request.getMultipartPayload() != null) { return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), request.getMultipartPayload()); - } else if (request.getMultipartPayloads() != null) { - return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), - request.getMultipartPayloads()); } else { return httpClient.execute(userAgent, request.getHeaders(), request.getVerb(), request.getCompleteUrl(), request.getByteArrayPayload()); diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java index 877d1e1f2..882293a43 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java @@ -48,18 +48,6 @@ public Future executeAsync(String userAgent, Map headers, converter); } - /** - * @deprecated {@inheritDoc} - */ - @Override - @Deprecated - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - - throw new UnsupportedOperationException("AhcHttpClient does not support MultipartPayload yet."); - } - @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java index 168376604..8c204e67b 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/ApacheHttpClient.java @@ -54,18 +54,6 @@ public Future executeAsync(String userAgent, Map headers, return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, entity, callback, converter); } - /** - * @deprecated {@inheritDoc} - */ - @Override - @Deprecated - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - - throw new UnsupportedOperationException("ApacheHttpClient does not support MultipartPayload yet."); - } - @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java index 6b065a4db..cc8c6fcda 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java @@ -54,18 +54,6 @@ public Future executeAsync(String userAgent, Map headers, converter); } - /** - * @deprecated {@inheritDoc} - */ - @Override - @Deprecated - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - - throw new UnsupportedOperationException("NingHttpClient does not support MultipartPayload yet."); - } - @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 18ae14b13..4f3e7e434 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -60,18 +60,6 @@ public Future executeAsync(String userAgent, Map headers, converter); } - /** - * @deprecated {@inheritDoc} - */ - @Override - @Deprecated - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - - throw new UnsupportedOperationException("OKHttpClient does not support Multipart payload for the moment"); - } - @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, @@ -119,18 +107,6 @@ public Response execute(String userAgent, Map headers, Verb http throw new UnsupportedOperationException("OKHttpClient does not support Multipart payload for the moment"); } - /** - * @deprecated {@inheritDoc} - */ - @Override - @Deprecated - public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, - com.github.scribejava.core.httpclient.MultipartPayload bodyContents) - throws InterruptedException, ExecutionException, IOException { - - throw new UnsupportedOperationException("OKHttpClient does not support Multipart payload for the moment"); - } - @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents) throws InterruptedException, ExecutionException, IOException { From 111cb9dfe9a865741e57ac6e7c75f75bee28e0c4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 18 Feb 2019 16:54:55 +0300 Subject: [PATCH 165/481] Create donate.md --- donate.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 donate.md diff --git a/donate.md b/donate.md new file mode 100644 index 000000000..634494bf1 --- /dev/null +++ b/donate.md @@ -0,0 +1 @@ +[![Donate with PayPal button](https://www.paypalobjects.com/en_US/RU/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=E3XAUM2ET2R3Y&source=url) From 9cadb25558fcca952e7efa40aa60009bcd5cc40f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 18 Feb 2019 17:36:14 +0300 Subject: [PATCH 166/481] Update donate.md --- donate.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/donate.md b/donate.md index 634494bf1..ccc9d44c6 100644 --- a/donate.md +++ b/donate.md @@ -1 +1,13 @@ -[![Donate with PayPal button](https://www.paypalobjects.com/en_US/RU/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=E3XAUM2ET2R3Y&source=url) +You can now help ScribeJava not only by Pull Requests. + +You can use [https://paypal.me/kullfar](https://paypal.me/kullfar) directly + +or try donation button from PayPal: [![Donate with PayPal button](https://www.paypalobjects.com/en_US/RU/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=E3XAUM2ET2R3Y&source=url) + +Thanks in advance! + +ps.If you can't for any reason to use above methods, let me know, we will find the way out. + +Hall of fame "Donors" (in alphabetical order, if you don't want to be here, just put a note along with the donation): +1.Be the first one! +2.Your name can be here. From 414e1f531682eb3f572e946c42b520179652a962 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 18 Feb 2019 17:37:10 +0300 Subject: [PATCH 167/481] Update donate.md --- donate.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/donate.md b/donate.md index ccc9d44c6..55a937059 100644 --- a/donate.md +++ b/donate.md @@ -8,6 +8,6 @@ Thanks in advance! ps.If you can't for any reason to use above methods, let me know, we will find the way out. -Hall of fame "Donors" (in alphabetical order, if you don't want to be here, just put a note along with the donation): -1.Be the first one! +Hall of fame "Donors" (in alphabetical order, if you don't want to be here, just put a note along with the donation):
    +1.Be the first one!
    2.Your name can be here. From 76c6e157054da0aaf342c17cb996a8b2f97cdbde Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 18 Feb 2019 17:38:42 +0300 Subject: [PATCH 168/481] Update donate.md --- donate.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/donate.md b/donate.md index 55a937059..01974ea63 100644 --- a/donate.md +++ b/donate.md @@ -6,7 +6,7 @@ or try donation button from PayPal: [![Donate with PayPal button](https://www.pa Thanks in advance! -ps.If you can't for any reason to use above methods, let me know, we will find the way out. +ps.If you can't for any reason use above methods, let me know, we will find the way out. Hall of fame "Donors" (in alphabetical order, if you don't want to be here, just put a note along with the donation):
    1.Be the first one!
    From b5933c898939df9b984ada761fe51d5a94de0e9e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 18 Feb 2019 17:42:37 +0300 Subject: [PATCH 169/481] Update README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e0e5cc2dd..35cff6c1f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Welcome to the home of ScribeJava, the simple OAuth client Java lib! -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.scribejava/scribejava/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.scribejava/scribejava) +[![Donate](https://www.paypalobjects.com/en_US/RU/i/btn/btn_donateCC_LG.gif)](https://github.com/scribejava/scribejava/blob/master/donate.md) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.scribejava/scribejava/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.scribejava/scribejava) # Why use ScribeJava? @@ -141,6 +141,10 @@ And in case you need just core classes (that's it, without any external API (FB,
    ``` +## How can I help ScribeJava + +First of all, Pull Requests are welcome, Second option is [donations](https://github.com/scribejava/scribejava/blob/master/donate.md). + ## Getting started in less than 2 minutes Check the [Getting Started](https://github.com/scribejava/scribejava/wiki/getting-started) page and start rocking! Please Read the [FAQ](https://github.com/scribejava/scribejava/wiki/faq) before creating an issue :) From 086c700824cf662801290a46656421facc4c5941 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 18 Feb 2019 17:43:37 +0300 Subject: [PATCH 170/481] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 35cff6c1f..b7b8838de 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ And in case you need just core classes (that's it, without any external API (FB, ## How can I help ScribeJava -First of all, Pull Requests are welcome, Second option is [donations](https://github.com/scribejava/scribejava/blob/master/donate.md). +First of all, Pull Requests are welcome, the second option is [donations](https://github.com/scribejava/scribejava/blob/master/donate.md). ## Getting started in less than 2 minutes From bfd7bf6651561c9a01a660f6cf2f4cd36a024658 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 18 Feb 2019 18:00:42 +0300 Subject: [PATCH 171/481] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b7b8838de..654d83dd8 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,8 @@ First of all, Pull Requests are welcome, the second option is [donations](https: Check the [Getting Started](https://github.com/scribejava/scribejava/wiki/getting-started) page and start rocking! Please Read the [FAQ](https://github.com/scribejava/scribejava/wiki/faq) before creating an issue :) +Some useful info and answers you can find on the [wiki](https://github.com/scribejava/scribejava/wiki) + Also, remember to read the [fantastic tutorial](http://akoskm.github.io/2015/07/31/twitter-sign-in-for-web-apps.html) that [@akoskm](https://twitter.com/akoskm) wrote to easily integrate a server side app with an API (twitter in this case). ## Questions? From dc6290b466444fbb821ad35855fe8114c750f976 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Feb 2019 12:50:39 +0300 Subject: [PATCH 172/481] Update donate.md --- donate.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/donate.md b/donate.md index 01974ea63..50f782838 100644 --- a/donate.md +++ b/donate.md @@ -9,5 +9,5 @@ Thanks in advance! ps.If you can't for any reason use above methods, let me know, we will find the way out. Hall of fame "Donors" (in alphabetical order, if you don't want to be here, just put a note along with the donation):
    -1.Be the first one!
    +1.Douglas Ross from USA
    2.Your name can be here. From bfc1cb4ccc950a200424930f6d92e7f68ba50b3c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Feb 2019 13:50:06 +0300 Subject: [PATCH 173/481] support TLS 1.3 in JDK 11 for Salesforce --- changelog | 3 ++ .../github/scribejava/apis/SalesforceApi.java | 35 +++++++------------ .../apis/examples/SalesforceExample.java | 2 +- .../examples/SalesforceNingAsyncExample.java | 2 +- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/changelog b/changelog index 89a311974..0e81fe569 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * support TLS 1.3 in JDK 11 for Salesforce + [6.3.0] * fix Muplipart request model and implement it for a jdk HTTP client (thanks to https://github.com/NTPape) * remove any Google+ mention (switch to clean Google OAuth2) (thanks to https://github.com/fvasco) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java index afd2eae5f..57cdd32ac 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java @@ -12,6 +12,7 @@ import java.io.IOException; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; +import java.util.Arrays; import javax.net.ssl.SSLSocket; /** @@ -84,7 +85,7 @@ public TokenExtractor getAccessTokenExtractor() { private static boolean isTLSv11orUpperEnabled(final SSLSocket socket) { for (String protocol : socket.getEnabledProtocols()) { - if ("TLSv1.2".equals(protocol) || "TLSv1.1".equals(protocol)) { + if (protocol.startsWith("TLSv1.")) { return true; } } @@ -97,7 +98,7 @@ private static boolean isTLSv11orUpperEnabled(final SSLSocket socket) { * Java 8 have TLS 1.2 enabled by default. java 7 - no, you should invoke this method or turn TLS>=1.1 somehow * else

    * - * @throws java.security.NoSuchAlgorithmException in case your jvm doesn't support TLSv1.1 and TLSv1.2 + * @throws java.security.NoSuchAlgorithmException in case your jvm doesn't support TLSv1.1 or higher * @throws java.security.KeyManagementException unexpected Exception from * {@link SSLContext#init(javax.net.ssl.KeyManager[], javax.net.ssl.TrustManager[], java.security.SecureRandom)} * @throws java.io.IOException unexpected Exception from {@link javax.net.ssl.SSLSocketFactory#createSocket()} @@ -107,29 +108,19 @@ public static void initTLSv11orUpper() throws NoSuchAlgorithmException, KeyManag if (isTLSv11orUpperEnabled(socket)) { return; } - boolean supportTLSv11 = false; - boolean supportTLSv12 = false; - for (String protocol : socket.getSupportedProtocols()) { - if ("TLSv1.2".equals(protocol)) { - supportTLSv12 = true; - break; + final String[] supportedProtocols = socket.getSupportedProtocols(); + Arrays.sort(supportedProtocols); + for (int i = supportedProtocols.length - 1; i >= 0; i--) { + final String supportedProtocol = supportedProtocols[i]; + if (supportedProtocol.startsWith("TLSv1.")) { + final SSLContext context = SSLContext.getInstance(supportedProtocol); + context.init(null, null, null); + SSLContext.setDefault(context); + return; } - if ("TLSv1.1".equals(protocol)) { - supportTLSv11 = true; - } - } - - final SSLContext context; - if (supportTLSv12) { - context = SSLContext.getInstance("TLSv1.2"); - } else if (supportTLSv11) { - context = SSLContext.getInstance("TLSv1.1"); - } else { - throw new NoSuchAlgorithmException("for Salesforce API to work you need jvm with TLS 1.1 or 1.2 support"); } - context.init(null, null, null); - SSLContext.setDefault(context); + throw new NoSuchAlgorithmException("for Salesforce API to work you need jvm with TLS 1.1 or higher support"); } @Override diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java index 7d4aa6b10..b9c65a868 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -29,7 +29,7 @@ public static void main(String... args) throws IOException, NoSuchAlgorithmExcep // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; - //IT's important! Salesforce upper require TLS v1.1 or 1.2. + //IT's important! Salesforce upper require TLS v1.1 or higher. //They are enabled in Java 8 by default, but not in Java 7 SalesforceApi.initTLSv11orUpper(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java index f5a524026..66470d597 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java @@ -42,7 +42,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx .setReadTimeout(10_000) .build()); - //IT's important! Salesforce upper require TLS v1.1 or 1.2 + //IT's important! Salesforce upper require TLS v1.1 or higher SalesforceApi.initTLSv11orUpper(); try (OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) From 2bfe14f7bfbbb538ab234ebde3dc40ad8fce8b2e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 7 Mar 2019 13:29:32 +0300 Subject: [PATCH 174/481] fix NPE in Apache HTTP client in case of empty body in HTTP response (e.g. with 204 response code) (thanks to https://github.com/SainagNeelamPatnaik) --- changelog | 1 + pom.xml | 4 ++-- scribejava-httpclient-ahc/pom.xml | 2 +- .../httpclient/apache/OAuthAsyncCompletionHandler.java | 4 +++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/changelog b/changelog index 0e81fe569..612e4aa8d 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * support TLS 1.3 in JDK 11 for Salesforce + * fix NPE in Apache HTTP client in case of empty body in HTTP response (e.g. with 204 response code) (thanks to https://github.com/SainagNeelamPatnaik) [6.3.0] * fix Muplipart request model and implement it for a jdk HTTP client (thanks to https://github.com/NTPape) diff --git a/pom.xml b/pom.xml index b9c60a7cc..3267c3328 100644 --- a/pom.xml +++ b/pom.xml @@ -107,7 +107,7 @@ com.puppycrawl.tools checkstyle - 8.17 + 8.18 @@ -188,7 +188,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.0.1 + 3.1.0 ${java.home}/bin/javadoc UTF-8 diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 9c9f5c226..dae66e4a6 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.7.0 + 2.8.1 com.github.scribejava diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java index 65b92a178..4494fea2b 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java @@ -17,6 +17,7 @@ import com.github.scribejava.core.model.OAuthRequest.ResponseConverter; import com.github.scribejava.core.model.Response; import java.io.IOException; +import org.apache.http.HttpEntity; public class OAuthAsyncCompletionHandler implements FutureCallback { @@ -42,8 +43,9 @@ public void completed(HttpResponse httpResponse) { final StatusLine statusLine = httpResponse.getStatusLine(); + final HttpEntity httpEntity = httpResponse.getEntity(); final Response response = new Response(statusLine.getStatusCode(), statusLine.getReasonPhrase(), headersMap, - httpResponse.getEntity().getContent()); + httpEntity == null ? null : httpEntity.getContent()); @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); From 088481db29dc03d600ac0631223b075165366866 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 19 Mar 2019 15:03:12 +0300 Subject: [PATCH 175/481] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 654d83dd8..d221e975c 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,12 @@ And in case you need just core classes (that's it, without any external API (FB, First of all, Pull Requests are welcome, the second option is [donations](https://github.com/scribejava/scribejava/blob/master/donate.md). +## When will ScribeJava support XXX (new RFC, custom functionality, new API etc.) + +When you will send the pull request. That's the way for a majority of changes here. +Or you can ask someone to make the paid job for you. +In some cases, when I'm interested in changes (technicaly or financialey), I can implement the request myself. + ## Getting started in less than 2 minutes Check the [Getting Started](https://github.com/scribejava/scribejava/wiki/getting-started) page and start rocking! Please Read the [FAQ](https://github.com/scribejava/scribejava/wiki/faq) before creating an issue :) From af55f79d386dd2ff5fecdda008cdf226c129b720 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 21 Mar 2019 12:49:11 +0300 Subject: [PATCH 176/481] update OkHTTP --- pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3267c3328..2b8434239 100644 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,7 @@ com.squareup.okhttp3 mockwebserver - 3.13.1 + 3.14.0 test diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index bfc65c303..968c72a9b 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 3.13.1 + 3.14.0 com.github.scribejava From 14a4b33a4d7485fe85bb3d74fc6038ad8745c7bb Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 21 Mar 2019 19:14:44 +0300 Subject: [PATCH 177/481] separate OAuth1.0a and OAuth2.0 classes --- changelog | 1 + .../github/scribejava/apis/FacebookApi.java | 28 +++++++++++++++-- .../com/github/scribejava/apis/ImgurApi.java | 28 +++++++++++++++-- .../com/github/scribejava/apis/MailruApi.java | 28 +++++++++++++++-- .../scribejava/apis/OdnoklassnikiApi.java | 31 +++++++++++++++++-- .../github/scribejava/apis/WunderlistAPI.java | 28 +++++++++++++++-- .../apis/facebook/FacebookService.java | 4 +-- .../apis/imgur/ImgurOAuthService.java | 4 +-- .../apis/mailru/MailruOAuthService.java | 4 +-- .../OdnoklassnikiOAuthService.java | 7 +++-- .../wunderlist/WunderlistOAuthService.java | 7 +++-- .../core/builder/ServiceBuilder.java | 17 ++++++++++ .../scribejava/core/builder/api/BaseApi.java | 26 +++++++++++++++- .../core/builder/api/DefaultApi10a.java | 22 +++++++++++++ .../core/builder/api/DefaultApi20.java | 27 ++++++++++++++-- .../core/oauth/OAuth10aService.java | 5 +-- .../scribejava/core/oauth/OAuth20Service.java | 31 +++++++++---------- .../scribejava/core/oauth/OAuthService.java | 26 ++++++++++++---- .../scribejava/core/pkce/PKCEService.java | 9 ++++++ .../scribejava/core/oauth/OAuth20ApiUnit.java | 28 +++++++++++++++-- .../core/oauth/OAuth20ServiceUnit.java | 4 +-- .../pkce/PKCECodeChallengeMethodTest.java | 2 +- 22 files changed, 311 insertions(+), 56 deletions(-) diff --git a/changelog b/changelog index 612e4aa8d..dbebf0499 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * support TLS 1.3 in JDK 11 for Salesforce * fix NPE in Apache HTTP client in case of empty body in HTTP response (e.g. with 204 response code) (thanks to https://github.com/SainagNeelamPatnaik) + * separate OAuth1.0a and OAuth2.0 classes [6.3.0] * fix Muplipart request model and implement it for a jdk HTTP client (thanks to https://github.com/NTPape) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index 4b2df428e..5551d0c4a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -70,11 +70,35 @@ public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } + /** + * + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param debugStream debugStream + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return service + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient) } + */ + @Deprecated @Override - public FacebookService createService(String apiKey, String apiSecret, String callback, String scope, + public FacebookService createService(String apiKey, String apiSecret, String callback, String defaultScope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new FacebookService(this, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, + return createService(apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); } + + @Override + public FacebookService createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new FacebookService(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, + httpClientConfig, httpClient); + } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index 3e2eddb50..7a7ce3435 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -54,11 +54,35 @@ protected String getAuthorizationBaseUrl() { throw new UnsupportedOperationException("use getAuthorizationUrl instead"); } + /** + * + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param debugStream debugStream + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return service + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient) } + */ + @Deprecated @Override - public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String scope, + public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new ImgurOAuthService(this, apiKey, apiSecret, callback, scope, responseType, userAgent, + return createService(apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, + httpClient); + } + + @Override + public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new ImgurOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index 2235301ba..e38e6b6af 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -29,11 +29,35 @@ protected String getAuthorizationBaseUrl() { return "https://connect.mail.ru/oauth/authorize"; } + /** + * + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param debugStream debugStream + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return service + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient) } + */ + @Deprecated @Override - public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String scope, + public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new MailruOAuthService(this, apiKey, apiSecret, callback, scope, responseType, userAgent, + return createService(apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, + httpClient); + } + + @Override + public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new MailruOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index 1d03bf1af..5b9ea87c9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -33,11 +33,36 @@ protected String getAuthorizationBaseUrl() { return "https://connect.ok.ru/oauth/authorize"; } + /** + * + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param debugStream debugStream + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return service + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient) } + */ + @Deprecated @Override - public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, + public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, + String defaultScope, OutputStream debugStream, String responseType, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, + httpClient); + } + + @Override + public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, + String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OdnoklassnikiOAuthService(this, apiKey, apiSecret, callback, scope, responseType, userAgent, + return new OdnoklassnikiOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java index 6bdcfdf7c..cb82470d0 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java @@ -48,11 +48,35 @@ public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } + /** + * + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param debugStream debugStream + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return service + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient) } + */ + @Deprecated @Override - public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, + public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new WunderlistOAuthService(this, apiKey, apiSecret, callback, scope, responseType, userAgent, + return createService(apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, + httpClient); + } + + @Override + public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new WunderlistOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java index 9ec9c0ceb..728d9349a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java @@ -13,9 +13,9 @@ public class FacebookService extends OAuth20Service { - public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); + super(api, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java index 4c8da3c82..b4fb16b66 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java @@ -10,9 +10,9 @@ public class ImgurOAuthService extends OAuth20Service { - public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); + super(api, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java index 37fcab964..b3f8c4770 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java @@ -16,9 +16,9 @@ public class MailruOAuthService extends OAuth20Service { - public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); + super(api, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java index f8cb1e3f5..c168aafcc 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java @@ -19,9 +19,10 @@ public class OdnoklassnikiOAuthService extends OAuth20Service { - public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); + public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, + String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java index b46a0870f..94e72b044 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java @@ -8,9 +8,10 @@ public class WunderlistOAuthService extends OAuth20Service { - public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, String scope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); + public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, + String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index 254b46e5f..cb2ef9c22 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -1,8 +1,12 @@ package com.github.scribejava.core.builder; import com.github.scribejava.core.builder.api.BaseApi; +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth.OAuth10aService; +import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.oauth.OAuthService; import com.github.scribejava.core.utils.Preconditions; @@ -121,9 +125,22 @@ public ServiceBuilder debug() { * @param OAuthService implementation (OAuth1/OAuth2/any API specific) * @param api will build Service for this API * @return fully configured {@link OAuthService} + * @deprecated use {@link #build(com.github.scribejava.core.builder.api.DefaultApi10a) } + * or {@link #build(com.github.scribejava.core.builder.api.DefaultApi20)} */ + @Deprecated public S build(BaseApi api) { return api.createService(apiKey, apiSecret, callback, scope, debugStream, responseType, userAgent, httpClientConfig, httpClient); } + + public OAuth10aService build(DefaultApi10a api) { + return api.createService(apiKey, apiSecret, callback, scope, debugStream, userAgent, httpClientConfig, + httpClient); + } + + public OAuth20Service build(DefaultApi20 api) { + return api.createService(apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, + httpClient); + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java index 0ce3377d6..2923c1e33 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java @@ -5,8 +5,32 @@ import com.github.scribejava.core.oauth.OAuthService; import java.io.OutputStream; +/** + * @param T + * @deprecated there is no common in Api10a and Api20. Use {@link DefaultApi10a} or {@link DefaultApi20}.
    + * if you need the common parent, it is the {@link Object} + */ +@Deprecated public interface BaseApi { - + /** + * + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param debugStream debugStream + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return service + * @deprecated use {@link DefaultApi10a#createService(java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient) } or {@link DefaultApi20#createService(java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated T createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index 7ef8b572d..859a67dc9 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -143,10 +143,32 @@ public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return parameters.appendTo(getAuthorizationBaseUrl()); } + /** + * + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param debugStream debugStream + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return service + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override public OAuth10aService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, scope, debugStream, userAgent, httpClientConfig, httpClient); + } + + public OAuth10aService createService(String apiKey, String apiSecret, String callback, String scope, + OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { return new OAuth10aService(this, apiKey, apiSecret, callback, scope, debugStream, userAgent, httpClientConfig, httpClient); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index e998cde81..5a9c88525 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -106,14 +106,37 @@ public String getAuthorizationUrl(String responseType, String apiKey, String cal return parameters.appendTo(getAuthorizationBaseUrl()); } + /** + * + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param debugStream debugStream + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return service + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient) } + */ + @Deprecated @Override - public OAuth20Service createService(String apiKey, String apiSecret, String callback, String scope, + public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OAuth20Service(this, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, + return createService(apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); } + public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new OAuth20Service(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, + httpClientConfig, httpClient); + } + public BearerSignature getBearerSignature() { return BearerSignatureAuthorizationRequestHeaderField.instance(); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index b168a9f2c..a2dc08142 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -24,12 +24,14 @@ public class OAuth10aService extends OAuthService { private static final String VERSION = "1.0"; private final OutputStream debugStream; private final DefaultApi10a api; + private final String scope; public OAuth10aService(DefaultApi10a api, String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(apiKey, apiSecret, callback, scope, userAgent, httpClientConfig, httpClient); + super(apiKey, apiSecret, callback, userAgent, httpClientConfig, httpClient); this.debugStream = debugStream; this.api = api; + this.scope = scope; } public OAuth1RequestToken getRequestToken() throws IOException, InterruptedException, ExecutionException { @@ -79,7 +81,6 @@ protected void addOAuthParams(OAuthRequest request, String tokenSecret) { request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, getApiKey()); request.addOAuthParameter(OAuthConstants.SIGN_METHOD, api.getSignatureService().getSignatureMethod()); request.addOAuthParameter(OAuthConstants.VERSION, getVersion()); - final String scope = getScope(); if (scope != null) { request.addOAuthParameter(OAuthConstants.SCOPE, scope); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 9c2a1aef3..2b85f7b47 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -24,15 +24,16 @@ public class OAuth20Service extends OAuthService { private static final String VERSION = "2.0"; - private static final PKCEService PKCE_SERVICE = new PKCEService(); private final DefaultApi20 api; private final String responseType; + private final String defaultScope; - public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(apiKey, apiSecret, callback, scope, userAgent, httpClientConfig, httpClient); + super(apiKey, apiSecret, callback, userAgent, httpClientConfig, httpClient); this.responseType = responseType; this.api = api; + this.defaultScope = defaultScope; } //protected to facilitate mocking @@ -109,9 +110,8 @@ protected OAuthRequest createAccessTokenRequest(String code) { if (callback != null) { request.addParameter(OAuthConstants.REDIRECT_URI, callback); } - final String scope = getScope(); - if (scope != null) { - request.addParameter(OAuthConstants.SCOPE, scope); + if (defaultScope != null) { + request.addParameter(OAuthConstants.SCOPE, defaultScope); } request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); return request; @@ -151,9 +151,8 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken) { api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); - final String scope = getScope(); - if (scope != null) { - request.addParameter(OAuthConstants.SCOPE, scope); + if (defaultScope != null) { + request.addParameter(OAuthConstants.SCOPE, defaultScope); } request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); @@ -192,9 +191,8 @@ protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, St request.addParameter(OAuthConstants.USERNAME, username); request.addParameter(OAuthConstants.PASSWORD, password); - final String scope = getScope(); - if (scope != null) { - request.addParameter(OAuthConstants.SCOPE, scope); + if (defaultScope != null) { + request.addParameter(OAuthConstants.SCOPE, defaultScope); } request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.PASSWORD); @@ -234,9 +232,8 @@ protected OAuthRequest createAccessTokenClientCredentialsGrantRequest() { api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); - final String scope = getScope(); - if (scope != null) { - request.addParameter(OAuthConstants.SCOPE, scope); + if (defaultScope != null) { + request.addParameter(OAuthConstants.SCOPE, defaultScope); } request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.CLIENT_CREDENTIALS); return request; @@ -271,7 +268,7 @@ public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(Map } public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state, Map additionalParams) { - final PKCE pkce = PKCE_SERVICE.generatePKCE(); + final PKCE pkce = PKCEService.defaultInstance().generatePKCE(); return new AuthorizationUrlWithPKCE(pkce, getAuthorizationUrl(state, additionalParams, pkce)); } @@ -322,7 +319,7 @@ public String getAuthorizationUrl(String state, Map additionalPa params = additionalParams == null ? new HashMap() : new HashMap<>(additionalParams); params.putAll(pkce.getAuthorizationUrlParams()); } - return api.getAuthorizationUrl(getResponseType(), getApiKey(), getCallback(), getScope(), state, params); + return api.getAuthorizationUrl(getResponseType(), getApiKey(), getCallback(), defaultScope, state, params); } public DefaultApi20 getApi() { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index cc9d7ad09..0a8cc8e93 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -21,16 +21,34 @@ public abstract class OAuthService implements Closeable { private final String apiKey; private final String apiSecret; private final String callback; - private final String scope; private final String userAgent; private final HttpClient httpClient; + /** + * + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param scope scope + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated scope moved to {@link OAuth10aService} and {@link OAuth20Service}.
    + * Use their constructors or {@link OAuthService#OAuthService(java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated public OAuthService(String apiKey, String apiSecret, String callback, String scope, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + this(apiKey, apiSecret, callback, userAgent, httpClientConfig, httpClient); + } + + public OAuthService(String apiKey, String apiSecret, String callback, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { this.apiKey = apiKey; this.apiSecret = apiSecret; this.callback = callback; - this.scope = scope; this.userAgent = userAgent; if (httpClientConfig == null && httpClient == null) { @@ -67,10 +85,6 @@ public String getCallback() { return callback; } - public String getScope() { - return scope; - } - /** * Returns the OAuth version of the service. * diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java index 2af370a75..8709174b8 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java @@ -28,6 +28,15 @@ public PKCEService() { this(32); } + private static class DefaultInstanceHolder { + + private static final PKCEService INSTANCE = new PKCEService(); + } + + public static PKCEService defaultInstance() { + return DefaultInstanceHolder.INSTANCE; + } + public PKCE generatePKCE() { final byte[] bytes = new byte[numberOFOctets]; RANDOM.nextBytes(bytes); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java index 141be05d5..7a9c6054b 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java @@ -19,11 +19,35 @@ protected String getAuthorizationBaseUrl() { return "http://localhost:8080/authorize"; } + /** + * + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param debugStream debugStream + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return service + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient) } + */ + @Deprecated @Override - public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String callback, String scope, + public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String callback, String defaultScope, OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OAuth20ServiceUnit(this, apiKey, apiSecret, callback, scope, responseType, userAgent, + return createService(apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, + httpClient); + } + + @Override + public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new OAuth20ServiceUnit(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index 0bcc766ad..fe68d3873 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -20,9 +20,9 @@ class OAuth20ServiceUnit extends OAuth20Service { static final String STATE = "123"; static final String EXPIRES = "3600"; - OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String scope, + OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); + super(api, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethodTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethodTest.java index 1f580480a..a83a5470d 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethodTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethodTest.java @@ -16,7 +16,7 @@ public class PKCECodeChallengeMethodTest { @Test public void testGeneratingPKCE() { - final PKCE pkce = new PKCEService().generatePKCE(RANDOM_BYTES); + final PKCE pkce = PKCEService.defaultInstance().generatePKCE(RANDOM_BYTES); assertEquals(PKCECodeChallengeMethod.S256, pkce.getCodeChallengeMethod()); assertEquals("dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk", pkce.getCodeVerifier()); From 03ab707ccf0ce424bb20337ffe6a70ac6d7488e2 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 21 Mar 2019 19:16:26 +0300 Subject: [PATCH 178/481] prepare v6.4.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d221e975c..aa5ec7106 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.3.0 + 6.4.0 ``` @@ -137,7 +137,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.3.0 + 6.4.0 ``` diff --git a/changelog b/changelog index dbebf0499..e49b93323 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.4.0] * support TLS 1.3 in JDK 11 for Salesforce * fix NPE in Apache HTTP client in case of empty body in HTTP response (e.g. with 204 response code) (thanks to https://github.com/SainagNeelamPatnaik) * separate OAuth1.0a and OAuth2.0 classes From 2a6dc253b572b57573d7fb0f548efdb406354851 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 21 Mar 2019 19:28:56 +0300 Subject: [PATCH 179/481] [maven-release-plugin] prepare release scribejava-6.4.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 2b8434239..5de802831 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.3.1-SNAPSHOT + 6.4.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.4.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 81ac6e17b..eeaa6fc6e 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.1-SNAPSHOT + 6.4.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 4252ba944..e78c06e29 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.1-SNAPSHOT + 6.4.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index dae66e4a6..9b694755f 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.1-SNAPSHOT + 6.4.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index a01b769d9..b98461081 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.1-SNAPSHOT + 6.4.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 33fb12bf8..4952870d3 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.1-SNAPSHOT + 6.4.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 968c72a9b..b36ae26b7 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.1-SNAPSHOT + 6.4.0 ../pom.xml From f232d800a044bda78b63f461e58f814c5f81b3ad Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 21 Mar 2019 19:29:09 +0300 Subject: [PATCH 180/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 5de802831..4cd5b70b3 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.4.0 + 6.4.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.4.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index eeaa6fc6e..57eb94938 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.0 + 6.4.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index e78c06e29..8e26aa487 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.0 + 6.4.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 9b694755f..ac0153b2f 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.0 + 6.4.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index b98461081..cd06ce261 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.0 + 6.4.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 4952870d3..4e6305725 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.0 + 6.4.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index b36ae26b7..d13301eaa 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.0 + 6.4.1-SNAPSHOT ../pom.xml From c7715d8511f2fadb29b7f8174c0f0a635f79e008 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Mar 2019 10:44:46 +0300 Subject: [PATCH 181/481] Revert "[maven-release-plugin] prepare for next development iteration" This reverts commit f232d800a044bda78b63f461e58f814c5f81b3ad. --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 4cd5b70b3..5de802831 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.4.1-SNAPSHOT + 6.4.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.4.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 57eb94938..eeaa6fc6e 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.1-SNAPSHOT + 6.4.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 8e26aa487..e78c06e29 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.1-SNAPSHOT + 6.4.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index ac0153b2f..9b694755f 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.1-SNAPSHOT + 6.4.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index cd06ce261..b98461081 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.1-SNAPSHOT + 6.4.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 4e6305725..4952870d3 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.1-SNAPSHOT + 6.4.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index d13301eaa..b36ae26b7 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.1-SNAPSHOT + 6.4.0 ../pom.xml From be5199d70585a570dd43319a8622c146c4d97a6a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Mar 2019 10:44:59 +0300 Subject: [PATCH 182/481] Revert "[maven-release-plugin] prepare release scribejava-6.4.0" This reverts commit 2a6dc253b572b57573d7fb0f548efdb406354851. --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 5de802831..2b8434239 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.4.0 + 6.3.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.4.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index eeaa6fc6e..81ac6e17b 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.0 + 6.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index e78c06e29..4252ba944 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.0 + 6.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 9b694755f..dae66e4a6 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.0 + 6.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index b98461081..a01b769d9 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.0 + 6.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 4952870d3..33fb12bf8 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.0 + 6.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index b36ae26b7..968c72a9b 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.0 + 6.3.1-SNAPSHOT ../pom.xml From 0bb4efdd57580d5ae955ab32b97d3f7c8908b4d5 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Mar 2019 10:45:10 +0300 Subject: [PATCH 183/481] Revert "prepare v6.4.0" This reverts commit 03ab707ccf0ce424bb20337ffe6a70ac6d7488e2. --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index aa5ec7106..d221e975c 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.4.0 + 6.3.0 ``` @@ -137,7 +137,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.4.0 + 6.3.0 ``` diff --git a/changelog b/changelog index e49b93323..dbebf0499 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[6.4.0] +[SNAPSHOT] * support TLS 1.3 in JDK 11 for Salesforce * fix NPE in Apache HTTP client in case of empty body in HTTP response (e.g. with 204 response code) (thanks to https://github.com/SainagNeelamPatnaik) * separate OAuth1.0a and OAuth2.0 classes From 1bdebc84db794f15c97790b2f9c2541baa84f1f0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Mar 2019 10:48:53 +0300 Subject: [PATCH 184/481] prepare v6.4.1 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d221e975c..61d8be29c 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.3.0 + 6.4.1 ``` @@ -137,7 +137,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.3.0 + 6.4.1 ``` diff --git a/changelog b/changelog index dbebf0499..007754eab 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.4.1] * support TLS 1.3 in JDK 11 for Salesforce * fix NPE in Apache HTTP client in case of empty body in HTTP response (e.g. with 204 response code) (thanks to https://github.com/SainagNeelamPatnaik) * separate OAuth1.0a and OAuth2.0 classes From d5a4a04892cd82a6e8b96927edf72a522712e73b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Mar 2019 10:51:20 +0300 Subject: [PATCH 185/481] [maven-release-plugin] prepare release scribejava-6.4.1 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 2b8434239..97f01c5ab 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.3.1-SNAPSHOT + 6.4.1 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.4.1 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 81ac6e17b..75387ceaa 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.1-SNAPSHOT + 6.4.1 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 4252ba944..c38056f1b 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.1-SNAPSHOT + 6.4.1 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index dae66e4a6..038244168 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.1-SNAPSHOT + 6.4.1 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index a01b769d9..214ab6a6a 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.1-SNAPSHOT + 6.4.1 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 33fb12bf8..b0d421710 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.1-SNAPSHOT + 6.4.1 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 968c72a9b..3e5559a21 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.3.1-SNAPSHOT + 6.4.1 ../pom.xml From be9614b4b74de0665f6073ec1b24a403f152eaf7 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Mar 2019 10:51:30 +0300 Subject: [PATCH 186/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 97f01c5ab..bd17a9f31 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.4.1 + 6.4.2-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.4.1 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 75387ceaa..4776cb3a5 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.1 + 6.4.2-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index c38056f1b..eee982dbf 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.1 + 6.4.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 038244168..54682f9c5 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.1 + 6.4.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 214ab6a6a..856fb8de7 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.1 + 6.4.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index b0d421710..6028cba24 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.1 + 6.4.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 3e5559a21..5640e147f 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.1 + 6.4.2-SNAPSHOT ../pom.xml From befc68494e90e725c264a9a20027ed7ba6912ef8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Mar 2019 11:36:16 +0300 Subject: [PATCH 187/481] grammar fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 61d8be29c..b63986121 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ OAuthService service = new ServiceBuilder(YOUR_API_KEY) That **single line** (added newlines for readability) is the only thing you need to configure ScribeJava with LinkedIn's OAuth API for example. -Working runnable examples are [here](https://github.com/scribejava/scribejava/tree/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples) +Working executable examples are [here](https://github.com/scribejava/scribejava/tree/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples) Common usage: [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java) ### Threadsafe From bec29fd2efa4f64fa9320a5a4ab1af38679de1fb Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Mar 2019 12:19:57 +0300 Subject: [PATCH 188/481] drop deprecates + add note to changelog about bask of java7 support --- changelog | 2 +- .../github/scribejava/apis/FacebookApi.java | 26 -------------- .../com/github/scribejava/apis/ImgurApi.java | 26 -------------- .../com/github/scribejava/apis/MailruApi.java | 26 -------------- .../scribejava/apis/OdnoklassnikiApi.java | 26 -------------- .../github/scribejava/apis/WunderlistAPI.java | 26 -------------- .../core/builder/ServiceBuilder.java | 16 --------- .../scribejava/core/builder/api/BaseApi.java | 36 ------------------- .../core/builder/api/DefaultApi10a.java | 26 +------------- .../core/builder/api/DefaultApi20.java | 28 +-------------- .../scribejava/core/oauth/OAuthService.java | 20 ----------- .../scribejava/core/oauth/OAuth20ApiUnit.java | 26 -------------- 12 files changed, 3 insertions(+), 281 deletions(-) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java diff --git a/changelog b/changelog index 007754eab..3d5baf6f4 100644 --- a/changelog +++ b/changelog @@ -68,7 +68,7 @@ * fix LinkedInApi20 (thanks to https://github.com/jhorowitz-firedrum) [5.0.0] - * drop Java 7 backward compatibility support, become Java 8 only + * drop Java 7 backward compatibility support, become Java 8 only (was reverted in v5.2.0-java7again) * add JSON token extractor for OAuth 1.0a (thanks to https://github.com/evstropovv) * add new API - uCoz (https://www.ucoz.com/) (thanks to https://github.com/evstropovv) * add PKCE (RFC 7636) support (Proof Key for Code Exchange by OAuth Public Clients) (thanks for suggesting to https://github.com/dieseldjango) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index 5551d0c4a..f41c801e1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -10,7 +10,6 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; -import java.io.OutputStream; /** * Facebook API @@ -70,31 +69,6 @@ public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } - /** - * - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param debugStream debugStream - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return service - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient) } - */ - @Deprecated - @Override - public FacebookService createService(String apiKey, String apiSecret, String callback, String defaultScope, - OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, - httpClient); - } - @Override public FacebookService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index 7a7ce3435..0a7aced8f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.ParameterList; -import java.io.OutputStream; import java.util.Map; public class ImgurApi extends DefaultApi20 { @@ -54,31 +53,6 @@ protected String getAuthorizationBaseUrl() { throw new UnsupportedOperationException("use getAuthorizationUrl instead"); } - /** - * - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param debugStream debugStream - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return service - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient) } - */ - @Deprecated - @Override - public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, - OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, - httpClient); - } - @Override public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index e38e6b6af..c10dd0bab 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -4,7 +4,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import java.io.OutputStream; public class MailruApi extends DefaultApi20 { @@ -29,31 +28,6 @@ protected String getAuthorizationBaseUrl() { return "https://connect.mail.ru/oauth/authorize"; } - /** - * - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param debugStream debugStream - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return service - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient) } - */ - @Deprecated - @Override - public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, - OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, - httpClient); - } - @Override public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index 5b9ea87c9..d1cdcedb0 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -8,7 +8,6 @@ import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; -import java.io.OutputStream; public class OdnoklassnikiApi extends DefaultApi20 { @@ -33,31 +32,6 @@ protected String getAuthorizationBaseUrl() { return "https://connect.ok.ru/oauth/authorize"; } - /** - * - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param debugStream debugStream - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return service - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient) } - */ - @Deprecated - @Override - public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, - String defaultScope, OutputStream debugStream, String responseType, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, - httpClient); - } - @Override public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java index cb82470d0..89f070fa4 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java @@ -9,7 +9,6 @@ import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; -import java.io.OutputStream; /** * Wunderlist.com Api @@ -48,31 +47,6 @@ public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } - /** - * - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param debugStream debugStream - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return service - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient) } - */ - @Deprecated - @Override - public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, - OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, - httpClient); - } - @Override public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index cb2ef9c22..663b4a757 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -1,6 +1,5 @@ package com.github.scribejava.core.builder; -import com.github.scribejava.core.builder.api.BaseApi; import com.github.scribejava.core.builder.api.DefaultApi10a; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; @@ -119,21 +118,6 @@ public ServiceBuilder debug() { return this; } - /** - * Returns the fully configured {@link OAuthService} - * - * @param OAuthService implementation (OAuth1/OAuth2/any API specific) - * @param api will build Service for this API - * @return fully configured {@link OAuthService} - * @deprecated use {@link #build(com.github.scribejava.core.builder.api.DefaultApi10a) } - * or {@link #build(com.github.scribejava.core.builder.api.DefaultApi20)} - */ - @Deprecated - public S build(BaseApi api) { - return api.createService(apiKey, apiSecret, callback, scope, debugStream, responseType, userAgent, - httpClientConfig, httpClient); - } - public OAuth10aService build(DefaultApi10a api) { return api.createService(apiKey, apiSecret, callback, scope, debugStream, userAgent, httpClientConfig, httpClient); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java deleted file mode 100644 index 2923c1e33..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/BaseApi.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.scribejava.core.builder.api; - -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.oauth.OAuthService; -import java.io.OutputStream; - -/** - * @param T - * @deprecated there is no common in Api10a and Api20. Use {@link DefaultApi10a} or {@link DefaultApi20}.
    - * if you need the common parent, it is the {@link Object} - */ -@Deprecated -public interface BaseApi { - /** - * - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param debugStream debugStream - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return service - * @deprecated use {@link DefaultApi10a#createService(java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient) } or {@link DefaultApi20#createService(java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - T createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient); -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index 859a67dc9..6bd1c9392 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -34,7 +34,7 @@ * fine-tune the process. Please read the javadocs of the interfaces to get an idea of what to do. * */ -public abstract class DefaultApi10a implements BaseApi { +public abstract class DefaultApi10a { /** * Returns the access token extractor. @@ -143,30 +143,6 @@ public String getAuthorizationUrl(OAuth1RequestToken requestToken) { return parameters.appendTo(getAuthorizationBaseUrl()); } - /** - * - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param debugStream debugStream - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return service - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public OAuth10aService createService(String apiKey, String apiSecret, String callback, String scope, - OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, scope, debugStream, userAgent, httpClientConfig, httpClient); - } - public OAuth10aService createService(String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { return new OAuth10aService(this, apiKey, apiSecret, callback, scope, debugStream, userAgent, httpClientConfig, diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 5a9c88525..92ad8fab7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -13,7 +13,6 @@ import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureAuthorizationRequestHeaderField; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.HttpBasicAuthenticationScheme; -import java.io.OutputStream; import java.util.Map; /** @@ -29,7 +28,7 @@ * fine-tune the process. Please read the javadocs of the interfaces to get an idea of what to do. * */ -public abstract class DefaultApi20 implements BaseApi { +public abstract class DefaultApi20 { /** * Returns the access token extractor. @@ -106,31 +105,6 @@ public String getAuthorizationUrl(String responseType, String apiKey, String cal return parameters.appendTo(getAuthorizationBaseUrl()); } - /** - * - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param debugStream debugStream - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return service - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient) } - */ - @Deprecated - @Override - public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, - OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, - httpClient); - } - public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { return new OAuth20Service(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 0a8cc8e93..4d514381d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -24,26 +24,6 @@ public abstract class OAuthService implements Closeable { private final String userAgent; private final HttpClient httpClient; - /** - * - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param scope scope - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated scope moved to {@link OAuth10aService} and {@link OAuth20Service}.
    - * Use their constructors or {@link OAuthService#OAuthService(java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public OAuthService(String apiKey, String apiSecret, String callback, String scope, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(apiKey, apiSecret, callback, userAgent, httpClientConfig, httpClient); - } - public OAuthService(String apiKey, String apiSecret, String callback, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { this.apiKey = apiKey; diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java index 7a9c6054b..9b8df0977 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java @@ -5,7 +5,6 @@ import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; -import java.io.OutputStream; class OAuth20ApiUnit extends DefaultApi20 { @@ -19,31 +18,6 @@ protected String getAuthorizationBaseUrl() { return "http://localhost:8080/authorize"; } - /** - * - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param debugStream debugStream - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return service - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient) } - */ - @Deprecated - @Override - public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String callback, String defaultScope, - OutputStream debugStream, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, - httpClient); - } - @Override public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { From 3f72ef50d5d0f8337b6fe77c258e1a1e901876e1 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Mar 2019 18:00:06 +0300 Subject: [PATCH 189/481] * separate OAuth1.0a and OAuth2.0 ServiceBuilders, introduce AuthorizationUrlBuilder (along with deprecation of AuthorizationUrlWithPKCE), add possibility to provide different scopes for each Access Token request --- changelog | 5 + .../apis/imgur/ImgurOAuthService.java | 11 +- .../apis/examples/AutomaticExample.java | 2 +- .../apis/examples/Box20Example.java | 5 +- .../apis/examples/DiscordExample.java | 2 +- .../apis/examples/FitbitApi20Example.java | 2 +- .../apis/examples/FrappeExample.java | 2 +- .../apis/examples/FreelancerExample.java | 2 +- .../apis/examples/GeniusExample.java | 2 +- .../examples/Google20AsyncAHCExample.java | 7 +- .../apis/examples/Google20Example.java | 7 +- .../apis/examples/Google20RevokeExample.java | 7 +- .../examples/Google20WithPKCEExample.java | 16 +- .../apis/examples/HiOrgServerExample.java | 2 +- .../apis/examples/KeycloakExample.java | 2 +- .../apis/examples/LinkedIn20Example.java | 2 +- .../scribejava/apis/examples/LiveExample.java | 2 +- ...icrosoftAzureActiveDirectory20Example.java | 2 +- .../MicrosoftAzureActiveDirectoryExample.java | 2 +- .../apis/examples/MisfitExample.java | 2 +- .../apis/examples/PinterestExample.java | 2 +- .../apis/examples/RenrenExample.java | 2 +- ...kontakteClientCredentialsGrantExample.java | 2 +- .../apis/examples/VkontakteExample.java | 11 +- .../VkontakteExternalHttpExample.java | 2 +- .../apis/examples/WunderlistExample.java | 1 - .../OdnoklassnikiServiceTest.java | 2 +- .../core/builder/ServiceBuilder.java | 65 ++-- .../core/builder/ServiceBuilderCommon.java | 59 ++++ .../core/builder/ServiceBuilderOAuth10a.java | 49 +++ .../core/builder/ServiceBuilderOAuth20.java | 52 +++ .../core/oauth/AccessTokenRequestParams.java | 37 ++ .../core/oauth/AuthorizationUrlBuilder.java | 61 ++++ .../scribejava/core/oauth/OAuth20Service.java | 328 ++++++++++++++++-- .../core/pkce/AuthorizationUrlWithPKCE.java | 33 +- .../core/oauth/OAuth20ServiceTest.java | 2 +- 36 files changed, 683 insertions(+), 109 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderCommon.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/oauth/AccessTokenRequestParams.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/oauth/AuthorizationUrlBuilder.java diff --git a/changelog b/changelog index 3d5baf6f4..ccce51b79 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,8 @@ +[SNAPSHOT] + * separate OAuth1.0a and OAuth2.0 ServiceBuilders, + introduce AuthorizationUrlBuilder (along with deprecation of AuthorizationUrlWithPKCE) + add possibility to provide different scopes for each Access Token request + [6.4.1] * support TLS 1.3 in JDK 11 for Salesforce * fix NPE in Apache HTTP client in case of empty body in HTTP response (e.g. with 204 response code) (thanks to https://github.com/SainagNeelamPatnaik) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java index b4fb16b66..a37d71cbf 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java @@ -6,7 +6,9 @@ import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.AccessTokenRequestParams; import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.core.pkce.PKCE; public class ImgurOAuthService extends OAuth20Service { @@ -16,12 +18,13 @@ public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, Stri } @Override - protected OAuthRequest createAccessTokenRequest(String oauthVerifier) { + protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) { final DefaultApi20 api = getApi(); final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); request.addBodyParameter(OAuthConstants.CLIENT_ID, getApiKey()); request.addBodyParameter(OAuthConstants.CLIENT_SECRET, getApiSecret()); + final String oauthVerifier = params.getCode(); if (ImgurApi.isOob(getCallback())) { request.addBodyParameter(OAuthConstants.GRANT_TYPE, "pin"); request.addBodyParameter("pin", oauthVerifier); @@ -29,6 +32,12 @@ protected OAuthRequest createAccessTokenRequest(String oauthVerifier) { request.addBodyParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); request.addBodyParameter(OAuthConstants.CODE, oauthVerifier); } + + final String pkceCodeVerifier = params.getPkceCodeVerifier(); + if (pkceCodeVerifier != null) { + request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); + } + return request; } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java index ed7ccd7ec..b3375aadd 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java @@ -29,7 +29,7 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .callback("http://www.example.com/oauth_callback/") - .scope("scope:user:profile").debug() + .defaultScope("scope:user:profile") .build(AutomaticAPI.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index 4931f097b..06d7d6c57 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -43,7 +43,10 @@ public static void main(String... args) throws IOException, InterruptedException additionalParams.put("access_type", "offline"); //force to reget refresh token (if usera are asked not the first time) additionalParams.put("prompt", "consent"); - final String authorizationUrl = service.getAuthorizationUrl(secretState, additionalParams); + final String authorizationUrl = service.createAuthorizationUrlBuilder() + .state(secretState) + .additionalParams(additionalParams) + .build(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java index 70714a16c..ec6784b14 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java @@ -28,7 +28,7 @@ public static void main(String... args) throws IOException, ExecutionException, final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .scope("identify") // replace with desired scope + .defaultScope("identify") // replace with desired scope .callback("http://example.com/callback") .userAgent("ScribeJava") .build(DiscordApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java index 955c1289f..fcffc5f7e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java @@ -27,7 +27,7 @@ public static void main(String... args) throws Exception { final String clientSecret = "your client secret"; final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .scope("activity profile") // replace with desired scope + .defaultScope("activity profile") // replace with desired scope //your callback URL to store and handle the authorization code sent by Fitbit .callback("http://www.example.com/oauth_callback/") .build(FitbitApi20.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java index ce9012b1c..ab1138411 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java @@ -26,7 +26,7 @@ public static void main(String... args) throws IOException, InterruptedException final String clientDomain = "https://example.com"; final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .scope("openid all") + .defaultScope("openid all") .callback("https://example.com/callback") .build(FrappeApi.instance(clientDomain)); final Scanner in = new Scanner(System.in, "UTF-8"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index 80640d989..42089ae74 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -26,7 +26,7 @@ private FreelancerExample() { public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") - .scope(SCOPE) + .withScope(SCOPE) .build(FreelancerApi.Sandbox.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java index d6726c2d1..538c4cf8d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java @@ -27,7 +27,7 @@ public static void main(String... args) throws IOException, InterruptedException final String secretState = "100"; final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .scope("me") + .defaultScope("me") .callback("com.scribejavatest://callback") .userAgent("ScribeJava") .build(GeniusApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index 3c20eb9bf..3365f06c7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -39,7 +39,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx try (OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .scope("profile") // replace with desired scope + .defaultScope("profile") // replace with desired scope .callback("http://example.com/callback") .httpClientConfig(clientConfig) .build(GoogleApi20.instance())) { @@ -56,7 +56,10 @@ public static void main(String... args) throws InterruptedException, ExecutionEx additionalParams.put("access_type", "offline"); //force to reget refresh token (if usera are asked not the first time) additionalParams.put("prompt", "consent"); - final String authorizationUrl = service.getAuthorizationUrl(secretState, additionalParams); + final String authorizationUrl = service.createAuthorizationUrlBuilder() + .state(secretState) + .additionalParams(additionalParams) + .build(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index de7e2e041..079f5670e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -29,7 +29,7 @@ public static void main(String... args) throws IOException, InterruptedException final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .scope("profile") // replace with desired scope + .defaultScope("profile") // replace with desired scope .callback("http://example.com/callback") .build(GoogleApi20.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); @@ -45,7 +45,10 @@ public static void main(String... args) throws IOException, InterruptedException additionalParams.put("access_type", "offline"); //force to reget refresh token (if usera are asked not the first time) additionalParams.put("prompt", "consent"); - final String authorizationUrl = service.getAuthorizationUrl(secretState, additionalParams); + final String authorizationUrl = service.createAuthorizationUrlBuilder() + .state(secretState) + .additionalParams(additionalParams) + .build(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java index f44a972a2..d399aa22b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java @@ -29,7 +29,7 @@ public static void main(String... args) throws IOException, InterruptedException final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .scope("profile") // replace with desired scope + .defaultScope("profile") // replace with desired scope .callback("http://example.com/callback") .build(GoogleApi20.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); @@ -45,7 +45,10 @@ public static void main(String... args) throws IOException, InterruptedException additionalParams.put("access_type", "offline"); //force to reget refresh token (if usera are asked not the first time) additionalParams.put("prompt", "consent"); - final String authorizationUrl = service.getAuthorizationUrl(secretState, additionalParams); + final String authorizationUrl = service.createAuthorizationUrlBuilder() + .state(secretState) + .additionalParams(additionalParams) + .build(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java index 377d52e6a..4091215a7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java @@ -4,12 +4,13 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.GoogleApi20; +import com.github.scribejava.core.oauth.AuthorizationUrlBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.AccessTokenRequestParams; import com.github.scribejava.core.oauth.OAuth20Service; -import com.github.scribejava.core.pkce.AuthorizationUrlWithPKCE; import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -30,7 +31,7 @@ public static void main(String... args) throws IOException, InterruptedException final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .scope("profile") // replace with desired scope + .defaultScope("profile") // replace with desired scope .callback("http://example.com/callback") .build(GoogleApi20.instance()); @@ -48,12 +49,14 @@ public static void main(String... args) throws IOException, InterruptedException //force to reget refresh token (if usera are asked not the first time) additionalParams.put("prompt", "consent"); - final AuthorizationUrlWithPKCE authUrlWithPKCE - = service.getAuthorizationUrlWithPKCE(secretState, additionalParams); + final AuthorizationUrlBuilder authorizationUrlBuilder = service.createAuthorizationUrlBuilder() + .state(secretState) + .additionalParams(additionalParams) + .initPKCE(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(authUrlWithPKCE.getAuthorizationUrl()); + System.out.println(authorizationUrlBuilder.build()); System.out.println("And paste the authorization code here"); System.out.print(">>"); final String code = in.nextLine(); @@ -73,7 +76,8 @@ public static void main(String... args) throws IOException, InterruptedException // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - OAuth2AccessToken accessToken = service.getAccessToken(code, authUrlWithPKCE.getPkce().getCodeVerifier()); + OAuth2AccessToken accessToken = service.getAccessToken(AccessTokenRequestParams.create(code) + .pkceCodeVerifier(authorizationUrlBuilder.getPkce().getCodeVerifier())); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java index 5ab81d8bc..4eb43b695 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java @@ -30,7 +30,7 @@ public static void main(String... args) throws IOException, InterruptedException final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .scope("basic eigenedaten") + .defaultScope("basic eigenedaten") .callback(CALLBACK_URL) .build(HiOrgServerApi20.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java index 57fa12c4f..18569f30d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java @@ -29,7 +29,7 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) - .scope("openid") + .defaultScope("openid") .callback(callback) .build(KeycloakApi.instance(baseUrl, realm)); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java index 825cf1ac2..00ab0abbf 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java @@ -25,7 +25,7 @@ public static void main(String... args) throws IOException, InterruptedException final String clientSecret = "your client secret"; final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .scope("r_basicprofile r_emailaddress") // replace with desired scope + .defaultScope("r_basicprofile r_emailaddress") // replace with desired scope .callback("http://example.com/callback") .build(LinkedInApi20.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index 119c5aca1..1bcd93cc9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -24,7 +24,7 @@ public static void main(String... args) throws IOException, InterruptedException final String apiSecret = ""; final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) - .scope("wl.basic") + .defaultScope("wl.basic") .callback("http://localhost:9000/") .build(LiveApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java index 9a8ac4f1e..bc42d4077 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java @@ -25,7 +25,7 @@ public static void main(String... args) throws IOException, InterruptedException final String clientSecret = "client secret here"; final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .scope("openid User.Read") + .defaultScope("openid User.Read") .callback("http://www.example.com/oauth_callback/") .build(MicrosoftAzureActiveDirectory20Api.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java index 51efc5cf8..2aa62b7b6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java @@ -27,7 +27,7 @@ public static void main(String... args) throws IOException, InterruptedException final String clientSecret = "client secret here"; final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .scope("openid") + .defaultScope("openid") .callback("http://www.example.com/oauth_callback/") .build(MicrosoftAzureActiveDirectoryApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java index 60d5a903c..e8a1437c0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java @@ -28,7 +28,7 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .callback("http://example.com/callback/") - .scope("public,birthday,email,tracking,session,sleep") + .defaultScope("public,birthday,email,tracking,session,sleep") .build(MisfitApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index 03b3a428a..54d058e68 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -25,7 +25,7 @@ public static void main(String... args) throws IOException, InterruptedException final String apiSecret = "your_app_secret"; final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) - .scope("read_public,write_public,read_relationships,write_relationships") + .defaultScope("read_public,write_public,read_relationships,write_relationships") .callback("https://localhost/") // Add as valid callback in developer portal .build(PinterestApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 4d9b3bd76..a3cdf3d66 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -35,7 +35,7 @@ public static void main(String... args) throws IOException, InterruptedException final String apiSecret = "your api secret"; final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) - .scope("status_update publish_feed") + .defaultScope("status_update publish_feed") .callback("http://your.doman.com/oauth/renren") .build(RenrenApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java index ed2fd0fba..f9d4a4514 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java @@ -20,7 +20,7 @@ public static void main(String... args) throws IOException, InterruptedException final String clientSecret = "your client secret"; final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .scope("wall,offline") // replace with desired scope + .defaultScope("wall,offline") // replace with desired scope .callback("http://your.site.com/callback") .build(VkontakteApi.instance()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java index bbab9db62..ca57c39f7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java @@ -8,6 +8,7 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.AccessTokenRequestParams; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; import java.util.concurrent.ExecutionException; @@ -27,7 +28,7 @@ public static void main(String... args) throws IOException, InterruptedException final String clientSecret = "your client secret"; final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .scope("wall,offline,email") // replace with desired scope + .defaultScope("wall,offline") // replace with desired scope .callback("http://your.site.com/callback") .build(VkontakteApi.instance()); final Scanner in = new Scanner(System.in); @@ -37,7 +38,10 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl(); + final String customScope = "wall,offline,email"; + final String authorizationUrl = service.createAuthorizationUrlBuilder() + .scope(customScope) + .build(); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -48,7 +52,8 @@ public static void main(String... args) throws IOException, InterruptedException // Trade the Request Token and Verfier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); - final OAuth2AccessToken accessToken = service.getAccessToken(code); + final OAuth2AccessToken accessToken = service.getAccessToken(AccessTokenRequestParams.create(code) + .scope(customScope)); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); if (accessToken instanceof VKOAuth2AccessToken) { diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java index eb0958491..abdf0b397 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java @@ -43,7 +43,7 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(clientId) .httpClient(wrappedAHCHttpClient) .apiSecret(clientSecret) - .scope("wall,offline") // replace with desired scope + .defaultScope("wall,offline") // replace with desired scope .callback("http://your.site.com/callback") .build(VkontakteApi.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java index 630df1c47..fd6fce936 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java @@ -31,7 +31,6 @@ public static void main(String... args) throws IOException, InterruptedException final OAuth20Service service = new ServiceBuilder(apiKey) .apiSecret(apiSecret) .callback(callbackUrl) - .debug() .build(WunderlistAPI.instance()); final String code; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiServiceTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiServiceTest.java index f1e108f49..f4bfbccac 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiServiceTest.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiServiceTest.java @@ -19,7 +19,7 @@ public class OdnoklassnikiServiceTest { private final OAuth20Service service = new ServiceBuilder("0000000000") .apiSecret("CCCCCCCCCCCCCCCCCCCCCCCC") - .scope("VALUABLE_ACCESS") + .defaultScope("VALUABLE_ACCESS") .callback("http://your.site.com/callback") .build(OdnoklassnikiApi.instance()); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index 663b4a757..fc767efb8 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -14,7 +14,7 @@ /** * Implementation of the Builder pattern, with a fluent interface that creates a {@link OAuthService} */ -public class ServiceBuilder { +public class ServiceBuilder implements ServiceBuilderOAuth10a, ServiceBuilderOAuth20 { private String callback; private String apiKey; @@ -31,36 +31,20 @@ public ServiceBuilder(String apiKey) { apiKey(apiKey); } - /** - * Adds an OAuth callback url - * - * @param callback callback url. Must be a valid url or 'oob' - * ({@link com.github.scribejava.core.model.OAuthConstants#OOB} for out of band OAuth - * @return the {@link ServiceBuilder} instance for method chaining - */ + @Override public ServiceBuilder callback(String callback) { this.callback = callback; return this; } - /** - * Configures the api key - * - * @param apiKey The api key for your application - * @return the {@link ServiceBuilder} instance for method chaining - */ + @Override public final ServiceBuilder apiKey(String apiKey) { Preconditions.checkEmptyString(apiKey, "Invalid Api key"); this.apiKey = apiKey; return this; } - /** - * Configures the api secret - * - * @param apiSecret The api secret for your application - * @return the {@link ServiceBuilder} instance for method chaining - */ + @Override public ServiceBuilder apiSecret(String apiSecret) { Preconditions.checkEmptyString(apiSecret, "Invalid Api secret"); this.apiSecret = apiSecret; @@ -68,61 +52,72 @@ public ServiceBuilder apiSecret(String apiSecret) { } /** - * Configures the OAuth scope. This is only necessary in some APIs (like Google's). - * - * @param scope The OAuth scope - * @return the {@link ServiceBuilder} instance for method chaining + * @deprecated use {@link ServiceBuilderOAuth20#defaultScope(java.lang.String)} or + * {@link ServiceBuilderOAuth10a#withScope(java.lang.String)} */ + @Override + @Deprecated public ServiceBuilder scope(String scope) { Preconditions.checkEmptyString(scope, "Invalid OAuth scope"); this.scope = scope; return this; } - public ServiceBuilder debugStream(OutputStream debugStream) { + @Override + public ServiceBuilderOAuth20 defaultScope(String defaultScope) { + return scope(defaultScope); + } + + @Override + public ServiceBuilderOAuth10a withScope(String scope) { + return scope(scope); + } + + @Override + public ServiceBuilderOAuth10a debugStream(OutputStream debugStream) { Preconditions.checkNotNull(debugStream, "debug stream can't be null"); this.debugStream = debugStream; return this; } - public ServiceBuilder responseType(String responseType) { + @Override + public ServiceBuilderOAuth20 responseType(String responseType) { Preconditions.checkEmptyString(responseType, "Invalid OAuth responseType"); this.responseType = responseType; return this; } + @Override public ServiceBuilder httpClientConfig(HttpClientConfig httpClientConfig) { Preconditions.checkNotNull(httpClientConfig, "httpClientConfig can't be null"); this.httpClientConfig = httpClientConfig; return this; } - /** - * takes precedence over httpClientConfig - * - * @param httpClient externally created HTTP client - * @return the {@link ServiceBuilder} instance for method chaining - */ + @Override public ServiceBuilder httpClient(HttpClient httpClient) { this.httpClient = httpClient; return this; } + @Override public ServiceBuilder userAgent(String userAgent) { this.userAgent = userAgent; return this; } - public ServiceBuilder debug() { - debugStream(System.out); - return this; + @Override + public ServiceBuilderOAuth10a debug() { + return debugStream(System.out); } + @Override public OAuth10aService build(DefaultApi10a api) { return api.createService(apiKey, apiSecret, callback, scope, debugStream, userAgent, httpClientConfig, httpClient); } + @Override public OAuth20Service build(DefaultApi20 api) { return api.createService(apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, httpClient); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderCommon.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderCommon.java new file mode 100644 index 000000000..3babd3d56 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderCommon.java @@ -0,0 +1,59 @@ +package com.github.scribejava.core.builder; + +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth.OAuthService; + +/** + * Implementation of the Builder pattern, with a fluent interface that creates a {@link OAuthService} + */ +public interface ServiceBuilderCommon { + + /** + * Adds an OAuth callback url + * + * @param callback callback url. Must be a valid url or 'oob' + * ({@link com.github.scribejava.core.model.OAuthConstants#OOB} for out of band OAuth + * @return the {@link ServiceBuilder} instance for method chaining + */ + ServiceBuilderCommon callback(String callback); + + /** + * Configures the api key + * + * @param apiKey The api key for your application + * @return the {@link ServiceBuilder} instance for method chaining + */ + ServiceBuilderCommon apiKey(String apiKey); + + /** + * Configures the api secret + * + * @param apiSecret The api secret for your application + * @return the {@link ServiceBuilder} instance for method chaining + */ + ServiceBuilderCommon apiSecret(String apiSecret); + + /** + * Configures the OAuth scope. This is only necessary in some APIs (like Google's). + * + * @param scope The OAuth scope + * @return the {@link ServiceBuilder} instance for method chaining + * @deprecated use {@link ServiceBuilderOAuth20#defaultScope(java.lang.String)} or + * {@link ServiceBuilderOAuth10a#withScope(java.lang.String)} + */ + @Deprecated + ServiceBuilderCommon scope(String scope); + + ServiceBuilderCommon httpClientConfig(HttpClientConfig httpClientConfig); + + /** + * takes precedence over httpClientConfig + * + * @param httpClient externally created HTTP client + * @return the {@link ServiceBuilder} instance for method chaining + */ + ServiceBuilderCommon httpClient(HttpClient httpClient); + + ServiceBuilderCommon userAgent(String userAgent); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java new file mode 100644 index 000000000..d73b99af9 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java @@ -0,0 +1,49 @@ +package com.github.scribejava.core.builder; + +import com.github.scribejava.core.builder.api.DefaultApi10a; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth.OAuth10aService; +import java.io.OutputStream; + +public interface ServiceBuilderOAuth10a extends ServiceBuilderCommon { + + @Override + ServiceBuilderOAuth20 callback(String callback); + + @Override + ServiceBuilderOAuth20 apiKey(String apiKey); + + @Override + ServiceBuilderOAuth20 apiSecret(String apiSecret); + + /** + * @deprecated use {@link #withScope(java.lang.String) } + */ + @Override + @Deprecated + ServiceBuilderOAuth20 scope(String scope); + + @Override + ServiceBuilderOAuth20 httpClientConfig(HttpClientConfig httpClientConfig); + + @Override + ServiceBuilderOAuth20 httpClient(HttpClient httpClient); + + @Override + ServiceBuilderOAuth20 userAgent(String userAgent); + + ServiceBuilderOAuth10a debugStream(OutputStream debugStream); + + ServiceBuilderOAuth10a debug(); + + /** + * Configures the OAuth 1.0a scope. This is only necessary in some APIs + * + * @param scope The OAuth scope + * @return the {@link ServiceBuilder} instance for method chaining + */ + ServiceBuilderOAuth10a withScope(String scope); + + OAuth10aService build(DefaultApi10a api); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java new file mode 100644 index 000000000..b7cefc475 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java @@ -0,0 +1,52 @@ +package com.github.scribejava.core.builder; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.oauth.OAuth20Service; + +public interface ServiceBuilderOAuth20 extends ServiceBuilderCommon { + + @Override + ServiceBuilderOAuth20 callback(String callback); + + @Override + ServiceBuilderOAuth20 apiKey(String apiKey); + + @Override + ServiceBuilderOAuth20 apiSecret(String apiSecret); + + /** + * @deprecated use {@link #defaultScope(java.lang.String) } + */ + @Override + @Deprecated + ServiceBuilderOAuth20 scope(String scope); + + @Override + ServiceBuilderOAuth20 httpClientConfig(HttpClientConfig httpClientConfig); + + @Override + ServiceBuilderOAuth20 httpClient(HttpClient httpClient); + + @Override + ServiceBuilderOAuth20 userAgent(String userAgent); + + ServiceBuilderOAuth20 responseType(String responseType); + + /** + * Configures the default OAuth 2.0 scope.
    + * + * You can request any uniq scope per each access token request using + * {@link com.github.scribejava.core.oauth.AuthorizationUrlBuilder#scope(java.lang.String) }.

    + * + * In case you're requesting always the same scope,
    + * you can just set it here and do not provide scope param nowhere more. + * + * @param defaultScope The OAuth scope, used as deafult + * @return the {@link ServiceBuilder} instance for method chaining + */ + ServiceBuilderOAuth20 defaultScope(String defaultScope); + + OAuth20Service build(DefaultApi20 api); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/AccessTokenRequestParams.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/AccessTokenRequestParams.java new file mode 100644 index 000000000..787ead8a7 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/AccessTokenRequestParams.java @@ -0,0 +1,37 @@ +package com.github.scribejava.core.oauth; + +public class AccessTokenRequestParams { + private final String code; + private String pkceCodeVerifier; + private String scope; + + public AccessTokenRequestParams(String code) { + this.code = code; + } + + public static AccessTokenRequestParams create(String code) { + return new AccessTokenRequestParams(code); + } + + public AccessTokenRequestParams pkceCodeVerifier(String pkceCodeVerifier) { + this.pkceCodeVerifier = pkceCodeVerifier; + return this; + } + + public AccessTokenRequestParams scope(String scope) { + this.scope = scope; + return this; + } + + public String getCode() { + return code; + } + + public String getPkceCodeVerifier() { + return pkceCodeVerifier; + } + + public String getScope() { + return scope; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/AuthorizationUrlBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/AuthorizationUrlBuilder.java new file mode 100644 index 000000000..fd02f60dd --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/AuthorizationUrlBuilder.java @@ -0,0 +1,61 @@ +package com.github.scribejava.core.oauth; + +import com.github.scribejava.core.pkce.PKCE; +import com.github.scribejava.core.pkce.PKCEService; +import java.util.HashMap; +import java.util.Map; + +public class AuthorizationUrlBuilder { + + private final OAuth20Service oauth20Service; + + private String state; + private Map additionalParams; + private PKCE pkce; + private String scope; + + public AuthorizationUrlBuilder(OAuth20Service oauth20Service) { + this.oauth20Service = oauth20Service; + } + + public AuthorizationUrlBuilder state(String state) { + this.state = state; + return this; + } + + public AuthorizationUrlBuilder additionalParams(Map additionalParams) { + this.additionalParams = additionalParams; + return this; + } + + public AuthorizationUrlBuilder pkce(PKCE pkce) { + this.pkce = pkce; + return this; + } + + public AuthorizationUrlBuilder initPKCE() { + this.pkce = PKCEService.defaultInstance().generatePKCE(); + return this; + } + + public AuthorizationUrlBuilder scope(String scope) { + this.scope = scope; + return this; + } + + public PKCE getPkce() { + return pkce; + } + + public String build() { + final Map params; + if (pkce == null) { + params = additionalParams; + } else { + params = additionalParams == null ? new HashMap() : new HashMap<>(additionalParams); + params.putAll(pkce.getAuthorizationUrlParams()); + } + return oauth20Service.getApi().getAuthorizationUrl(oauth20Service.getResponseType(), oauth20Service.getApiKey(), + oauth20Service.getCallback(), scope == null ? oauth20Service.getDefaultScope() : scope, state, params); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 2b85f7b47..2d571f9cc 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -15,8 +15,6 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.pkce.AuthorizationUrlWithPKCE; import com.github.scribejava.core.pkce.PKCE; -import com.github.scribejava.core.pkce.PKCEService; -import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutionException; import com.github.scribejava.core.revoke.TokenTypeHint; @@ -63,14 +61,36 @@ public Future getAccessTokenAsync(String code) { return getAccessToken(code, null, null); } + /** + * @param code code + * @param pkceCodeVerifier pkceCodeVerifier + * @return future + * @deprecated use {@link #getAccessTokenAsync(com.github.scribejava.core.oauth.AccessTokenRequestParams) } + */ + @Deprecated public Future getAccessTokenAsync(String code, String pkceCodeVerifier) { return getAccessToken(code, null, pkceCodeVerifier); } + public Future getAccessTokenAsync(AccessTokenRequestParams params) { + return getAccessToken(params, null); + } + public OAuth2AccessToken getAccessToken(String code) throws IOException, InterruptedException, ExecutionException { return getAccessToken(code, (String) null); } + /** + * @param code code + * @param pkceCodeVerifier pkceCodeVerifier + * @return token + * @throws IOException IOException + * @throws InterruptedException InterruptedException + * @throws ExecutionException ExecutionException + * + * @deprecated use {@link #getAccessToken(com.github.scribejava.core.oauth.AccessTokenRequestParams) } + */ + @Deprecated public OAuth2AccessToken getAccessToken(String code, String pkceCodeVerifier) throws IOException, InterruptedException, ExecutionException { final OAuthRequest request = createAccessTokenRequest(code, pkceCodeVerifier); @@ -78,15 +98,34 @@ public OAuth2AccessToken getAccessToken(String code, String pkceCodeVerifier) return sendAccessTokenRequestSync(request); } + public OAuth2AccessToken getAccessToken(AccessTokenRequestParams params) + throws IOException, InterruptedException, ExecutionException { + return sendAccessTokenRequestSync(createAccessTokenRequest(params)); + } + /** * Start the request to retrieve the access token. The optionally provided callback will be called with the Token * when it is available. * - * @param code code + * @param params params * @param callback optional callback - * @param pkceCodeVerifier pkce Code Verifier * @return Future */ + public Future getAccessToken(AccessTokenRequestParams params, + OAuthAsyncRequestCallback callback) { + return sendAccessTokenRequestAsync(createAccessTokenRequest(params), callback); + } + + /** + * @param code code + * @param callback callback + * @param pkceCodeVerifier pkceCodeVerifier + * @return future + * + * @deprecated use {@link #getAccessToken(com.github.scribejava.core.oauth.AccessTokenRequestParams, + * com.github.scribejava.core.model.OAuthAsyncRequestCallback) } + */ + @Deprecated public Future getAccessToken(String code, OAuthAsyncRequestCallback callback, String pkceCodeVerifier) { final OAuthRequest request = createAccessTokenRequest(code, pkceCodeVerifier); @@ -100,25 +139,49 @@ public Future getAccessToken(String code, return getAccessToken(code, callback, null); } + /** + * @param code code + * @return request + * + * @deprecated use {@link #createAccessTokenRequest(com.github.scribejava.core.oauth.AccessTokenRequestParams)} + */ + @Deprecated protected OAuthRequest createAccessTokenRequest(String code) { + return createAccessTokenRequest(AccessTokenRequestParams.create(code)); + } + + /** + * + * @param code code + * @param pkceCodeVerifier pkceCodeVerifier + * @return request + * + * @deprecated use {@link #createAccessTokenRequest(com.github.scribejava.core.oauth.AccessTokenRequestParams)} + */ + @Deprecated + protected OAuthRequest createAccessTokenRequest(String code, String pkceCodeVerifier) { + return createAccessTokenRequest(AccessTokenRequestParams.create(code).pkceCodeVerifier(pkceCodeVerifier)); + } + + protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); - request.addParameter(OAuthConstants.CODE, code); + request.addParameter(OAuthConstants.CODE, params.getCode()); final String callback = getCallback(); if (callback != null) { request.addParameter(OAuthConstants.REDIRECT_URI, callback); } - if (defaultScope != null) { + final String scope = params.getScope(); + if (scope != null) { + request.addParameter(OAuthConstants.SCOPE, scope); + } else if (defaultScope != null) { request.addParameter(OAuthConstants.SCOPE, defaultScope); } request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); - return request; - } - protected OAuthRequest createAccessTokenRequest(String code, String pkceCodeVerifier) { - final OAuthRequest request = createAccessTokenRequest(code); + final String pkceCodeVerifier = params.getPkceCodeVerifier(); if (pkceCodeVerifier != null) { request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); } @@ -126,7 +189,11 @@ protected OAuthRequest createAccessTokenRequest(String code, String pkceCodeVeri } public Future refreshAccessTokenAsync(String refreshToken) { - return refreshAccessToken(refreshToken, null); + return refreshAccessToken(refreshToken, (OAuthAsyncRequestCallback) null); + } + + public Future refreshAccessTokenAsync(String refreshToken, String scope) { + return refreshAccessToken(refreshToken, scope, null); } public OAuth2AccessToken refreshAccessToken(String refreshToken) @@ -136,6 +203,13 @@ public OAuth2AccessToken refreshAccessToken(String refreshToken) return sendAccessTokenRequestSync(request); } + public OAuth2AccessToken refreshAccessToken(String refreshToken, String scope) + throws IOException, InterruptedException, ExecutionException { + final OAuthRequest request = createRefreshTokenRequest(refreshToken, scope); + + return sendAccessTokenRequestSync(request); + } + public Future refreshAccessToken(String refreshToken, OAuthAsyncRequestCallback callback) { final OAuthRequest request = createRefreshTokenRequest(refreshToken); @@ -143,7 +217,25 @@ public Future refreshAccessToken(String refreshToken, return sendAccessTokenRequestAsync(request, callback); } + public Future refreshAccessToken(String refreshToken, String scope, + OAuthAsyncRequestCallback callback) { + final OAuthRequest request = createRefreshTokenRequest(refreshToken, scope); + + return sendAccessTokenRequestAsync(request, callback); + } + + /** + * @param refreshToken refreshToken + * @return request + * + * @deprecated use {@link #createRefreshTokenRequest(java.lang.String, java.lang.String) } + */ + @Deprecated protected OAuthRequest createRefreshTokenRequest(String refreshToken) { + return createRefreshTokenRequest(refreshToken, null); + } + + protected OAuthRequest createRefreshTokenRequest(String refreshToken, String scope) { if (refreshToken == null || refreshToken.isEmpty()) { throw new IllegalArgumentException("The refreshToken cannot be null or empty"); } @@ -151,7 +243,9 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken) { api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); - if (defaultScope != null) { + if (scope != null) { + request.addParameter(OAuthConstants.SCOPE, scope); + } else if (defaultScope != null) { request.addParameter(OAuthConstants.SCOPE, defaultScope); } @@ -167,8 +261,19 @@ public OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String passwo return sendAccessTokenRequestSync(request); } + public OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String password, String scope) + throws IOException, InterruptedException, ExecutionException { + final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password, scope); + + return sendAccessTokenRequestSync(request); + } + public Future getAccessTokenPasswordGrantAsync(String uname, String password) { - return getAccessTokenPasswordGrantAsync(uname, password, null); + return getAccessTokenPasswordGrantAsync(uname, password, (OAuthAsyncRequestCallback) null); + } + + public Future getAccessTokenPasswordGrantAsync(String uname, String password, String scope) { + return getAccessTokenPasswordGrantAsync(uname, password, scope, null); } /** @@ -186,12 +291,35 @@ public Future getAccessTokenPasswordGrantAsync(String uname, return sendAccessTokenRequestAsync(request, callback); } + public Future getAccessTokenPasswordGrantAsync(String uname, String password, String scope, + OAuthAsyncRequestCallback callback) { + final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password, scope); + + return sendAccessTokenRequestAsync(request, callback); + } + + /** + * + * @param username username + * @param password password + * @return request + * + * @deprecated use {@link #createAccessTokenPasswordGrantRequest(java.lang.String, java.lang.String, + * java.lang.String) } + */ + @Deprecated protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, String password) { + return createAccessTokenPasswordGrantRequest(username, password, null); + } + + protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, String password, String scope) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); request.addParameter(OAuthConstants.USERNAME, username); request.addParameter(OAuthConstants.PASSWORD, password); - if (defaultScope != null) { + if (scope != null) { + request.addParameter(OAuthConstants.SCOPE, scope); + } else if (defaultScope != null) { request.addParameter(OAuthConstants.SCOPE, defaultScope); } @@ -203,7 +331,11 @@ protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, St } public Future getAccessTokenClientCredentialsGrantAsync() { - return getAccessTokenClientCredentialsGrant(null); + return getAccessTokenClientCredentialsGrant((OAuthAsyncRequestCallback) null); + } + + public Future getAccessTokenClientCredentialsGrantAsync(String scope) { + return getAccessTokenClientCredentialsGrant(scope, null); } public OAuth2AccessToken getAccessTokenClientCredentialsGrant() @@ -213,6 +345,13 @@ public OAuth2AccessToken getAccessTokenClientCredentialsGrant() return sendAccessTokenRequestSync(request); } + public OAuth2AccessToken getAccessTokenClientCredentialsGrant(String scope) + throws IOException, InterruptedException, ExecutionException { + final OAuthRequest request = createAccessTokenClientCredentialsGrantRequest(scope); + + return sendAccessTokenRequestSync(request); + } + /** * Start the request to retrieve the access token using client-credentials grant. The optionally provided callback * will be called with the Token when it is available. @@ -227,12 +366,31 @@ public Future getAccessTokenClientCredentialsGrant( return sendAccessTokenRequestAsync(request, callback); } + public Future getAccessTokenClientCredentialsGrant(String scope, + OAuthAsyncRequestCallback callback) { + final OAuthRequest request = createAccessTokenClientCredentialsGrantRequest(scope); + + return sendAccessTokenRequestAsync(request, callback); + } + + /** + * @return request + * + * @deprecated use {@link #createAccessTokenClientCredentialsGrantRequest(java.lang.String) } + */ + @Deprecated protected OAuthRequest createAccessTokenClientCredentialsGrantRequest() { + return createAccessTokenClientCredentialsGrantRequest(null); + } + + protected OAuthRequest createAccessTokenClientCredentialsGrantRequest(String scope) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); - if (defaultScope != null) { + if (scope != null) { + request.addParameter(OAuthConstants.SCOPE, scope); + } else if (defaultScope != null) { request.addParameter(OAuthConstants.SCOPE, defaultScope); } request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.CLIENT_CREDENTIALS); @@ -255,21 +413,64 @@ public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { signRequest(accessToken == null ? null : accessToken.getAccessToken(), request); } + /** + * @return AuthorizationUrlWithPKCE + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} + */ + @Deprecated public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE() { - return getAuthorizationUrlWithPKCE(null, null); + final AuthorizationUrlBuilder authorizationUrlBuilder = createAuthorizationUrlBuilder() + .initPKCE(); + + return new AuthorizationUrlWithPKCE(authorizationUrlBuilder.getPkce(), authorizationUrlBuilder.build()); } + /** + * @param state state + * @return AuthorizationUrlWithPKCE + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} + */ + @Deprecated public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state) { - return getAuthorizationUrlWithPKCE(state, null); + final AuthorizationUrlBuilder authorizationUrlBuilder = createAuthorizationUrlBuilder() + .state(state) + .initPKCE(); + + return new AuthorizationUrlWithPKCE(authorizationUrlBuilder.getPkce(), authorizationUrlBuilder.build()); } + /** + * @param additionalParams additionalParams + * @return AuthorizationUrlWithPKCE + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} + */ + @Deprecated public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(Map additionalParams) { - return getAuthorizationUrlWithPKCE(null, additionalParams); + final AuthorizationUrlBuilder authorizationUrlBuilder = createAuthorizationUrlBuilder() + .additionalParams(additionalParams) + .initPKCE(); + + return new AuthorizationUrlWithPKCE(authorizationUrlBuilder.getPkce(), authorizationUrlBuilder.build()); } + /** + * @param state state + * @param additionalParams additionalParams + * @return AuthorizationUrlWithPKCE + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} + */ + @Deprecated public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state, Map additionalParams) { - final PKCE pkce = PKCEService.defaultInstance().generatePKCE(); - return new AuthorizationUrlWithPKCE(pkce, getAuthorizationUrl(state, additionalParams, pkce)); + final AuthorizationUrlBuilder authorizationUrlBuilder = createAuthorizationUrlBuilder() + .state(state) + .additionalParams(additionalParams) + .initPKCE(); + + return new AuthorizationUrlWithPKCE(authorizationUrlBuilder.getPkce(), authorizationUrlBuilder.build()); } /** @@ -278,11 +479,13 @@ public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state, Map additionalParams) { - return getAuthorizationUrl(null, additionalParams); + return createAuthorizationUrlBuilder() + .additionalParams(additionalParams) + .build(); } + /** + * + * @param state state + * @param additionalParams additionalParams + * @return url + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} + */ + @Deprecated public String getAuthorizationUrl(String state, Map additionalParams) { - return getAuthorizationUrl(state, additionalParams, null); + return createAuthorizationUrlBuilder() + .state(state) + .additionalParams(additionalParams) + .build(); } public String getAuthorizationUrl(PKCE pkce) { - return getAuthorizationUrl(null, null, pkce); + return createAuthorizationUrlBuilder() + .pkce(pkce) + .build(); } + /** + * @param state state + * @param pkce pkce + * @return url + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} + */ + @Deprecated public String getAuthorizationUrl(String state, PKCE pkce) { - return getAuthorizationUrl(state, null, pkce); + return createAuthorizationUrlBuilder() + .state(state) + .pkce(pkce) + .build(); } + /** + * @param additionalParams additionalParams + * @param pkce pkce + * @return url + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} + */ + @Deprecated public String getAuthorizationUrl(Map additionalParams, PKCE pkce) { - return getAuthorizationUrl(null, additionalParams, pkce); + return createAuthorizationUrlBuilder() + .additionalParams(additionalParams) + .pkce(pkce) + .build(); } + /** + * + * @param state state + * @param additionalParams additionalParams + * @param pkce pkce + * @return url + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} + */ + @Deprecated public String getAuthorizationUrl(String state, Map additionalParams, PKCE pkce) { - final Map params; - if (pkce == null) { - params = additionalParams; - } else { - params = additionalParams == null ? new HashMap() : new HashMap<>(additionalParams); - params.putAll(pkce.getAuthorizationUrlParams()); - } - return api.getAuthorizationUrl(getResponseType(), getApiKey(), getCallback(), defaultScope, state, params); + return createAuthorizationUrlBuilder() + .state(state) + .additionalParams(additionalParams) + .pkce(pkce) + .build(); + } + + public AuthorizationUrlBuilder createAuthorizationUrlBuilder() { + return new AuthorizationUrlBuilder(this); } public DefaultApi20 getApi() { @@ -406,4 +658,8 @@ public OAuth2Authorization extractAuthorization(String redirectLocation) { public String getResponseType() { return responseType; } + + public String getDefaultScope() { + return defaultScope; + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java index 101f82f10..3dc1f345c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java @@ -1,21 +1,52 @@ package com.github.scribejava.core.pkce; +import com.github.scribejava.core.oauth.AuthorizationUrlBuilder; + +/** + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} and it's methods
    + * {@link AuthorizationUrlBuilder#getPkce()} and {@link AuthorizationUrlBuilder#build()} + * + */ +@Deprecated public class AuthorizationUrlWithPKCE { private final PKCE pkce; private final String authorizationUrl; + /** + * + * @param pkce pkce + * @param authorizationUrl authorizationUrl + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} and it's methods
    + * {@link AuthorizationUrlBuilder#getPkce()} and {@link AuthorizationUrlBuilder#build()} + */ + @Deprecated public AuthorizationUrlWithPKCE(PKCE pkce, String authorizationUrl) { this.pkce = pkce; this.authorizationUrl = authorizationUrl; } + /** + * @return pkce + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} and it's method
    + * {@link AuthorizationUrlBuilder#getPkce()} + */ + @Deprecated public PKCE getPkce() { return pkce; } + /** + * + * @return url + * + * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} and it's method
    + * {@link AuthorizationUrlBuilder#build()} + */ + @Deprecated public String getAuthorizationUrl() { return authorizationUrl; } - } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java index 1f1983092..297c37894 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java @@ -52,7 +52,7 @@ public void shouldProduceCorrectRequestAsync() throws ExecutionException, Interr .apiSecret("your_api_secret") .build(new OAuth20ApiUnit()); - final OAuth2AccessToken token = service.getAccessTokenPasswordGrantAsync("user1", "password1", null).get(); + final OAuth2AccessToken token = service.getAccessTokenPasswordGrantAsync("user1", "password1").get(); final Gson json = new Gson(); assertNotNull(token); From c62fae68654c10f69c6e2adf0dbb948af522164d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Mar 2019 18:05:55 +0300 Subject: [PATCH 190/481] upgrade Facebook API from 2.11 to 3.2 --- changelog | 1 + .../src/main/java/com/github/scribejava/apis/FacebookApi.java | 2 +- .../scribejava/apis/examples/FacebookAsyncApacheExample.java | 2 +- .../scribejava/apis/examples/FacebookAsyncNingExample.java | 2 +- .../com/github/scribejava/apis/examples/FacebookExample.java | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/changelog b/changelog index ccce51b79..bcdc2babe 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * separate OAuth1.0a and OAuth2.0 ServiceBuilders, introduce AuthorizationUrlBuilder (along with deprecation of AuthorizationUrlWithPKCE) add possibility to provide different scopes for each Access Token request + * upgrade Facebook API from v2.11 to v3.2 [6.4.1] * support TLS 1.3 in JDK 11 for Salesforce diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index f41c801e1..a7d81e8b1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -19,7 +19,7 @@ public class FacebookApi extends DefaultApi20 { private final String version; protected FacebookApi() { - this("2.11"); + this("3.2"); } protected FacebookApi(String version) { diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java index c98c00eba..94e14e015 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java @@ -16,7 +16,7 @@ public class FacebookAsyncApacheExample { private static final String NETWORK_NAME = "Facebook"; - private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.11/me"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v3.2/me"; private FacebookAsyncApacheExample() { } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index 1d7e38576..fa42a2332 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -17,7 +17,7 @@ public class FacebookAsyncNingExample { private static final String NETWORK_NAME = "Facebook"; - private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.11/me"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v3.2/me"; private FacebookAsyncNingExample() { } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index 071a979a3..139c01bf0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -15,7 +15,7 @@ public class FacebookExample { private static final String NETWORK_NAME = "Facebook"; - private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v2.11/me"; + private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v3.2/me"; private FacebookExample() { } From b9ad89463744408ca451849bc4787400dce54c1b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Mar 2019 18:10:18 +0300 Subject: [PATCH 191/481] upgrade VkontakteApi from 5.73 to 5.92 --- changelog | 1 + .../src/main/java/com/github/scribejava/apis/VkontakteApi.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog b/changelog index bcdc2babe..b730631ee 100644 --- a/changelog +++ b/changelog @@ -3,6 +3,7 @@ introduce AuthorizationUrlBuilder (along with deprecation of AuthorizationUrlWithPKCE) add possibility to provide different scopes for each Access Token request * upgrade Facebook API from v2.11 to v3.2 + * upgrade VkontakteApi from 5.73 to 5.92 [6.4.1] * support TLS 1.3 in JDK 11 for Salesforce diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java index 1662891c3..dfc96275b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/VkontakteApi.java @@ -12,7 +12,7 @@ public class VkontakteApi extends DefaultApi20 { - public static final String VERSION = "5.73"; + public static final String VERSION = "5.92"; protected VkontakteApi() { } From c84bf63693661b7e239e312c61abe94406d2d74c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Mar 2019 18:24:03 +0300 Subject: [PATCH 192/481] prepare v6.5.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b63986121..926d58931 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.4.1 + 6.5.0 ``` @@ -137,7 +137,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.4.1 + 6.5.0 ``` diff --git a/changelog b/changelog index b730631ee..c1d509e7c 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.5.0] * separate OAuth1.0a and OAuth2.0 ServiceBuilders, introduce AuthorizationUrlBuilder (along with deprecation of AuthorizationUrlWithPKCE) add possibility to provide different scopes for each Access Token request From fbf94b3ea0aee9684329b40c1fff10ed8ccb498d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Mar 2019 18:25:15 +0300 Subject: [PATCH 193/481] [maven-release-plugin] prepare release scribejava-6.5.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index bd17a9f31..f63433530 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.4.2-SNAPSHOT + 6.5.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.5.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 4776cb3a5..93dcbb8b8 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.2-SNAPSHOT + 6.5.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index eee982dbf..756890f9c 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.2-SNAPSHOT + 6.5.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 54682f9c5..87ac1f88a 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.2-SNAPSHOT + 6.5.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 856fb8de7..43aa61499 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.2-SNAPSHOT + 6.5.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 6028cba24..de782bc53 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.2-SNAPSHOT + 6.5.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 5640e147f..b0a0e3c38 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.4.2-SNAPSHOT + 6.5.0 ../pom.xml From ce72a8ab6350cb5160b44cbfe08ccae684a3c3fd Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 22 Mar 2019 18:25:21 +0300 Subject: [PATCH 194/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index f63433530..2d139ab8e 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.5.0 + 6.5.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.5.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 93dcbb8b8..4c0903b8f 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.0 + 6.5.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 756890f9c..caf694f86 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.0 + 6.5.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 87ac1f88a..87a926393 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.0 + 6.5.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 43aa61499..d2271c72e 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.0 + 6.5.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index de782bc53..5d62b1bc3 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.0 + 6.5.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index b0a0e3c38..6e50aadb4 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.0 + 6.5.1-SNAPSHOT ../pom.xml From c3c19f2390a08f185c40f88fee6001bfc0e7bbe4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Mar 2019 10:59:07 +0300 Subject: [PATCH 195/481] cleanup deprecates methods --- changelog | 3 + .../core/builder/ServiceBuilder.java | 12 +- .../core/builder/ServiceBuilderCommon.java | 11 - .../core/builder/ServiceBuilderOAuth10a.java | 7 - .../core/builder/ServiceBuilderOAuth20.java | 7 - .../scribejava/core/oauth/OAuth20Service.java | 272 ++---------------- .../core/pkce/AuthorizationUrlWithPKCE.java | 52 ---- 7 files changed, 27 insertions(+), 337 deletions(-) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java diff --git a/changelog b/changelog index c1d509e7c..50be9ba26 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * cleanup deprecates methods + [6.5.0] * separate OAuth1.0a and OAuth2.0 ServiceBuilders, introduce AuthorizationUrlBuilder (along with deprecation of AuthorizationUrlWithPKCE) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index fc767efb8..bbc68b571 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -51,13 +51,7 @@ public ServiceBuilder apiSecret(String apiSecret) { return this; } - /** - * @deprecated use {@link ServiceBuilderOAuth20#defaultScope(java.lang.String)} or - * {@link ServiceBuilderOAuth10a#withScope(java.lang.String)} - */ - @Override - @Deprecated - public ServiceBuilder scope(String scope) { + private ServiceBuilder setScope(String scope) { Preconditions.checkEmptyString(scope, "Invalid OAuth scope"); this.scope = scope; return this; @@ -65,12 +59,12 @@ public ServiceBuilder scope(String scope) { @Override public ServiceBuilderOAuth20 defaultScope(String defaultScope) { - return scope(defaultScope); + return setScope(defaultScope); } @Override public ServiceBuilderOAuth10a withScope(String scope) { - return scope(scope); + return setScope(scope); } @Override diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderCommon.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderCommon.java index 3babd3d56..9cddb2947 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderCommon.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderCommon.java @@ -34,17 +34,6 @@ public interface ServiceBuilderCommon { */ ServiceBuilderCommon apiSecret(String apiSecret); - /** - * Configures the OAuth scope. This is only necessary in some APIs (like Google's). - * - * @param scope The OAuth scope - * @return the {@link ServiceBuilder} instance for method chaining - * @deprecated use {@link ServiceBuilderOAuth20#defaultScope(java.lang.String)} or - * {@link ServiceBuilderOAuth10a#withScope(java.lang.String)} - */ - @Deprecated - ServiceBuilderCommon scope(String scope); - ServiceBuilderCommon httpClientConfig(HttpClientConfig httpClientConfig); /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java index d73b99af9..14323b809 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java @@ -17,13 +17,6 @@ public interface ServiceBuilderOAuth10a extends ServiceBuilderCommon { @Override ServiceBuilderOAuth20 apiSecret(String apiSecret); - /** - * @deprecated use {@link #withScope(java.lang.String) } - */ - @Override - @Deprecated - ServiceBuilderOAuth20 scope(String scope); - @Override ServiceBuilderOAuth20 httpClientConfig(HttpClientConfig httpClientConfig); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java index b7cefc475..97347959b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java @@ -16,13 +16,6 @@ public interface ServiceBuilderOAuth20 extends ServiceBuilderCommon { @Override ServiceBuilderOAuth20 apiSecret(String apiSecret); - /** - * @deprecated use {@link #defaultScope(java.lang.String) } - */ - @Override - @Deprecated - ServiceBuilderOAuth20 scope(String scope); - @Override ServiceBuilderOAuth20 httpClientConfig(HttpClientConfig httpClientConfig); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 2d571f9cc..13a3ed4ef 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -13,7 +13,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.pkce.AuthorizationUrlWithPKCE; import com.github.scribejava.core.pkce.PKCE; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -58,18 +57,7 @@ public OAuth2AccessToken convert(Response response) throws IOException { } public Future getAccessTokenAsync(String code) { - return getAccessToken(code, null, null); - } - - /** - * @param code code - * @param pkceCodeVerifier pkceCodeVerifier - * @return future - * @deprecated use {@link #getAccessTokenAsync(com.github.scribejava.core.oauth.AccessTokenRequestParams) } - */ - @Deprecated - public Future getAccessTokenAsync(String code, String pkceCodeVerifier) { - return getAccessToken(code, null, pkceCodeVerifier); + return getAccessToken(AccessTokenRequestParams.create(code), null); } public Future getAccessTokenAsync(AccessTokenRequestParams params) { @@ -77,25 +65,7 @@ public Future getAccessTokenAsync(AccessTokenRequestParams pa } public OAuth2AccessToken getAccessToken(String code) throws IOException, InterruptedException, ExecutionException { - return getAccessToken(code, (String) null); - } - - /** - * @param code code - * @param pkceCodeVerifier pkceCodeVerifier - * @return token - * @throws IOException IOException - * @throws InterruptedException InterruptedException - * @throws ExecutionException ExecutionException - * - * @deprecated use {@link #getAccessToken(com.github.scribejava.core.oauth.AccessTokenRequestParams) } - */ - @Deprecated - public OAuth2AccessToken getAccessToken(String code, String pkceCodeVerifier) - throws IOException, InterruptedException, ExecutionException { - final OAuthRequest request = createAccessTokenRequest(code, pkceCodeVerifier); - - return sendAccessTokenRequestSync(request); + return getAccessToken(AccessTokenRequestParams.create(code)); } public OAuth2AccessToken getAccessToken(AccessTokenRequestParams params) @@ -116,51 +86,9 @@ public Future getAccessToken(AccessTokenRequestParams params, return sendAccessTokenRequestAsync(createAccessTokenRequest(params), callback); } - /** - * @param code code - * @param callback callback - * @param pkceCodeVerifier pkceCodeVerifier - * @return future - * - * @deprecated use {@link #getAccessToken(com.github.scribejava.core.oauth.AccessTokenRequestParams, - * com.github.scribejava.core.model.OAuthAsyncRequestCallback) } - */ - @Deprecated - public Future getAccessToken(String code, OAuthAsyncRequestCallback callback, - String pkceCodeVerifier) { - final OAuthRequest request = createAccessTokenRequest(code, pkceCodeVerifier); - - return sendAccessTokenRequestAsync(request, callback); - } - public Future getAccessToken(String code, OAuthAsyncRequestCallback callback) { - - return getAccessToken(code, callback, null); - } - - /** - * @param code code - * @return request - * - * @deprecated use {@link #createAccessTokenRequest(com.github.scribejava.core.oauth.AccessTokenRequestParams)} - */ - @Deprecated - protected OAuthRequest createAccessTokenRequest(String code) { - return createAccessTokenRequest(AccessTokenRequestParams.create(code)); - } - - /** - * - * @param code code - * @param pkceCodeVerifier pkceCodeVerifier - * @return request - * - * @deprecated use {@link #createAccessTokenRequest(com.github.scribejava.core.oauth.AccessTokenRequestParams)} - */ - @Deprecated - protected OAuthRequest createAccessTokenRequest(String code, String pkceCodeVerifier) { - return createAccessTokenRequest(AccessTokenRequestParams.create(code).pkceCodeVerifier(pkceCodeVerifier)); + return getAccessToken(AccessTokenRequestParams.create(code), callback); } protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) { @@ -198,7 +126,7 @@ public Future refreshAccessTokenAsync(String refreshToken, St public OAuth2AccessToken refreshAccessToken(String refreshToken) throws IOException, InterruptedException, ExecutionException { - final OAuthRequest request = createRefreshTokenRequest(refreshToken); + final OAuthRequest request = createRefreshTokenRequest(refreshToken, null); return sendAccessTokenRequestSync(request); } @@ -212,7 +140,7 @@ public OAuth2AccessToken refreshAccessToken(String refreshToken, String scope) public Future refreshAccessToken(String refreshToken, OAuthAsyncRequestCallback callback) { - final OAuthRequest request = createRefreshTokenRequest(refreshToken); + final OAuthRequest request = createRefreshTokenRequest(refreshToken, null); return sendAccessTokenRequestAsync(request, callback); } @@ -224,17 +152,6 @@ public Future refreshAccessToken(String refreshToken, String return sendAccessTokenRequestAsync(request, callback); } - /** - * @param refreshToken refreshToken - * @return request - * - * @deprecated use {@link #createRefreshTokenRequest(java.lang.String, java.lang.String) } - */ - @Deprecated - protected OAuthRequest createRefreshTokenRequest(String refreshToken) { - return createRefreshTokenRequest(refreshToken, null); - } - protected OAuthRequest createRefreshTokenRequest(String refreshToken, String scope) { if (refreshToken == null || refreshToken.isEmpty()) { throw new IllegalArgumentException("The refreshToken cannot be null or empty"); @@ -254,64 +171,51 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken, String sco return request; } - public OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String password) + public OAuth2AccessToken getAccessTokenPasswordGrant(String username, String password) throws IOException, InterruptedException, ExecutionException { - final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password); + final OAuthRequest request = createAccessTokenPasswordGrantRequest(username, password, null); return sendAccessTokenRequestSync(request); } - public OAuth2AccessToken getAccessTokenPasswordGrant(String uname, String password, String scope) + public OAuth2AccessToken getAccessTokenPasswordGrant(String username, String password, String scope) throws IOException, InterruptedException, ExecutionException { - final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password, scope); + final OAuthRequest request = createAccessTokenPasswordGrantRequest(username, password, scope); return sendAccessTokenRequestSync(request); } - public Future getAccessTokenPasswordGrantAsync(String uname, String password) { - return getAccessTokenPasswordGrantAsync(uname, password, (OAuthAsyncRequestCallback) null); + public Future getAccessTokenPasswordGrantAsync(String username, String password) { + return getAccessTokenPasswordGrantAsync(username, password, + (OAuthAsyncRequestCallback) null); } - public Future getAccessTokenPasswordGrantAsync(String uname, String password, String scope) { - return getAccessTokenPasswordGrantAsync(uname, password, scope, null); + public Future getAccessTokenPasswordGrantAsync(String username, String password, String scope) { + return getAccessTokenPasswordGrantAsync(username, password, scope, null); } /** * Request Access Token Password Grant async version * - * @param uname User name + * @param username User name * @param password User password * @param callback Optional callback * @return Future */ - public Future getAccessTokenPasswordGrantAsync(String uname, String password, + public Future getAccessTokenPasswordGrantAsync(String username, String password, OAuthAsyncRequestCallback callback) { - final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password); + final OAuthRequest request = createAccessTokenPasswordGrantRequest(username, password, null); return sendAccessTokenRequestAsync(request, callback); } - public Future getAccessTokenPasswordGrantAsync(String uname, String password, String scope, + public Future getAccessTokenPasswordGrantAsync(String username, String password, String scope, OAuthAsyncRequestCallback callback) { - final OAuthRequest request = createAccessTokenPasswordGrantRequest(uname, password, scope); + final OAuthRequest request = createAccessTokenPasswordGrantRequest(username, password, scope); return sendAccessTokenRequestAsync(request, callback); } - /** - * - * @param username username - * @param password password - * @return request - * - * @deprecated use {@link #createAccessTokenPasswordGrantRequest(java.lang.String, java.lang.String, - * java.lang.String) } - */ - @Deprecated - protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, String password) { - return createAccessTokenPasswordGrantRequest(username, password, null); - } - protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, String password, String scope) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); request.addParameter(OAuthConstants.USERNAME, username); @@ -340,7 +244,7 @@ public Future getAccessTokenClientCredentialsGrantAsync(Strin public OAuth2AccessToken getAccessTokenClientCredentialsGrant() throws IOException, InterruptedException, ExecutionException { - final OAuthRequest request = createAccessTokenClientCredentialsGrantRequest(); + final OAuthRequest request = createAccessTokenClientCredentialsGrantRequest(null); return sendAccessTokenRequestSync(request); } @@ -361,7 +265,7 @@ public OAuth2AccessToken getAccessTokenClientCredentialsGrant(String scope) */ public Future getAccessTokenClientCredentialsGrant( OAuthAsyncRequestCallback callback) { - final OAuthRequest request = createAccessTokenClientCredentialsGrantRequest(); + final OAuthRequest request = createAccessTokenClientCredentialsGrantRequest(null); return sendAccessTokenRequestAsync(request, callback); } @@ -373,16 +277,6 @@ public Future getAccessTokenClientCredentialsGrant(String sco return sendAccessTokenRequestAsync(request, callback); } - /** - * @return request - * - * @deprecated use {@link #createAccessTokenClientCredentialsGrantRequest(java.lang.String) } - */ - @Deprecated - protected OAuthRequest createAccessTokenClientCredentialsGrantRequest() { - return createAccessTokenClientCredentialsGrantRequest(null); - } - protected OAuthRequest createAccessTokenClientCredentialsGrantRequest(String scope) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); @@ -413,66 +307,6 @@ public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { signRequest(accessToken == null ? null : accessToken.getAccessToken(), request); } - /** - * @return AuthorizationUrlWithPKCE - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} - */ - @Deprecated - public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE() { - final AuthorizationUrlBuilder authorizationUrlBuilder = createAuthorizationUrlBuilder() - .initPKCE(); - - return new AuthorizationUrlWithPKCE(authorizationUrlBuilder.getPkce(), authorizationUrlBuilder.build()); - } - - /** - * @param state state - * @return AuthorizationUrlWithPKCE - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} - */ - @Deprecated - public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state) { - final AuthorizationUrlBuilder authorizationUrlBuilder = createAuthorizationUrlBuilder() - .state(state) - .initPKCE(); - - return new AuthorizationUrlWithPKCE(authorizationUrlBuilder.getPkce(), authorizationUrlBuilder.build()); - } - - /** - * @param additionalParams additionalParams - * @return AuthorizationUrlWithPKCE - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} - */ - @Deprecated - public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(Map additionalParams) { - final AuthorizationUrlBuilder authorizationUrlBuilder = createAuthorizationUrlBuilder() - .additionalParams(additionalParams) - .initPKCE(); - - return new AuthorizationUrlWithPKCE(authorizationUrlBuilder.getPkce(), authorizationUrlBuilder.build()); - } - - /** - * @param state state - * @param additionalParams additionalParams - * @return AuthorizationUrlWithPKCE - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} - */ - @Deprecated - public AuthorizationUrlWithPKCE getAuthorizationUrlWithPKCE(String state, Map additionalParams) { - final AuthorizationUrlBuilder authorizationUrlBuilder = createAuthorizationUrlBuilder() - .state(state) - .additionalParams(additionalParams) - .initPKCE(); - - return new AuthorizationUrlWithPKCE(authorizationUrlBuilder.getPkce(), authorizationUrlBuilder.build()); - } - /** * Returns the URL where you should redirect your users to authenticate your application. * @@ -500,76 +334,12 @@ public String getAuthorizationUrl(Map additionalParams) { .build(); } - /** - * - * @param state state - * @param additionalParams additionalParams - * @return url - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} - */ - @Deprecated - public String getAuthorizationUrl(String state, Map additionalParams) { - return createAuthorizationUrlBuilder() - .state(state) - .additionalParams(additionalParams) - .build(); - } - public String getAuthorizationUrl(PKCE pkce) { return createAuthorizationUrlBuilder() .pkce(pkce) .build(); } - /** - * @param state state - * @param pkce pkce - * @return url - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} - */ - @Deprecated - public String getAuthorizationUrl(String state, PKCE pkce) { - return createAuthorizationUrlBuilder() - .state(state) - .pkce(pkce) - .build(); - } - - /** - * @param additionalParams additionalParams - * @param pkce pkce - * @return url - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} - */ - @Deprecated - public String getAuthorizationUrl(Map additionalParams, PKCE pkce) { - return createAuthorizationUrlBuilder() - .additionalParams(additionalParams) - .pkce(pkce) - .build(); - } - - /** - * - * @param state state - * @param additionalParams additionalParams - * @param pkce pkce - * @return url - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} - */ - @Deprecated - public String getAuthorizationUrl(String state, Map additionalParams, PKCE pkce) { - return createAuthorizationUrlBuilder() - .state(state) - .additionalParams(additionalParams) - .pkce(pkce) - .build(); - } - public AuthorizationUrlBuilder createAuthorizationUrlBuilder() { return new AuthorizationUrlBuilder(this); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java deleted file mode 100644 index 3dc1f345c..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/AuthorizationUrlWithPKCE.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.github.scribejava.core.pkce; - -import com.github.scribejava.core.oauth.AuthorizationUrlBuilder; - -/** - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} and it's methods
    - * {@link AuthorizationUrlBuilder#getPkce()} and {@link AuthorizationUrlBuilder#build()} - * - */ -@Deprecated -public class AuthorizationUrlWithPKCE { - - private final PKCE pkce; - private final String authorizationUrl; - - /** - * - * @param pkce pkce - * @param authorizationUrl authorizationUrl - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} and it's methods
    - * {@link AuthorizationUrlBuilder#getPkce()} and {@link AuthorizationUrlBuilder#build()} - */ - @Deprecated - public AuthorizationUrlWithPKCE(PKCE pkce, String authorizationUrl) { - this.pkce = pkce; - this.authorizationUrl = authorizationUrl; - } - - /** - * @return pkce - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} and it's method
    - * {@link AuthorizationUrlBuilder#getPkce()} - */ - @Deprecated - public PKCE getPkce() { - return pkce; - } - - /** - * - * @return url - * - * @deprecated use new builder pattern {@link AuthorizationUrlBuilder} and it's method
    - * {@link AuthorizationUrlBuilder#build()} - */ - @Deprecated - public String getAuthorizationUrl() { - return authorizationUrl; - } -} From dd388df2b67a3c5f07ea4a7e5e70ddc091b0c15e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Mar 2019 11:10:08 +0300 Subject: [PATCH 196/481] prepare v6.5.1 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 926d58931..bbd290e7b 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.5.0 + 6.5.1 ``` @@ -137,7 +137,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.5.0 + 6.5.1 ``` diff --git a/changelog b/changelog index 50be9ba26..c2f35d34b 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.5.1] * cleanup deprecates methods [6.5.0] From 3f4152e84884f521b409fb139ac0520e6c4e01b9 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Mar 2019 11:11:27 +0300 Subject: [PATCH 197/481] [maven-release-plugin] prepare release scribejava-6.5.1 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 2d139ab8e..1d1637a3e 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.5.1-SNAPSHOT + 6.5.1 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.5.1 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 4c0903b8f..3b44fbcde 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1-SNAPSHOT + 6.5.1 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index caf694f86..749182377 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1-SNAPSHOT + 6.5.1 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 87a926393..09ce718db 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1-SNAPSHOT + 6.5.1 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index d2271c72e..ad7f3c722 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1-SNAPSHOT + 6.5.1 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 5d62b1bc3..17772e414 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1-SNAPSHOT + 6.5.1 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 6e50aadb4..3f02c3f28 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1-SNAPSHOT + 6.5.1 ../pom.xml From ebf67e068906c5b3d78d93ce193811a5dd6df527 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 25 Mar 2019 11:13:17 +0300 Subject: [PATCH 198/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 1d1637a3e..e6fa72440 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.5.1 + 6.5.2-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.5.1 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 3b44fbcde..fbcbf7f41 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1 + 6.5.2-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 749182377..61cf7df26 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1 + 6.5.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 09ce718db..f3de40bc2 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1 + 6.5.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index ad7f3c722..02b290379 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1 + 6.5.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 17772e414..185088deb 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1 + 6.5.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 3f02c3f28..d18c6f9e2 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.1 + 6.5.2-SNAPSHOT ../pom.xml From 7301f7abf9b846473eedfe59f07f098e4c342574 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 27 Mar 2019 15:02:29 +0300 Subject: [PATCH 199/481] introduce PMD check --- changelog | 3 ++ pmd.xml | 11 ++++ pom.xml | 51 ++++++++++++++++++- .../core/oauth/OAuth20ServiceTest.java | 4 +- 4 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 pmd.xml diff --git a/changelog b/changelog index c2f35d34b..6e6bb1221 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * add PMD checks on compile + [6.5.1] * cleanup deprecates methods diff --git a/pmd.xml b/pmd.xml new file mode 100644 index 000000000..1a866a686 --- /dev/null +++ b/pmd.xml @@ -0,0 +1,11 @@ + + + + + This ruleset defines the PMD rules for project "ScribeJava". + + + diff --git a/pom.xml b/pom.xml index e6fa72440..506ba5237 100644 --- a/pom.xml +++ b/pom.xml @@ -147,7 +147,7 @@ 3.8.0 UTF-8 - 7 + ${java.release} true
    @@ -225,9 +225,58 @@ + + org.apache.maven.plugins + maven-pmd-plugin + 3.11.0 + + + net.sourceforge.pmd + pmd-core + ${pmdVersion} + + + net.sourceforge.pmd + pmd-java + ${pmdVersion} + + + net.sourceforge.pmd + pmd-javascript + ${pmdVersion} + + + net.sourceforge.pmd + pmd-jsp + ${pmdVersion} + + + + 1.${java.release} + false + + ../pmd.xml + + true + true + true + + + + + check + + + + + + 7 + 6.12.0 + + release-sign-artifacts diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java index 297c37894..b876d2d87 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java @@ -39,7 +39,7 @@ public void shouldProduceCorrectRequestSync() throws IOException, InterruptedExc final String authorize = base64Encoder.encodeToString( String.format("%s:%s", service.getApiKey(), service.getApiSecret()).getBytes(Charset.forName("UTF-8"))); - assertEquals(OAuthConstants.BASIC + " " + authorize, map.get(OAuthConstants.HEADER)); + assertEquals(OAuthConstants.BASIC + ' ' + authorize, map.get(OAuthConstants.HEADER)); assertEquals("user1", map.get("query-username")); assertEquals("password1", map.get("query-password")); @@ -65,7 +65,7 @@ public void shouldProduceCorrectRequestAsync() throws ExecutionException, Interr final String authorize = base64Encoder.encodeToString( String.format("%s:%s", service.getApiKey(), service.getApiSecret()).getBytes(Charset.forName("UTF-8"))); - assertEquals(OAuthConstants.BASIC + " " + authorize, map.get(OAuthConstants.HEADER)); + assertEquals(OAuthConstants.BASIC + ' ' + authorize, map.get(OAuthConstants.HEADER)); assertEquals("user1", map.get("query-username")); assertEquals("password1", map.get("query-password")); From 2afba057c55183d2c96a1a321766d5a81b6bece6 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 27 Mar 2019 15:54:53 +0300 Subject: [PATCH 200/481] introduce PMD/category/java/bestpractices.xml/AvoidPrintStackTrace rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 1a866a686..54150437d 100644 --- a/pmd.xml +++ b/pmd.xml @@ -8,4 +8,5 @@ This ruleset defines the PMD rules for project "ScribeJava". + From 8b27ee63075235d1e9f257bc357adf2afda2908d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 27 Mar 2019 17:44:02 +0300 Subject: [PATCH 201/481] introduce PMD/category/java/bestpractices.xml/MissingOverride rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 54150437d..1a576a8ec 100644 --- a/pmd.xml +++ b/pmd.xml @@ -9,4 +9,5 @@ + From f70aaa3cff0d4337aef8bedbf744b042c9cd05aa Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 27 Mar 2019 17:54:31 +0300 Subject: [PATCH 202/481] introduce PMD/category/java/bestpractices.xml/OneDeclarationPerLine rule --- pmd.xml | 5 +++++ .../main/java/com/github/scribejava/core/java8/Base64.java | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pmd.xml b/pmd.xml index 1a576a8ec..aff50648c 100644 --- a/pmd.xml +++ b/pmd.xml @@ -10,4 +10,9 @@ + + + true + + diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java index 6da66f9de..59d1fdc2b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java @@ -566,7 +566,8 @@ public ByteBuffer decode(ByteBuffer buffer) { int pos0 = buffer.position(); try { byte[] src; - int sp, sl; + int sp; + int sl; if (buffer.hasArray()) { src = buffer.array(); sp = buffer.arrayOffset() + buffer.position(); @@ -725,7 +726,9 @@ private int decode0(byte[] src, int sp, int sl, byte[] dst) { private static class EncOutputStream extends FilterOutputStream { private int leftover; - private int b0, b1, b2; + private int b0; + private int b1; + private int b2; private boolean closed; private final char[] base64; // byte->base64 mapping From ba20e8483e50f43535a4fccc84af2b0be97157bf Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 27 Mar 2019 18:14:04 +0300 Subject: [PATCH 203/481] introduce PMD/category/java/bestpractices.xml/SwitchStmtsShouldHaveDefault rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index aff50648c..d483fa463 100644 --- a/pmd.xml +++ b/pmd.xml @@ -15,4 +15,5 @@ true + From a53f5392e03dcf6a3795505a6055bc2edfa17f59 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 27 Mar 2019 18:41:42 +0300 Subject: [PATCH 204/481] introduce PMD/category/java/bestpractices.xml/SystemPrintln rule --- pmd.xml | 1 + .../java/com/github/scribejava/apis/examples/AWeberExample.java | 1 + .../java/com/github/scribejava/apis/examples/AsanaExample.java | 1 + .../com/github/scribejava/apis/examples/AutomaticExample.java | 1 + .../java/com/github/scribejava/apis/examples/Box20Example.java | 1 + .../com/github/scribejava/apis/examples/DataportenExample.java | 1 + .../java/com/github/scribejava/apis/examples/DiggExample.java | 1 + .../com/github/scribejava/apis/examples/DiscordExample.java | 1 + .../java/com/github/scribejava/apis/examples/EtsyExample.java | 1 + .../scribejava/apis/examples/FacebookAsyncApacheExample.java | 1 + .../scribejava/apis/examples/FacebookAsyncNingExample.java | 1 + .../com/github/scribejava/apis/examples/FacebookExample.java | 1 + .../com/github/scribejava/apis/examples/FitbitApi20Example.java | 1 + .../java/com/github/scribejava/apis/examples/FlickrExample.java | 1 + .../com/github/scribejava/apis/examples/Foursquare2Example.java | 1 + .../com/github/scribejava/apis/examples/FoursquareExample.java | 1 + .../java/com/github/scribejava/apis/examples/FrappeExample.java | 1 + .../com/github/scribejava/apis/examples/FreelancerExample.java | 1 + .../java/com/github/scribejava/apis/examples/GeniusExample.java | 1 + .../scribejava/apis/examples/GitHubAsyncOkHttpExample.java | 1 + .../java/com/github/scribejava/apis/examples/GitHubExample.java | 1 + .../scribejava/apis/examples/Google20AsyncAHCExample.java | 1 + .../com/github/scribejava/apis/examples/Google20Example.java | 1 + .../github/scribejava/apis/examples/Google20RevokeExample.java | 1 + .../scribejava/apis/examples/Google20WithPKCEExample.java | 1 + .../java/com/github/scribejava/apis/examples/HHExample.java | 1 + .../com/github/scribejava/apis/examples/HiOrgServerExample.java | 1 + .../java/com/github/scribejava/apis/examples/ImgurExample.java | 1 + .../com/github/scribejava/apis/examples/Kaixin20Example.java | 1 + .../com/github/scribejava/apis/examples/KeycloakExample.java | 1 + .../com/github/scribejava/apis/examples/LinkedIn20Example.java | 1 + .../com/github/scribejava/apis/examples/LinkedInExample.java | 1 + .../scribejava/apis/examples/LinkedInExampleWithScopes.java | 1 + .../java/com/github/scribejava/apis/examples/LiveExample.java | 1 + .../com/github/scribejava/apis/examples/MailruAsyncExample.java | 1 + .../java/com/github/scribejava/apis/examples/MailruExample.java | 1 + .../com/github/scribejava/apis/examples/MediaWikiExample.java | 1 + .../java/com/github/scribejava/apis/examples/MeetupExample.java | 1 + .../apis/examples/MicrosoftAzureActiveDirectory20Example.java | 1 + .../apis/examples/MicrosoftAzureActiveDirectoryExample.java | 1 + .../java/com/github/scribejava/apis/examples/MisfitExample.java | 1 + .../java/com/github/scribejava/apis/examples/NaverExample.java | 1 + .../github/scribejava/apis/examples/OdnoklassnikiExample.java | 1 + .../com/github/scribejava/apis/examples/PinterestExample.java | 1 + .../java/com/github/scribejava/apis/examples/Px500Example.java | 1 + .../java/com/github/scribejava/apis/examples/RenrenExample.java | 1 + .../com/github/scribejava/apis/examples/SalesforceExample.java | 1 + .../scribejava/apis/examples/SalesforceNingAsyncExample.java | 2 +- .../com/github/scribejava/apis/examples/SinaWeibo2Example.java | 1 + .../com/github/scribejava/apis/examples/SinaWeiboExample.java | 1 + .../com/github/scribejava/apis/examples/SkyrockExample.java | 1 + .../github/scribejava/apis/examples/StackExchangeExample.java | 1 + .../apis/examples/TheThingsNetworkV1StagingExample.java | 1 + .../apis/examples/TheThingsNetworkV2PreviewExample.java | 1 + .../java/com/github/scribejava/apis/examples/TrelloExample.java | 1 + .../java/com/github/scribejava/apis/examples/TumblrExample.java | 1 + .../java/com/github/scribejava/apis/examples/TutByExample.java | 1 + .../com/github/scribejava/apis/examples/TwitterExample.java | 1 + .../java/com/github/scribejava/apis/examples/UcozExample.java | 1 + .../java/com/github/scribejava/apis/examples/ViadeoExample.java | 1 + .../apis/examples/VkontakteClientCredentialsGrantExample.java | 1 + .../com/github/scribejava/apis/examples/VkontakteExample.java | 1 + .../scribejava/apis/examples/VkontakteExternalHttpExample.java | 1 + .../com/github/scribejava/apis/examples/WunderlistExample.java | 1 + .../java/com/github/scribejava/apis/examples/XingExample.java | 1 + .../com/github/scribejava/apis/examples/Yahoo20Example.java | 1 + .../java/com/github/scribejava/apis/examples/YahooExample.java | 1 + 67 files changed, 67 insertions(+), 1 deletion(-) diff --git a/pmd.xml b/pmd.xml index d483fa463..fa2527ce9 100644 --- a/pmd.xml +++ b/pmd.xml @@ -16,4 +16,5 @@ + diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index 6a35e469b..e77555d7c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -23,6 +23,7 @@ public class AWeberExample { private AWeberExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder(CONSUMER_KEY) .apiSecret(CONSUMER_SECRET) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java index c851a9e22..1c5bf684d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java @@ -20,6 +20,7 @@ public class AsanaExample { private AsanaExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final String apiKey = "your client id"; final String apiSecret = "your client secret"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java index b3375aadd..7174b0eb3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java @@ -21,6 +21,7 @@ public class AutomaticExample { private AutomaticExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index 06d7d6c57..edbbd1663 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -22,6 +22,7 @@ public class Box20Example { private Box20Example() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { //Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java index c24a596fb..1878983eb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java @@ -20,6 +20,7 @@ public class DataportenExample { private DataportenExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index a1f11b196..3b1d0ad61 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -20,6 +20,7 @@ public class DiggExample { private DiggExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "myKey"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java index ec6784b14..b574034c7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java @@ -21,6 +21,7 @@ public class DiscordExample { private DiscordExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, ExecutionException, InterruptedException { // Replace these with your client id and secret final String clientId = "client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java index d26adb59a..e39877ef6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java @@ -20,6 +20,7 @@ public class EtsyExample { private EtsyExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String[] args) throws InterruptedException, ExecutionException, IOException { // Replace with your api and secret key final OAuth10aService service = new ServiceBuilder("your api key") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java index 94e14e015..c2e55187e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java @@ -21,6 +21,7 @@ public class FacebookAsyncApacheExample { private FacebookAsyncApacheExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws InterruptedException, ExecutionException, IOException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index fa42a2332..6c9b64436 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -22,6 +22,7 @@ public class FacebookAsyncNingExample { private FacebookAsyncNingExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws InterruptedException, ExecutionException, IOException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index 139c01bf0..e4e7ca180 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -20,6 +20,7 @@ public class FacebookExample { private FacebookExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java index fcffc5f7e..0be7c1b6e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java @@ -20,6 +20,7 @@ public class FitbitApi20Example { private FitbitApi20Example() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws Exception { // Replace these with your client id and secret fron your app diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index 66ddf3fd2..5c37b1248 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -20,6 +20,7 @@ public class FlickrExample { private FlickrExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your_app_id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index aae4fe7f8..3aa3ab38b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -19,6 +19,7 @@ public class Foursquare2Example { private Foursquare2Example() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index d9ec56652..236d9b686 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -19,6 +19,7 @@ public class FoursquareExample { private FoursquareExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java index ab1138411..64751a92d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java @@ -19,6 +19,7 @@ public class FrappeExample { private FrappeExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { //Replace these with your client id and secret final String clientId = "clientId"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index 42089ae74..84cc45c2f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -23,6 +23,7 @@ public class FreelancerExample { private FreelancerExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java index 538c4cf8d..71ebfc1f9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java @@ -20,6 +20,7 @@ public class GeniusExample { private GeniusExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java index eb4f5ee2e..7559f9188 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java @@ -22,6 +22,7 @@ public class GitHubAsyncOkHttpExample { private GitHubAsyncOkHttpExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, ExecutionException, InterruptedException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index d48d7abfd..d9fa467be 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -20,6 +20,7 @@ public class GitHubExample { private GitHubExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index 3365f06c7..6dc0dc624 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -25,6 +25,7 @@ public class Google20AsyncAHCExample { private Google20AsyncAHCExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws InterruptedException, ExecutionException, IOException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 079f5670e..4b141c42b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -22,6 +22,7 @@ public class Google20Example { private Google20Example() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java index d399aa22b..9f55b43d7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java @@ -22,6 +22,7 @@ public class Google20RevokeExample { private Google20RevokeExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java index 4091215a7..b4d108430 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java @@ -24,6 +24,7 @@ public class Google20WithPKCEExample { private Google20WithPKCEExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index 0c1d24b9b..ae7cafa2d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -21,6 +21,7 @@ public class HHExample { private HHExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java index 4eb43b695..22846f21d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java @@ -23,6 +23,7 @@ public class HiOrgServerExample { private HiOrgServerExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = CLIENT_ID; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index ddc67c107..d804ed5d4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -20,6 +20,7 @@ public class ImgurExample { private ImgurExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java index dad494e49..e354722a6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -19,6 +19,7 @@ public class Kaixin20Example { private Kaixin20Example() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your api key"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java index 18569f30d..80cf06473 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java @@ -17,6 +17,7 @@ public class KeycloakExample { private KeycloakExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key, secret, callback, base url and realm final String apiKey = "your_api_key"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java index 00ab0abbf..4fa1388de 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java @@ -19,6 +19,7 @@ public class LinkedIn20Example { private LinkedIn20Example() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index 48f9fdcb5..ce7849b1d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -20,6 +20,7 @@ public class LinkedInExample { private LinkedInExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index f90f91ce0..537c06104 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -20,6 +20,7 @@ public class LinkedInExampleWithScopes { private LinkedInExampleWithScopes() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index 1bcd93cc9..fb6712b6a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -18,6 +18,7 @@ public class LiveExample { private LiveExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = ""; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index 95673747d..6fcb28be8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -22,6 +22,7 @@ public class MailruAsyncExample { private MailruAsyncExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws InterruptedException, ExecutionException, IOException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index 372bedd1a..7c7ea8161 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -20,6 +20,7 @@ public class MailruExample { private MailruExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java index 6ec9e5b67..e3a998ec8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java @@ -24,6 +24,7 @@ public class MediaWikiExample { private MediaWikiExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder(CONSUMER_KEY) .apiSecret(CONSUMER_SECRET) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index ff97a734a..62b01866a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -19,6 +19,7 @@ public class MeetupExample { private MeetupExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java index bc42d4077..b06ae03db 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java @@ -19,6 +19,7 @@ public class MicrosoftAzureActiveDirectory20Example { private MicrosoftAzureActiveDirectory20Example() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "client id here"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java index 2aa62b7b6..70dd25a94 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java @@ -21,6 +21,7 @@ private MicrosoftAzureActiveDirectoryExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "client id here"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java index e8a1437c0..309e34237 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java @@ -21,6 +21,7 @@ public class MisfitExample { private MisfitExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java index ec3e79db8..2879cb1f9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java @@ -21,6 +21,7 @@ public class NaverExample { private NaverExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index 4ff6a4933..3deb43a30 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -20,6 +20,7 @@ public class OdnoklassnikiExample { private OdnoklassnikiExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your api client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index 54d058e68..c7fd39149 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -19,6 +19,7 @@ public class PinterestExample { private PinterestExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your_app_id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index 962faaa3d..d9b6622f6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -19,6 +19,7 @@ public class Px500Example { private Px500Example() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("your-api-key") .apiSecret("your-api-secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index a3cdf3d66..61bcd5c6d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -29,6 +29,7 @@ public class RenrenExample { private RenrenExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your api key"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java index b9c65a868..43d3d91b0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -24,6 +24,7 @@ public class SalesforceExample { private SalesforceExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, NoSuchAlgorithmException, KeyManagementException, InterruptedException, ExecutionException { // Replace these with your client id and secret diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java index 66470d597..10505a804 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java @@ -27,7 +27,7 @@ public class SalesforceNingAsyncExample { private SalesforceNingAsyncExample() { } - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"unchecked", "rawtypes", "PMD.SystemPrintln"}) public static void main(String... args) throws InterruptedException, ExecutionException, UnsupportedEncodingException, IOException, NoSuchAlgorithmException, KeyManagementException { // Replace these with your client id and secret diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java index d4ff865de..a6565e7d6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -19,6 +19,7 @@ public class SinaWeibo2Example { private SinaWeibo2Example() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your_api_key"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index 618e8c881..6a95f9472 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -20,6 +20,7 @@ public class SinaWeiboExample { private SinaWeiboExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your key"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index 5751538ef..dab1f94f8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -19,6 +19,7 @@ public class SkyrockExample { private SkyrockExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("your-api-key") .apiSecret("your-api-secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index e179799e4..564dbc222 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -21,6 +21,7 @@ public class StackExchangeExample { private StackExchangeExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id, secret, application key and // optionally site name diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java index 6c88f7434..d1b8dcd09 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java @@ -22,6 +22,7 @@ public class TheThingsNetworkV1StagingExample { private TheThingsNetworkV1StagingExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your_client_id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java index 57aacac05..3c35b8be8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java @@ -22,6 +22,7 @@ public class TheThingsNetworkV2PreviewExample { private TheThingsNetworkV2PreviewExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your_client_id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index a73826a34..0909e9115 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -21,6 +21,7 @@ public class TrelloExample { private TrelloExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder(API_KEY) .apiSecret(API_SECRET) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index 6d16ef54f..5ca71b373 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -19,6 +19,7 @@ public class TumblrExample { private TumblrExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("MY_CONSUMER_KEY") .apiSecret("MY_CONSUMER_SECRET") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index 70f05e5b2..393db2a65 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -21,6 +21,7 @@ public class TutByExample { private TutByExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index 20b95531d..04d23911c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -19,6 +19,7 @@ public class TwitterExample { private TwitterExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java index dcf6e1fd5..899e2ed57 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java @@ -20,6 +20,7 @@ public class UcozExample { private UcozExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("your_api_key") .apiSecret("your_api_secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index 134faf3cc..c16bd9770 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -19,6 +19,7 @@ public class ViadeoExample { private ViadeoExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own api key and secret final String apiKey = "your_app_id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java index f9d4a4514..2b6e2d4f7 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java @@ -14,6 +14,7 @@ public class VkontakteClientCredentialsGrantExample { private VkontakteClientCredentialsGrantExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java index ca57c39f7..2c73d583d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java @@ -22,6 +22,7 @@ public class VkontakteExample { private VkontakteExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java index abdf0b397..c918633c0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java @@ -23,6 +23,7 @@ public class VkontakteExternalHttpExample { private VkontakteExternalHttpExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "your client id"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java index fd6fce936..5e9e9b52d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java @@ -21,6 +21,7 @@ public class WunderlistExample { private WunderlistExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your own values final String apiKey = "apiKey"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index 5cfd1d89d..c66ebb984 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -19,6 +19,7 @@ public class XingExample { private XingExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java index 8102b4ea3..e151e8e5b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java @@ -29,6 +29,7 @@ public class Yahoo20Example { private Yahoo20Example() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Add your personal information here final String clientId = "ADD CLIENT ID HERE!!!!"; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index b75b8a447..455624cfd 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -20,6 +20,7 @@ public class YahooExample { private YahooExample() { } + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { final OAuth10aService service = new ServiceBuilder("your client id") .apiSecret("your client secret") From 163d5c7af0d4dbb0bfa77abc91524fc633df042f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 27 Mar 2019 18:49:01 +0300 Subject: [PATCH 205/481] introduce PMD/category/java/bestpractices.xml/UnusedImports rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index fa2527ce9..8c86d5727 100644 --- a/pmd.xml +++ b/pmd.xml @@ -17,4 +17,5 @@ + From caf0bf5074f73b4c47ca9e2f8a4a4cfde65f0228 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 27 Mar 2019 19:00:47 +0300 Subject: [PATCH 206/481] introduce PMD/category/java/bestpractices.xml/UnusedLocalVariable rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 8c86d5727..ad141130a 100644 --- a/pmd.xml +++ b/pmd.xml @@ -18,4 +18,5 @@ + From a9abebf0359c2b961091f65478741b68ac19cca0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 28 Mar 2019 16:29:08 +0300 Subject: [PATCH 207/481] introduce PMD/category/java/bestpractices.xml/UseAssertNullInsteadOfAssertTrue rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index ad141130a..576bc42d6 100644 --- a/pmd.xml +++ b/pmd.xml @@ -19,4 +19,5 @@ + From 6d15798f7ce5cfc70d7fb6d78131617d34827bb9 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 28 Mar 2019 16:46:15 +0300 Subject: [PATCH 208/481] introduce PMD/category/java/bestpractices.xml/UseAssertSameInsteadOfAssertTrue rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 576bc42d6..86b4a5e42 100644 --- a/pmd.xml +++ b/pmd.xml @@ -20,4 +20,5 @@ + From 2fc64208a351b3b7ca39b735a92b5c724374d644 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 28 Mar 2019 17:05:50 +0300 Subject: [PATCH 209/481] introduce PMD/category/java/bestpractices.xml/UseAssertTrueInsteadOfAssertEquals rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 86b4a5e42..66f5f55b1 100644 --- a/pmd.xml +++ b/pmd.xml @@ -21,4 +21,5 @@ + From 9b5013a696d1f536f52f53b204daaa50bd2ff62c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 28 Mar 2019 17:17:57 +0300 Subject: [PATCH 210/481] introduce PMD/category/java/bestpractices.xml/UseCollectionIsEmpty rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 66f5f55b1..c4d0479fc 100644 --- a/pmd.xml +++ b/pmd.xml @@ -22,4 +22,5 @@ + From 04e6beea2095fd9ff0fd761ad2de4a130d428848 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 28 Mar 2019 17:25:34 +0300 Subject: [PATCH 211/481] introduce PMD/category/java/bestpractices.xml/UseTryWithResources rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index c4d0479fc..aa4bb843f 100644 --- a/pmd.xml +++ b/pmd.xml @@ -23,4 +23,5 @@ + From c722cb038d63f5132bfc07fcd682bf52ec33842c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 28 Mar 2019 19:11:58 +0300 Subject: [PATCH 212/481] introduce PMD/category/java/codestyle.xml/AvoidDollarSigns rule --- pmd.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pmd.xml b/pmd.xml index aa4bb843f..b963acb63 100644 --- a/pmd.xml +++ b/pmd.xml @@ -24,4 +24,6 @@ + + From 8d81b4c8d35bab7c5c7894bde200c0f45a7e60ea Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 28 Mar 2019 19:15:27 +0300 Subject: [PATCH 213/481] introduce PMD/category/java/codestyle.xml/AvoidProtectedFieldInFinalClass rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index b963acb63..c7cca8510 100644 --- a/pmd.xml +++ b/pmd.xml @@ -26,4 +26,5 @@ + From 12f578f75a68958e5adccfdda684bbd2b8b744fd Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 28 Mar 2019 19:20:46 +0300 Subject: [PATCH 214/481] introduce PMD/category/java/codestyle.xml/AvoidProtectedMethodInFinalClassNotExtending rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index c7cca8510..84bc910d7 100644 --- a/pmd.xml +++ b/pmd.xml @@ -27,4 +27,5 @@ + From 946bf84251579afb7cd8e382fef0e582bdb70e48 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 28 Mar 2019 19:27:08 +0300 Subject: [PATCH 215/481] introduce PMD/category/java/codestyle.xml/BooleanGetMethodName rule --- pmd.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pmd.xml b/pmd.xml index 84bc910d7..85049489a 100644 --- a/pmd.xml +++ b/pmd.xml @@ -28,4 +28,9 @@ + + + true + + From bccbc594817a60ca1ae130f778d62de37d589004 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 29 Mar 2019 17:43:17 +0300 Subject: [PATCH 216/481] introduce PMD/category/java/codestyle.xml/ControlStatementBraces rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 85049489a..722aa43e0 100644 --- a/pmd.xml +++ b/pmd.xml @@ -33,4 +33,5 @@ true + From e843492791278761adb8a142ae4c2a44d5e485f3 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 29 Mar 2019 17:46:04 +0300 Subject: [PATCH 217/481] introduce PMD/category/java/codestyle.xml/DontImportJavaLang rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 722aa43e0..abfe6fbcb 100644 --- a/pmd.xml +++ b/pmd.xml @@ -34,4 +34,5 @@ + From 47a10e21189972ce2ebef5616423a86a6f336ddc Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 29 Mar 2019 17:47:50 +0300 Subject: [PATCH 218/481] introduce PMD/category/java/codestyle.xml/DuplicateImports rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index abfe6fbcb..ee423732a 100644 --- a/pmd.xml +++ b/pmd.xml @@ -35,4 +35,5 @@ + From ea5f7ea08945fac7a65e9b857e161fbe45144112 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 29 Mar 2019 17:53:36 +0300 Subject: [PATCH 219/481] introduce PMD/category/java/codestyle.xml/ExtendsObject rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index ee423732a..4f884821d 100644 --- a/pmd.xml +++ b/pmd.xml @@ -36,4 +36,5 @@ + From d67a7a69014b0c9bf8225914020741b7a0885ec0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 29 Mar 2019 18:21:34 +0300 Subject: [PATCH 220/481] introduce PMD/category/java/codestyle.xml/FieldNamingConventions rule --- pmd.xml | 1 + .../github/scribejava/apis/FreelancerApi.java | 2 +- .../apis/fitbit/FitBitJsonTokenExtractor.java | 2 +- .../fitbit/FitBitJsonTokenExtractorTest.java | 2 +- .../core/builder/api/DefaultApi10a.java | 2 +- .../core/builder/api/OAuth1SignatureType.java | 4 ++-- .../OAuth2AccessTokenJsonExtractor.java | 2 +- .../model/OAuth2AccessTokenErrorResponse.java | 24 +++++++++++++++++-- .../core/oauth/OAuth10aService.java | 4 ++-- .../scribejava/core/oauth/OAuth20Service.java | 2 +- .../core/pkce/PKCECodeChallengeMethod.java | 2 +- .../scribejava/core/pkce/PKCEService.java | 4 ++-- .../scribejava/core/revoke/TokenTypeHint.java | 14 ++++++++++- .../OAuth2AccessTokenJsonExtractorTest.java | 2 +- 14 files changed, 50 insertions(+), 17 deletions(-) diff --git a/pmd.xml b/pmd.xml index 4f884821d..55885d489 100644 --- a/pmd.xml +++ b/pmd.xml @@ -37,4 +37,5 @@ + diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java index b5c302ffc..33844d193 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FreelancerApi.java @@ -21,7 +21,7 @@ public static FreelancerApi instance() { @Override public OAuth1SignatureType getSignatureType() { - return OAuth1SignatureType.QueryString; + return OAuth1SignatureType.QUERY_STRING; } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java index fad86fc53..3679ee14a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java @@ -39,7 +39,7 @@ public void generateError(String response) { OAuth2AccessTokenErrorResponse.ErrorCode errorCode; try { - errorCode = OAuth2AccessTokenErrorResponse.ErrorCode.valueOf(errorInString); + errorCode = OAuth2AccessTokenErrorResponse.ErrorCode.parseFrom(errorInString); } catch (IllegalArgumentException iaE) { //non oauth standard error code errorCode = null; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java index a0f5b53a3..448d5ff52 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java @@ -28,7 +28,7 @@ public void testErrorExtraction() { final FitBitJsonTokenExtractor extractor = new FitBitJsonTokenExtractor(); thrown.expect(OAuth2AccessTokenErrorResponse.class); - thrown.expect(new ErrorCodeFeatureMatcher(ErrorCode.invalid_grant)); + thrown.expect(new ErrorCodeFeatureMatcher(ErrorCode.INVALID_GRANT)); thrown.expect(new ErrorDescriptionFeatureMatcher(ERROR_DESCRIPTION)); extractor.generateError(ERROR_JSON); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java index 6bd1c9392..2ea470110 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi10a.java @@ -85,7 +85,7 @@ public SignatureService getSignatureService() { * @return the signature type, choose between header, querystring, etc. Defaults to Header */ public OAuth1SignatureType getSignatureType() { - return OAuth1SignatureType.Header; + return OAuth1SignatureType.HEADER; } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth1SignatureType.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth1SignatureType.java index 7660b5826..7de68ff7b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth1SignatureType.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/OAuth1SignatureType.java @@ -2,6 +2,6 @@ public enum OAuth1SignatureType { - Header, - QueryString + HEADER, + QUERY_STRING } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index e49831daf..a87e8ab82 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -66,7 +66,7 @@ public void generateError(String response) { OAuth2AccessTokenErrorResponse.ErrorCode errorCode; try { - errorCode = OAuth2AccessTokenErrorResponse.ErrorCode.valueOf(errorInString); + errorCode = OAuth2AccessTokenErrorResponse.ErrorCode.parseFrom(errorInString); } catch (IllegalArgumentException iaE) { //non oauth standard error code errorCode = null; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java index 86ca38d88..57ada61de 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java @@ -12,11 +12,31 @@ public class OAuth2AccessTokenErrorResponse extends OAuthException { private static final long serialVersionUID = 2309424849700276816L; public enum ErrorCode { - invalid_request, invalid_client, invalid_grant, unauthorized_client, unsupported_grant_type, invalid_scope, + INVALID_REQUEST("invalid_request"), + INVALID_CLIENT("invalid_client"), + INVALID_GRANT("invalid_grant"), + UNAUTHORIZED_CLIENT("unauthorized_client"), + UNSUPPORTED_GRANT_TYPE("unsupported_grant_type"), + INVALID_SCOPE("invalid_scope"), /** * @see RFC 7009, 2.2.1. Error Response */ - unsupported_token_type + UNSUPPORTED_TOKEN_TYPE("unsupported_token_type"); + + private final String errorCodeString; + + ErrorCode(String errorCodeString) { + this.errorCodeString = errorCodeString; + } + + public static ErrorCode parseFrom(String errorCodeString) { + for (ErrorCode errorCode : ErrorCode.values()) { + if (errorCode.errorCodeString.equals(errorCodeString)) { + return errorCode; + } + } + throw new IllegalArgumentException("there is no knowlege about '" + errorCodeString + "' ErrorCode"); + } } private final ErrorCode errorCode; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index a2dc08142..3e67bf1ad 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -171,13 +171,13 @@ private String getSignature(OAuthRequest request, String tokenSecret) { protected void appendSignature(OAuthRequest request) { final OAuth1SignatureType signatureType = api.getSignatureType(); switch (signatureType) { - case Header: + case HEADER: log("using Http Header signature"); final String oauthHeader = api.getHeaderExtractor().extract(request); request.addHeader(OAuthConstants.HEADER, oauthHeader); break; - case QueryString: + case QUERY_STRING: log("using Querystring signature"); for (Map.Entry oauthParameter : request.getOauthParameters().entrySet()) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 13a3ed4ef..df4557ea0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -355,7 +355,7 @@ protected OAuthRequest createRevokeTokenRequest(String tokenToRevoke, TokenTypeH request.addParameter("token", tokenToRevoke); if (tokenTypeHint != null) { - request.addParameter("token_type_hint", tokenTypeHint.toString()); + request.addParameter("token_type_hint", tokenTypeHint.getValue()); } return request; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java index 29648859c..08bb60c5b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java @@ -15,7 +15,7 @@ public String transform2CodeChallenge(String codeVerifier) throws NoSuchAlgorith MessageDigest.getInstance("SHA-256").digest(codeVerifier.getBytes(StandardCharsets.US_ASCII))); } }, - plain { + PLAIN { @Override public String transform2CodeChallenge(String codeVerifier) { return codeVerifier; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java index 8709174b8..eea3e7b94 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java @@ -51,9 +51,9 @@ public PKCE generatePKCE(byte[] randomBytes) { try { pkce.setCodeChallenge(pkce.getCodeChallengeMethod().transform2CodeChallenge(codeVerifier)); } catch (NoSuchAlgorithmException nsaE) { - pkce.setCodeChallengeMethod(PKCECodeChallengeMethod.plain); + pkce.setCodeChallengeMethod(PKCECodeChallengeMethod.PLAIN); try { - pkce.setCodeChallenge(PKCECodeChallengeMethod.plain.transform2CodeChallenge(codeVerifier)); + pkce.setCodeChallenge(PKCECodeChallengeMethod.PLAIN.transform2CodeChallenge(codeVerifier)); } catch (NoSuchAlgorithmException unrealE) { throw new IllegalStateException("It's just cannot be", unrealE); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java index 55a95057e..450bd691b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java @@ -8,5 +8,17 @@ * @see RFC 7009, 2.1. Revocation Request */ public enum TokenTypeHint { - access_token, refresh_token + ACCESS_TOKEN("access_token"), + REFRESH_TOKEN("refresh_token"); + + private final String value; + + TokenTypeHint(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java index 3aa80cd30..5d00d89e0 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java @@ -65,7 +65,7 @@ public void shouldThrowExceptionIfResponseIsError() throws IOException { extractor.extract(error(body)); fail(); } catch (OAuth2AccessTokenErrorResponse oaer) { - assertEquals(OAuth2AccessTokenErrorResponse.ErrorCode.invalid_grant, oaer.getErrorCode()); + assertEquals(OAuth2AccessTokenErrorResponse.ErrorCode.INVALID_GRANT, oaer.getErrorCode()); assertEquals("unknown, invalid, or expired refresh token", oaer.getErrorDescription()); } } From e4ec62a9860d2bcce48f2a175636cdc2a8a0c6d7 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 1 Apr 2019 13:38:45 +0300 Subject: [PATCH 221/481] add deprecation note for TokenTypeHint::toString method --- .../github/scribejava/core/revoke/TokenTypeHint.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java index 450bd691b..c041d3efc 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java @@ -21,4 +21,15 @@ public String getValue() { return value; } + /** + * @return value + * @deprecated use {@link #getValue() } to get a lower-cased value as in reference (RFC7009), otherwise you can + * continue using this method. Note, that returned value will be UPPER-cased (not overrided toString method) in the + * next release. + */ + @Override + @Deprecated + public String toString() { + return value; + } } From 477587fa2d4e4ee6f3ed9d257d6e594526e4a4f6 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 1 Apr 2019 13:45:36 +0300 Subject: [PATCH 222/481] introduce PMD/category/java/codestyle.xml/ForLoopShouldBeWhileLoop rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 55885d489..1bacb8f9a 100644 --- a/pmd.xml +++ b/pmd.xml @@ -38,4 +38,5 @@ + From d36c4914a667613e8e798ef722bea648c0710090 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 1 Apr 2019 15:27:18 +0300 Subject: [PATCH 223/481] introduce PMD/category/java/codestyle.xml/FormalParameterNamingConventions rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 1bacb8f9a..475b5ed13 100644 --- a/pmd.xml +++ b/pmd.xml @@ -39,4 +39,5 @@ + From 55ed61e5db9cf2d917fa1fdbe0c380c9ad6e0e9b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 1 Apr 2019 16:45:39 +0300 Subject: [PATCH 224/481] introduce PMD/category/java/codestyle.xml/IdenticalCatchBranches rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 475b5ed13..8ae744551 100644 --- a/pmd.xml +++ b/pmd.xml @@ -40,4 +40,5 @@ + From 3c5e14672d616cc0cb516e9df6b161730afa7830 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 1 Apr 2019 18:41:30 +0300 Subject: [PATCH 225/481] introduce PMD/category/java/codestyle.xml/LocalVariableNamingConventions rule --- pmd.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pmd.xml b/pmd.xml index 8ae744551..caa78ca37 100644 --- a/pmd.xml +++ b/pmd.xml @@ -28,7 +28,7 @@ - + true @@ -41,4 +41,5 @@ + From 8efe8cc585173797562a823948e902319475885f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 1 Apr 2019 18:46:44 +0300 Subject: [PATCH 226/481] introduce PMD/category/java/codestyle.xml/MethodNamingConventions rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index caa78ca37..8a3424a06 100644 --- a/pmd.xml +++ b/pmd.xml @@ -42,4 +42,5 @@ + From ba3458aa825b81b1f34c8960031f785424e5ccea Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 1 Apr 2019 18:48:59 +0300 Subject: [PATCH 227/481] introduce PMD/category/java/codestyle.xml/NoPackage rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 8a3424a06..417a99b53 100644 --- a/pmd.xml +++ b/pmd.xml @@ -43,4 +43,5 @@ + From 3c6ab96ab21469accaf4d526b33fe9d8596ad3d2 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 1 Apr 2019 18:51:15 +0300 Subject: [PATCH 228/481] introduce PMD/category/java/codestyle.xml/PackageCase rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 417a99b53..ead5d39ea 100644 --- a/pmd.xml +++ b/pmd.xml @@ -44,4 +44,5 @@ + From a1a75d0b2fce6520c81ffb62b08acb7185d24cd3 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 2 Apr 2019 19:33:33 +0300 Subject: [PATCH 229/481] introduce PMD/category/java/codestyle.xml/UnnecessaryAnnotationValueElement rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index ead5d39ea..0738453c2 100644 --- a/pmd.xml +++ b/pmd.xml @@ -45,4 +45,5 @@ + From e7dd8e5d3d15d1b16efad3d077b7817b38b21447 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 2 Apr 2019 19:44:27 +0300 Subject: [PATCH 230/481] introduce PMD/category/java/codestyle.xml/UnnecessaryConstructor rule --- pmd.xml | 1 + .../src/main/java/com/github/scribejava/apis/NaverApi.java | 3 --- .../com/github/scribejava/core/oauth/OAuth20ServiceTest.java | 4 ---- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/pmd.xml b/pmd.xml index 0738453c2..89c1cf62b 100644 --- a/pmd.xml +++ b/pmd.xml @@ -46,4 +46,5 @@ + diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java index 3ff3a9b0a..f60871735 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/NaverApi.java @@ -10,9 +10,6 @@ protected NaverApi() { private static class InstanceHolder { private static final NaverApi INSTANCE = new NaverApi(); - - private InstanceHolder() { - } } public static NaverApi instance() { diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java index b876d2d87..3590e6b5d 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java @@ -121,9 +121,5 @@ public void testOAuthExtractAuthorization() { } private static class TypeTokenImpl extends TypeToken> { - - private TypeTokenImpl() { - } } - } From d27362811eb82b35a9da30e395d805fbd6b8f918 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 3 Apr 2019 14:03:36 +0300 Subject: [PATCH 231/481] introduce PMD/category/java/codestyle.xml/UnnecessaryFullyQualifiedName rule --- pmd.xml | 1 + .../test/java/com/github/scribejava/apis/ExampleUtils.java | 2 +- .../httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pmd.xml b/pmd.xml index 89c1cf62b..998e9941d 100644 --- a/pmd.xml +++ b/pmd.xml @@ -47,4 +47,5 @@ + diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java index 195729b3c..f5917bcda 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java @@ -19,7 +19,7 @@ public static void turnOfSSl() { try { final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() { @Override - public java.security.cert.X509Certificate[] getAcceptedIssuers() { + public X509Certificate[] getAcceptedIssuers() { return null; } diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java index 863d2eee3..645c45557 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java @@ -72,7 +72,7 @@ public void shouldReleaseLatchOnSuccess() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER, future); call.enqueue(handler); - final okhttp3.Request request = new Request.Builder().url("http://localhost/").build(); + final Request request = new Request.Builder().url("http://localhost/").build(); final okhttp3.Response response = new okhttp3.Response.Builder() .request(request) .protocol(Protocol.HTTP_1_1) @@ -92,7 +92,7 @@ public void shouldReleaseLatchOnIOException() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, EXCEPTION_RESPONSE_CONVERTER, future); call.enqueue(handler); - final okhttp3.Request request = new Request.Builder().url("http://localhost/").build(); + final Request request = new Request.Builder().url("http://localhost/").build(); final okhttp3.Response response = new okhttp3.Response.Builder() .request(request) .protocol(Protocol.HTTP_1_1) @@ -118,7 +118,7 @@ public void shouldReportOAuthException() throws Exception { handler = new OAuthAsyncCompletionHandler<>(callback, OAUTH_EXCEPTION_RESPONSE_CONVERTER, future); call.enqueue(handler); - final okhttp3.Request request = new Request.Builder().url("http://localhost/").build(); + final Request request = new Request.Builder().url("http://localhost/").build(); final okhttp3.Response response = new okhttp3.Response.Builder() .request(request) .protocol(Protocol.HTTP_1_1) From 3643fc2b52ef4ec7e95481cd6c03f728dc399e6c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 3 Apr 2019 14:07:40 +0300 Subject: [PATCH 232/481] introduce PMD/category/java/codestyle.xml/UnnecessaryModifier rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 998e9941d..6abbac788 100644 --- a/pmd.xml +++ b/pmd.xml @@ -48,4 +48,5 @@ + From e49dcea29dc4913e7f2f72fc565ba408ce8a5e42 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 3 Apr 2019 14:23:42 +0300 Subject: [PATCH 233/481] introduce PMD/category/java/codestyle.xml/UnnecessaryReturn rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 6abbac788..e9b66c874 100644 --- a/pmd.xml +++ b/pmd.xml @@ -49,4 +49,5 @@ + From 91ce572f988c3b680a1c770e4e90c0bdd7f017ac Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 3 Apr 2019 14:30:05 +0300 Subject: [PATCH 234/481] introduce PMD/category/java/codestyle.xml/UselessParentheses rule --- pmd.xml | 1 + .../src/main/java/com/github/scribejava/core/java8/Base64.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pmd.xml b/pmd.xml index e9b66c874..578935a1b 100644 --- a/pmd.xml +++ b/pmd.xml @@ -50,4 +50,5 @@ + diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java index 59d1fdc2b..9e855a617 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java @@ -627,7 +627,7 @@ private int outLength(byte[] src, int sp, int sl) { while (sp < sl) { int b = src[sp++] & 0xff; if (b == '=') { - len -= (sl - sp + 1); + len -= sl - sp + 1; break; } b = base64[b]; From 91100833a34051edd2ac82cb8d1372db57ac9ac8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 3 Apr 2019 14:36:38 +0300 Subject: [PATCH 235/481] introduce PMD/category/java/codestyle.xml/UselessQualifiedThis rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 578935a1b..3383e082a 100644 --- a/pmd.xml +++ b/pmd.xml @@ -51,4 +51,5 @@ + From fbf933db419711bc4d8f7c816d19e6fb08060430 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 3 Apr 2019 14:52:11 +0300 Subject: [PATCH 236/481] introduce PMD/category/java/design.xml/AbstractClassWithoutAnyMethod rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 3383e082a..5eff22b01 100644 --- a/pmd.xml +++ b/pmd.xml @@ -52,4 +52,5 @@ + From e41c220c67b1017b8e1cf989cb306cf7c6d0c6ca Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 3 Apr 2019 14:57:47 +0300 Subject: [PATCH 237/481] introduce PMD/category/java/design.xml/AvoidThrowingNewInstanceOfSameException rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 5eff22b01..47072ed72 100644 --- a/pmd.xml +++ b/pmd.xml @@ -53,4 +53,5 @@ + From 6ba97ec3960d2d81347b8003220916c37a31ed3f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 3 Apr 2019 16:32:12 +0300 Subject: [PATCH 238/481] introduce PMD/category/java/design.xml/CollapsibleIfStatements rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 47072ed72..5765899f6 100644 --- a/pmd.xml +++ b/pmd.xml @@ -54,4 +54,5 @@ + From 0fc534b94c4d70603ad778fa425f6fa74be1a2a8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 3 Apr 2019 16:36:51 +0300 Subject: [PATCH 239/481] introduce PMD/category/java/design.xml/DoNotExtendJavaLangError rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 5765899f6..9bc405aac 100644 --- a/pmd.xml +++ b/pmd.xml @@ -55,4 +55,5 @@ + From 8362b1773212b5d6229befe58f9dc7b1f0ca2bea Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 12:41:20 +0300 Subject: [PATCH 240/481] introduce PMD/category/java/design.xml/LogicInversion rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 9bc405aac..533ab8cc6 100644 --- a/pmd.xml +++ b/pmd.xml @@ -56,4 +56,5 @@ + From 90cde591187623c68a97a0ccf6b8c0f92fd478c9 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 13:35:36 +0300 Subject: [PATCH 241/481] introduce PMD/category/java/design.xml/SimplifiedTernary rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 533ab8cc6..6716713e4 100644 --- a/pmd.xml +++ b/pmd.xml @@ -57,4 +57,5 @@ + From 054dde3f21a23771f4fba3eddd7dc0be879f3aee Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 13:53:39 +0300 Subject: [PATCH 242/481] introduce PMD/category/java/design.xml/SimplifyBooleanAssertion rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 6716713e4..fe37edaa5 100644 --- a/pmd.xml +++ b/pmd.xml @@ -58,4 +58,5 @@ + From da3a03e05b30e2c0a98ad049df003a3ea06022f1 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 13:58:07 +0300 Subject: [PATCH 243/481] introduce PMD/category/java/design.xml/SimplifyBooleanExpressions rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index fe37edaa5..e159f2538 100644 --- a/pmd.xml +++ b/pmd.xml @@ -59,4 +59,5 @@ + From 5cfa2456de32be35fa6ac32c0166e535f00aa750 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 14:16:47 +0300 Subject: [PATCH 244/481] introduce PMD/category/java/design.xml/SimplifyBooleanReturns rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index e159f2538..a0332f3d7 100644 --- a/pmd.xml +++ b/pmd.xml @@ -60,4 +60,5 @@ + From 88966d4a07832751f1a5e5634e67435ef773da2e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 14:31:24 +0300 Subject: [PATCH 245/481] introduce PMD/category/java/design.xml/SimplifyConditional rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index a0332f3d7..efd6ad411 100644 --- a/pmd.xml +++ b/pmd.xml @@ -61,4 +61,5 @@ + From 851051d6657e337e42647da9994ca5218ccecb84 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 17:06:14 +0300 Subject: [PATCH 246/481] introduce PMD/category/java/design.xml/UseUtilityClass rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index efd6ad411..ce5c6a428 100644 --- a/pmd.xml +++ b/pmd.xml @@ -62,4 +62,5 @@ + From 8d5ef48496fa8d840b969403e011ecdcb6afb1d0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 17:20:31 +0300 Subject: [PATCH 247/481] introduce PMD/category/java/errorprone.xml/AvoidAssertAsIdentifier rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index ce5c6a428..f6c5a926c 100644 --- a/pmd.xml +++ b/pmd.xml @@ -63,4 +63,5 @@ + From 26a420b536518dfa73c32fafa31465efa9e5785d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 17:39:31 +0300 Subject: [PATCH 248/481] introduce PMD/category/java/errorprone.xml/AvoidBranchingStatementAsLastInLoop rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index f6c5a926c..caec51815 100644 --- a/pmd.xml +++ b/pmd.xml @@ -64,4 +64,5 @@ + From 5c0cccbf5d74619ef6078c73183365491e494eb8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 17:51:04 +0300 Subject: [PATCH 249/481] introduce PMD/category/java/errorprone.xml/AvoidCallingFinalize rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index caec51815..3351e91b7 100644 --- a/pmd.xml +++ b/pmd.xml @@ -65,4 +65,5 @@ + From 1a4d255f9d879380b5e93bb1a3c6f4a0effcedb2 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 18:02:46 +0300 Subject: [PATCH 250/481] introduce PMD/category/java/errorprone.xml/AvoidEnumAsIdentifier rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 3351e91b7..1e3645a87 100644 --- a/pmd.xml +++ b/pmd.xml @@ -66,4 +66,5 @@ + From 6f3eb2bf9937662ce9ae73773028d745e5a5b884 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 18:17:58 +0300 Subject: [PATCH 251/481] introduce PMD/category/java/errorprone.xml/AvoidLosingExceptionInformation rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 1e3645a87..20d8a6b11 100644 --- a/pmd.xml +++ b/pmd.xml @@ -67,4 +67,5 @@ + From f1ab512e23d45e77a9d3ef089a642e5dc7f832b4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 18:26:10 +0300 Subject: [PATCH 252/481] introduce PMD/category/java/errorprone.xml/AvoidMultipleUnaryOperators rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 20d8a6b11..6c459475b 100644 --- a/pmd.xml +++ b/pmd.xml @@ -68,4 +68,5 @@ + From 224248e1a8ab11f8c9c5cac390074b7ae7fad9f5 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 18:30:02 +0300 Subject: [PATCH 253/481] introduce PMD/category/java/errorprone.xml/BrokenNullCheck rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 6c459475b..0bdcc86c2 100644 --- a/pmd.xml +++ b/pmd.xml @@ -69,4 +69,5 @@ + From 01a6e80661c5e85f779727f4d912976cf61e66c0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 18:33:10 +0300 Subject: [PATCH 254/481] introduce PMD/category/java/errorprone.xml/ClassCastExceptionWithToArray rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 0bdcc86c2..4fafa2891 100644 --- a/pmd.xml +++ b/pmd.xml @@ -70,4 +70,5 @@ + From 860e8d7a2df7bf2817bfa87bc97030c45783c721 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 18:37:08 +0300 Subject: [PATCH 255/481] introduce PMD/category/java/errorprone.xml/CloneMethodMustBePublic rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 4fafa2891..eda022c06 100644 --- a/pmd.xml +++ b/pmd.xml @@ -71,4 +71,5 @@ + From 3cf82496224960f99b36c7574901e51254c46f59 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 18:39:34 +0300 Subject: [PATCH 256/481] introduce PMD/category/java/errorprone.xml/CloneMethodMustImplementCloneable rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index eda022c06..08d9b6e35 100644 --- a/pmd.xml +++ b/pmd.xml @@ -72,4 +72,5 @@ + From 9137ca6a369c5311127569dd8af172243a03655b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 18:41:52 +0300 Subject: [PATCH 257/481] introduce PMD/category/java/errorprone.xml/CloneMethodReturnTypeMustMatchClassName rule --- pmd.xml | 1 + .../java/com/github/scribejava/httpclient/okhttp/MockCall.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pmd.xml b/pmd.xml index 08d9b6e35..b2889b695 100644 --- a/pmd.xml +++ b/pmd.xml @@ -73,4 +73,5 @@ + diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java index c6dabd4c2..7fa14a630 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/MockCall.java @@ -49,7 +49,7 @@ public boolean isExecuted() { } @Override - public Call clone() { + public MockCall clone() { throw new UnsupportedOperationException("Not supported yet."); } From a4ff03fee9599a95334af9fe65e54768444a4100 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 4 Apr 2019 19:31:49 +0300 Subject: [PATCH 258/481] introduce PMD/category/java/errorprone.xml/ConstructorCallsOverridableMethod rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index b2889b695..80ec8008b 100644 --- a/pmd.xml +++ b/pmd.xml @@ -74,4 +74,5 @@ + From c4898b990b7772699ea8fa449be4a7734f3d1df0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 11:40:22 +0300 Subject: [PATCH 259/481] introduce PMD/category/java/errorprone.xml/DoNotExtendJavaLangThrowable rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 80ec8008b..4707335a6 100644 --- a/pmd.xml +++ b/pmd.xml @@ -75,4 +75,5 @@ + From 6ee14a89d6d397d641f36fcc2f021af01f9c9cfc Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:02:14 +0300 Subject: [PATCH 260/481] introduce PMD/category/java/errorprone.xml/DontImportSun rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 4707335a6..64b3f05c9 100644 --- a/pmd.xml +++ b/pmd.xml @@ -76,4 +76,5 @@ + From daebd4d3bdeced3288ac36220fe468cfd2048efd Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:06:43 +0300 Subject: [PATCH 261/481] introduce PMD/category/java/errorprone.xml/EmptyFinalizer rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 64b3f05c9..cc0a36d89 100644 --- a/pmd.xml +++ b/pmd.xml @@ -77,4 +77,5 @@ + From 245682f32ee135dee76b0ec697d988cd087bd14e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:08:27 +0300 Subject: [PATCH 262/481] introduce PMD/category/java/errorprone.xml/EmptyFinallyBlock rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index cc0a36d89..42faf3351 100644 --- a/pmd.xml +++ b/pmd.xml @@ -78,4 +78,5 @@ + From 1b1846c3a6891ce45739d1514885848182983fc6 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:12:02 +0300 Subject: [PATCH 263/481] introduce PMD/category/java/errorprone.xml/EmptyIfStmt rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 42faf3351..c3116e8dd 100644 --- a/pmd.xml +++ b/pmd.xml @@ -79,4 +79,5 @@ + From 667eef0748851e096d40b92c21fe5bc23f48b12e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:14:21 +0300 Subject: [PATCH 264/481] introduce PMD/category/java/errorprone.xml/EmptyInitializer rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index c3116e8dd..28df9569c 100644 --- a/pmd.xml +++ b/pmd.xml @@ -80,4 +80,5 @@ + From ac9eae5c0f5c7c4d95d6230ee373b5f804391c54 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:17:54 +0300 Subject: [PATCH 265/481] introduce PMD/category/java/errorprone.xml/EmptyStatementBlock rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 28df9569c..e25acfb20 100644 --- a/pmd.xml +++ b/pmd.xml @@ -81,4 +81,5 @@ + From 6b22afbb936bf2ce1d32cc20499ab75118d2677e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:20:45 +0300 Subject: [PATCH 266/481] introduce PMD/category/java/errorprone.xml/EmptyStatementNotInLoop rule --- pmd.xml | 1 + .../scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pmd.xml b/pmd.xml index e25acfb20..58c576c70 100644 --- a/pmd.xml +++ b/pmd.xml @@ -82,4 +82,5 @@ + diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java index 08706c195..0cb77af25 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/OAuthAsyncCompletionHandler.java @@ -48,4 +48,4 @@ public void onThrowable(Throwable t) { callback.onThrowable(t); } } -}; +} From ec92064cb308e1ec65d0937f6955bea60fbd4be5 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:23:14 +0300 Subject: [PATCH 267/481] introduce PMD/category/java/errorprone.xml/EmptySwitchStatements rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 58c576c70..12222308b 100644 --- a/pmd.xml +++ b/pmd.xml @@ -83,4 +83,5 @@ + From b98d84a25f064e598fceb991ba30690f8f78a000 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:26:22 +0300 Subject: [PATCH 268/481] introduce PMD/category/java/errorprone.xml/EmptyTryBlock rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 12222308b..8e6d3ad5e 100644 --- a/pmd.xml +++ b/pmd.xml @@ -84,4 +84,5 @@ + From 09a5aba91e125d462ffcf2f45a251b51383863e8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:28:43 +0300 Subject: [PATCH 269/481] introduce PMD/category/java/errorprone.xml/EmptyWhileStmt rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 8e6d3ad5e..5fafcb9cb 100644 --- a/pmd.xml +++ b/pmd.xml @@ -85,4 +85,5 @@ + From 0c97686d526bf3abd70261b7db7601cc2babeeb1 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:30:54 +0300 Subject: [PATCH 270/481] introduce PMD/category/java/errorprone.xml/EqualsNull rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 5fafcb9cb..89e65a84e 100644 --- a/pmd.xml +++ b/pmd.xml @@ -86,4 +86,5 @@ + From 0798550643dadfd291f1fb3ab6839d9480531fb8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:34:24 +0300 Subject: [PATCH 271/481] introduce PMD/category/java/errorprone.xml/FinalizeDoesNotCallSuperFinalize rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 89e65a84e..92abb1977 100644 --- a/pmd.xml +++ b/pmd.xml @@ -87,4 +87,5 @@ + From 9d69b65ee153dc28c6f0d867e88dccdf6ff819a6 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:36:46 +0300 Subject: [PATCH 272/481] introduce PMD/category/java/errorprone.xml/FinalizeOnlyCallsSuperFinalize rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 92abb1977..088b01c19 100644 --- a/pmd.xml +++ b/pmd.xml @@ -88,4 +88,5 @@ + From 818aeed7a3a4e7ab5d24cc53ccd3da1c82c71a4d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:39:17 +0300 Subject: [PATCH 273/481] introduce PMD/category/java/errorprone.xml/FinalizeShouldBeProtected rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 088b01c19..5a05e2948 100644 --- a/pmd.xml +++ b/pmd.xml @@ -89,4 +89,5 @@ + From 7cba688df0e232222093b33b292199cc016d2bc5 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:47:56 +0300 Subject: [PATCH 274/481] introduce PMD/category/java/errorprone.xml/IdempotentOperations rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 5a05e2948..56904bd31 100644 --- a/pmd.xml +++ b/pmd.xml @@ -90,4 +90,5 @@ + From bf163177d50232f994fa8d217a8875c2ec8aaa7f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:49:55 +0300 Subject: [PATCH 275/481] introduce PMD/category/java/errorprone.xml/ImportFromSamePackage rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 56904bd31..bc2c24a37 100644 --- a/pmd.xml +++ b/pmd.xml @@ -91,4 +91,5 @@ + From 15a2f53d4155c121c5ff72d2663f2698880c00ed Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 12:56:37 +0300 Subject: [PATCH 276/481] introduce PMD/category/java/errorprone.xml/InstantiationToGetClass rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index bc2c24a37..7dfd56345 100644 --- a/pmd.xml +++ b/pmd.xml @@ -92,4 +92,5 @@ + From 7153f5ba292f140204a57365e6d376bc7f46f569 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 13:45:50 +0300 Subject: [PATCH 277/481] introduce PMD/category/java/errorprone.xml/InvalidSlf4jMessageFormat rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 7dfd56345..ede4de616 100644 --- a/pmd.xml +++ b/pmd.xml @@ -93,4 +93,5 @@ + From 72ac67adadf1c6af7eb61493bdf5e2c54e238d6b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 13:58:57 +0300 Subject: [PATCH 278/481] introduce PMD/category/java/errorprone.xml/MissingStaticMethodInNonInstantiatableClass rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index ede4de616..20659404d 100644 --- a/pmd.xml +++ b/pmd.xml @@ -94,4 +94,5 @@ + From 0a88b7a2c18accde7256e6a44d1d9ecbddb15613 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 14:08:27 +0300 Subject: [PATCH 279/481] introduce PMD/category/java/errorprone.xml/StringBufferInstantiationWithChar rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 20659404d..00e3455ce 100644 --- a/pmd.xml +++ b/pmd.xml @@ -95,4 +95,5 @@ + From fa2639c36c9ec669efdb223be35cf2765d5b9cec Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 14:41:15 +0300 Subject: [PATCH 280/481] introduce PMD/category/java/errorprone.xml/UnconditionalIfStatement rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 00e3455ce..3682fb33f 100644 --- a/pmd.xml +++ b/pmd.xml @@ -96,4 +96,5 @@ + From 194c224f26da2a52499f601b065df6de147f994a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 14:48:24 +0300 Subject: [PATCH 281/481] introduce PMD/category/java/errorprone.xml/UnnecessaryBooleanAssertion rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 3682fb33f..6f1eba1f5 100644 --- a/pmd.xml +++ b/pmd.xml @@ -97,4 +97,5 @@ + From ef126c53c11abebcb09d88655def187136ad2f43 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 15:00:05 +0300 Subject: [PATCH 282/481] introduce PMD/category/java/errorprone.xml/UnnecessaryConversionTemporary rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 6f1eba1f5..a1b0ce615 100644 --- a/pmd.xml +++ b/pmd.xml @@ -98,4 +98,5 @@ + From f30bf9fb9f7d10d3d71c1bc197cbb0b104e76675 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 15:17:24 +0300 Subject: [PATCH 283/481] introduce PMD/category/java/errorprone.xml/UselessOperationOnImmutable rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index a1b0ce615..562364e08 100644 --- a/pmd.xml +++ b/pmd.xml @@ -99,4 +99,5 @@ + From 7263e338576326ecc76f24e557cd1719f650273d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 15:22:34 +0300 Subject: [PATCH 284/481] introduce PMD/category/java/multithreading.xml/DoubleCheckedLocking rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 562364e08..13c3a90cc 100644 --- a/pmd.xml +++ b/pmd.xml @@ -100,4 +100,5 @@ + From dc297ce6fe8665ec0ec409e1b9f93e2b12a3e07a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 15:55:08 +0300 Subject: [PATCH 285/481] introduce PMD/category/java/multithreading.xml/NonThreadSafeSingleton rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 13c3a90cc..d591af97e 100644 --- a/pmd.xml +++ b/pmd.xml @@ -101,4 +101,5 @@ + From 50cd8524992ed75473d0bde6853d497603360199 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 16:10:39 +0300 Subject: [PATCH 286/481] introduce PMD/category/java/multithreading.xml/UnsynchronizedStaticFormatter rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index d591af97e..a9d8f109b 100644 --- a/pmd.xml +++ b/pmd.xml @@ -102,4 +102,5 @@ + From 39f02cc369d834df59b73b78f486d2c7ca20df41 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 16:42:01 +0300 Subject: [PATCH 287/481] introduce PMD/category/java/performance.xml/AddEmptyString rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index a9d8f109b..ced4cd7b1 100644 --- a/pmd.xml +++ b/pmd.xml @@ -103,4 +103,5 @@ + From 128a12cff8ad5abb480a5235437e66d0ad9cef97 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 16:53:32 +0300 Subject: [PATCH 288/481] introduce PMD/category/java/performance.xml/AppendCharacterWithChar rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index ced4cd7b1..3e81fab5c 100644 --- a/pmd.xml +++ b/pmd.xml @@ -104,4 +104,5 @@ + From ad666fec4796891fbdcd8344f68ec44a1a70b3f8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 16:56:04 +0300 Subject: [PATCH 289/481] introduce PMD/category/java/performance.xml/AvoidArrayLoops rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 3e81fab5c..bc3aa8b7f 100644 --- a/pmd.xml +++ b/pmd.xml @@ -105,4 +105,5 @@ + From 08f62983245d4352c652f3acdc8c1dad1d3c38d6 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 18:04:14 +0300 Subject: [PATCH 290/481] introduce PMD/category/java/performance.xml/BigIntegerInstantiation rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index bc3aa8b7f..f135bc012 100644 --- a/pmd.xml +++ b/pmd.xml @@ -106,4 +106,5 @@ + From 07349a49f159a12c04521a8f99266fe66429c421 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 18:06:07 +0300 Subject: [PATCH 291/481] introduce PMD/category/java/performance.xml/BooleanInstantiation rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index f135bc012..6690404cc 100644 --- a/pmd.xml +++ b/pmd.xml @@ -107,4 +107,5 @@ + From 929ad9eed358edcf81100ea89dcf0401b29b3c1b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 18:08:06 +0300 Subject: [PATCH 292/481] introduce PMD/category/java/performance.xml/ByteInstantiation rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 6690404cc..e2e7d16f1 100644 --- a/pmd.xml +++ b/pmd.xml @@ -108,4 +108,5 @@ + From 9ca8ba9ff5a2b04a5d2d7f6aa527c9b59cd881c5 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 18:56:40 +0300 Subject: [PATCH 293/481] introduce PMD/category/java/performance.xml/ConsecutiveAppendsShouldReuse rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index e2e7d16f1..c0ec8d720 100644 --- a/pmd.xml +++ b/pmd.xml @@ -109,4 +109,5 @@ + From d0ecbc6bd7a6b3201f3743586083d3ae761c4ab4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 18:58:20 +0300 Subject: [PATCH 294/481] introduce PMD/category/java/performance.xml/ConsecutiveLiteralAppends rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index c0ec8d720..cd19493a7 100644 --- a/pmd.xml +++ b/pmd.xml @@ -110,4 +110,5 @@ + From f3f23f15e676d354e95dfc393528143717db04e3 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 19:06:52 +0300 Subject: [PATCH 295/481] introduce PMD/category/java/performance.xml/InefficientEmptyStringCheck rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index cd19493a7..dcbeeb731 100644 --- a/pmd.xml +++ b/pmd.xml @@ -111,4 +111,5 @@ + From af2e0f08ca56eaa6ca9107690724d391af00a2d3 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 19:12:36 +0300 Subject: [PATCH 296/481] introduce PMD/category/java/performance.xml/IntegerInstantiation rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index dcbeeb731..3dc600418 100644 --- a/pmd.xml +++ b/pmd.xml @@ -112,4 +112,5 @@ + From 3088146b0b95d2bc69556c28f42f875ec4a64576 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 19:14:33 +0300 Subject: [PATCH 297/481] introduce PMD/category/java/performance.xml/LongInstantiation rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 3dc600418..a5fd3502a 100644 --- a/pmd.xml +++ b/pmd.xml @@ -113,4 +113,5 @@ + From 4768e4f1d5c263dfd6c85f8ef49157a5d7c86eb4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 5 Apr 2019 19:26:41 +0300 Subject: [PATCH 298/481] introduce PMD/category/java/performance.xml/OptimizableToArrayCall rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index a5fd3502a..ec6496c4d 100644 --- a/pmd.xml +++ b/pmd.xml @@ -114,4 +114,5 @@ + From 5b64e222d4802c25200ccfc35df399ed1529720c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Apr 2019 12:51:49 +0300 Subject: [PATCH 299/481] introduce PMD/category/java/performance.xml/RedundantFieldInitializer rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index ec6496c4d..27897c6a1 100644 --- a/pmd.xml +++ b/pmd.xml @@ -115,4 +115,5 @@ + From 36546e8ff94e350a8248d37053fbf3665e97ebf6 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Apr 2019 12:53:55 +0300 Subject: [PATCH 300/481] introduce PMD/category/java/performance.xml/ShortInstantiation rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 27897c6a1..8d8809ea4 100644 --- a/pmd.xml +++ b/pmd.xml @@ -116,4 +116,5 @@ + From 9cb0b10a6a898fd1364f848783a827276fff5e03 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Apr 2019 12:57:56 +0300 Subject: [PATCH 301/481] introduce PMD/category/java/performance.xml/StringInstantiation rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 8d8809ea4..4691c3523 100644 --- a/pmd.xml +++ b/pmd.xml @@ -117,4 +117,5 @@ + From 9caf83aeb63a5cb8e01dc47a4bebcb82ea0ae093 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Apr 2019 13:01:57 +0300 Subject: [PATCH 302/481] introduce PMD/category/java/performance.xml/StringToString rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 4691c3523..0903f6e17 100644 --- a/pmd.xml +++ b/pmd.xml @@ -118,4 +118,5 @@ + From 2751d798a25ed64d3dd2c71ed2457d1d2c9d5cd0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Apr 2019 13:08:27 +0300 Subject: [PATCH 303/481] introduce PMD/category/java/performance.xml/UnnecessaryWrapperObjectCreation rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 0903f6e17..71f32c4de 100644 --- a/pmd.xml +++ b/pmd.xml @@ -119,4 +119,5 @@ + From 9442d4fb8c70677db0464cc085e863783ea14121 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Apr 2019 13:17:18 +0300 Subject: [PATCH 304/481] introduce PMD/category/java/performance.xml/UseIndexOfChar rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 71f32c4de..6eeafdc1c 100644 --- a/pmd.xml +++ b/pmd.xml @@ -120,4 +120,5 @@ + From 6ba30729fab56517f22c4c8b6175136ec54d7e46 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Apr 2019 13:26:20 +0300 Subject: [PATCH 305/481] introduce PMD/category/java/performance.xml/UseStringBufferLength rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 6eeafdc1c..86b1c4d8f 100644 --- a/pmd.xml +++ b/pmd.xml @@ -121,4 +121,5 @@ + From a86cbeea005429add828e272e17911cd68758e8f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Apr 2019 13:52:47 +0300 Subject: [PATCH 306/481] introduce PMD/category/java/security.xml/HardCodedCryptoKey rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index 86b1c4d8f..c7f438e23 100644 --- a/pmd.xml +++ b/pmd.xml @@ -122,4 +122,5 @@ + From 9c810fd4e2d84910a23c53e9548a9d1c34cb3593 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 8 Apr 2019 13:54:23 +0300 Subject: [PATCH 307/481] introduce PMD/category/java/security.xml/InsecureCryptoIv rule --- pmd.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd.xml b/pmd.xml index c7f438e23..6c204f770 100644 --- a/pmd.xml +++ b/pmd.xml @@ -123,4 +123,5 @@ + From bc796e4c43d0323c151f7472fb079c22c7a09e58 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 11 Apr 2019 19:06:08 +0300 Subject: [PATCH 308/481] Update README.md add example for The OAuth 1.0 Protocol RFC 5849 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bbd290e7b..5ebf4674c 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ ScribeJava support out-of-box several HTTP clients: * [RFC 6750](https://tools.ietf.org/html/rfc6750) The OAuth 2.0 Authorization Framework: Bearer Token Usage * [RFC 7636](https://tools.ietf.org/html/rfc7636) Proof Key for Code Exchange by OAuth Public Clients (PKCE), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) * [RFC 7009](https://tools.ietf.org/html/rfc7009) OAuth 2.0 Token Revocation, [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java) + * [RFC 5849](https://tools.ietf.org/html/rfc5849) The OAuth 1.0 Protocol, [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java) ### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box From 030d76872fe371a84b5d05c6c3c33c34e8f611f1 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 11 Apr 2019 20:21:22 +0300 Subject: [PATCH 309/481] add all OAuth error codes from supported RFCs (incl. "invalid_token") (thanks to https://github.com/echorebel) --- changelog | 1 + .../apis/fitbit/FitBitJsonTokenExtractor.java | 5 +- .../fitbit/FitBitJsonTokenExtractorTest.java | 12 +-- .../OAuth2AccessTokenJsonExtractor.java | 5 +- .../model/OAuth2AccessTokenErrorResponse.java | 41 +++++++++ .../scribejava/core/oauth2/OAuth2Error.java | 90 +++++++++++++++++++ .../OAuth2AccessTokenJsonExtractorTest.java | 2 + 7 files changed, 146 insertions(+), 10 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java diff --git a/changelog b/changelog index 6e6bb1221..6a5b00f49 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * add PMD checks on compile + * add all OAuth error codes from supported RFCs (incl. "invalid_token") (thanks to https://github.com/echorebel) [6.5.1] * cleanup deprecates methods diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java index 3679ee14a..1f9f4b5dc 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java @@ -2,6 +2,7 @@ import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; +import com.github.scribejava.core.oauth2.OAuth2Error; import java.util.regex.Pattern; @@ -37,9 +38,9 @@ public void generateError(String response) { final String errorInString = extractParameter(response, ERROR_REGEX_PATTERN, true); final String errorDescription = extractParameter(response, ERROR_DESCRIPTION_REGEX_PATTERN, false); - OAuth2AccessTokenErrorResponse.ErrorCode errorCode; + OAuth2Error errorCode; try { - errorCode = OAuth2AccessTokenErrorResponse.ErrorCode.parseFrom(errorInString); + errorCode = OAuth2Error.parseFrom(errorInString); } catch (IllegalArgumentException iaE) { //non oauth standard error code errorCode = null; diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java index 448d5ff52..d7572816b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis.fitbit; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; -import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse.ErrorCode; +import com.github.scribejava.core.oauth2.OAuth2Error; import org.hamcrest.FeatureMatcher; import org.junit.Rule; @@ -28,21 +28,21 @@ public void testErrorExtraction() { final FitBitJsonTokenExtractor extractor = new FitBitJsonTokenExtractor(); thrown.expect(OAuth2AccessTokenErrorResponse.class); - thrown.expect(new ErrorCodeFeatureMatcher(ErrorCode.INVALID_GRANT)); + thrown.expect(new ErrorCodeFeatureMatcher(OAuth2Error.INVALID_GRANT)); thrown.expect(new ErrorDescriptionFeatureMatcher(ERROR_DESCRIPTION)); extractor.generateError(ERROR_JSON); } - private static class ErrorCodeFeatureMatcher extends FeatureMatcher { + private static class ErrorCodeFeatureMatcher extends FeatureMatcher { - private ErrorCodeFeatureMatcher(ErrorCode expected) { + private ErrorCodeFeatureMatcher(OAuth2Error expected) { super(equalTo(expected), "a response with errorCode", "errorCode"); } @Override - protected ErrorCode featureValueOf(OAuth2AccessTokenErrorResponse actual) { - return actual.getErrorCode(); + protected OAuth2Error featureValueOf(OAuth2AccessTokenErrorResponse actual) { + return actual.getError(); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index a87e8ab82..792ed613f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -8,6 +8,7 @@ import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.oauth2.OAuth2Error; import com.github.scribejava.core.utils.Preconditions; /** @@ -64,9 +65,9 @@ public void generateError(String response) { errorUri = null; } - OAuth2AccessTokenErrorResponse.ErrorCode errorCode; + OAuth2Error errorCode; try { - errorCode = OAuth2AccessTokenErrorResponse.ErrorCode.parseFrom(errorInString); + errorCode = OAuth2Error.parseFrom(errorInString); } catch (IllegalArgumentException iaE) { //non oauth standard error code errorCode = null; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java index 57ada61de..8d78f15c6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java @@ -1,6 +1,7 @@ package com.github.scribejava.core.model; import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.oauth2.OAuth2Error; import java.net.URI; @@ -11,6 +12,10 @@ public class OAuth2AccessTokenErrorResponse extends OAuthException { private static final long serialVersionUID = 2309424849700276816L; + /** + * @deprecated use {@link com.github.scribejava.core.oauth2.OAuth2Error} + */ + @Deprecated public enum ErrorCode { INVALID_REQUEST("invalid_request"), INVALID_CLIENT("invalid_client"), @@ -40,19 +45,55 @@ public static ErrorCode parseFrom(String errorCodeString) { } private final ErrorCode errorCode; + private final OAuth2Error error; private final String errorDescription; private final URI errorUri; private final String rawResponse; + /** + * @param errorCode errorCode + * @param errorDescription errorDescription + * @param errorUri errorUri + * @param rawResponse rawResponse + * @deprecated use {@link #OAuth2AccessTokenErrorResponse(com.github.scribejava.core.oauth2.OAuth2Error, + * java.lang.String, java.net.URI, java.lang.String)} + */ + @Deprecated public OAuth2AccessTokenErrorResponse(ErrorCode errorCode, String errorDescription, URI errorUri, String rawResponse) { super(rawResponse); this.errorCode = errorCode; + this.error = OAuth2Error.parseFrom(errorCode.errorCodeString); this.errorDescription = errorDescription; this.errorUri = errorUri; this.rawResponse = rawResponse; } + public OAuth2AccessTokenErrorResponse(OAuth2Error error, String errorDescription, URI errorUri, + String rawResponse) { + super(rawResponse); + ErrorCode oldErrorCode; + try { + oldErrorCode = ErrorCode.parseFrom(error.getErrorString()); + } catch (IllegalArgumentException iaE) { + oldErrorCode = null; + } + this.errorCode = oldErrorCode; + this.error = error; + this.errorDescription = errorDescription; + this.errorUri = errorUri; + this.rawResponse = rawResponse; + } + + public OAuth2Error getError() { + return error; + } + + /** + * @return error code + * @deprecated use {@link #getError() } + */ + @Deprecated public ErrorCode getErrorCode() { return errorCode; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java new file mode 100644 index 000000000..b5a8d89e6 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java @@ -0,0 +1,90 @@ +package com.github.scribejava.core.oauth2; + +public enum OAuth2Error { + /** + * @see RFC 6749, 4.1.2.1 Error Response + * @see RFC 6749, 4.2.2.1 Error Response + * @see RFC 6749, 5.2 Error Response + * @see RFC 6750, 6.2. OAuth Extensions Error + * Registration + */ + INVALID_REQUEST("invalid_request"), + /** + * @see RFC 6749, 4.1.2.1 Error Response + * @see RFC 6749, 4.2.2.1 Error Response + * @see RFC 6749, 5.2 Error Response + */ + UNAUTHORIZED_CLIENT("unauthorized_client"), + /** + * @see RFC 6749, 4.1.2.1 Error Response + * @see RFC 6749, 4.2.2.1 Error Response + */ + ACCESS_DENIED("access_denied"), + /** + * @see RFC 6749, 4.1.2.1 Error Response + * @see RFC 6749, 4.2.2.1 Error Response + */ + UNSUPPORTED_RESPONSE_TYPE("unsupported_response_type"), + /** + * @see RFC 6749, 4.1.2.1 Error Response + * @see RFC 6749, 4.2.2.1 Error Response + * @see RFC 6749, 5.2 Error Response + */ + INVALID_SCOPE("invalid_scope"), + /** + * @see RFC 6749, 4.1.2.1 Error Response + * @see RFC 6749, 4.2.2.1 Error Response + */ + SERVER_ERROR("server_error"), + /** + * @see RFC 6749, 4.1.2.1 Error Response + * @see RFC 6749, 4.2.2.1 Error Response + */ + TEMPORARILY_UNAVAILABLE("temporarily_unavailable"), + /** + * @see RFC 6749, 5.2 Error Response + */ + INVALID_CLIENT("invalid_client"), + /** + * @see RFC 6749, 5.2 Error Response + */ + INVALID_GRANT("invalid_grant"), + /** + * @see RFC 6749, 5.2 Error Response + */ + UNSUPPORTED_GRANT_TYPE("unsupported_grant_type"), + /** + * @see RFC 6750, 6.2. OAuth Extensions Error + * Registration + */ + INVALID_TOKEN("invalid_token"), + /** + * @see RFC 6750, 6.2. OAuth Extensions Error + * Registration + */ + INSUFFICIENT_SCOPE("insufficient_scope"), + /** + * @see RFC 7009, 4.1. OAuth Extensions Error + * Registration + */ + UNSUPPORTED_TOKEN_TYPE("unsupported_token_type"); + + private final String errorString; + + OAuth2Error(String errorString) { + this.errorString = errorString; + } + + public static OAuth2Error parseFrom(String errorString) { + for (OAuth2Error error : OAuth2Error.values()) { + if (error.errorString.equals(errorString)) { + return error; + } + } + throw new IllegalArgumentException("there is no knowlege about '" + errorString + "' Error"); + } + + public String getErrorString() { + return errorString; + } +} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java index 5d00d89e0..0202c3c20 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java @@ -3,6 +3,7 @@ import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.oauth2.OAuth2Error; import org.junit.Test; import java.io.IOException; @@ -66,6 +67,7 @@ public void shouldThrowExceptionIfResponseIsError() throws IOException { fail(); } catch (OAuth2AccessTokenErrorResponse oaer) { assertEquals(OAuth2AccessTokenErrorResponse.ErrorCode.INVALID_GRANT, oaer.getErrorCode()); + assertEquals(OAuth2Error.INVALID_GRANT, oaer.getError()); assertEquals("unknown, invalid, or expired refresh token", oaer.getErrorDescription()); } } From 4f84b315f17d4a4623ed78cf073b7dc8b2792865 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 20 May 2019 14:22:28 +0300 Subject: [PATCH 310/481] Update LinkedIn Example to API v2 (thanks to https://github.com/peternees) --- changelog | 1 + .../apis/examples/LinkedIn20Example.java | 51 ++++++++++--------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/changelog b/changelog index 6a5b00f49..806422173 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * add PMD checks on compile * add all OAuth error codes from supported RFCs (incl. "invalid_token") (thanks to https://github.com/echorebel) + * Update LinkedIn Example to API v2 (thanks to https://github.com/peternees) [6.5.1] * cleanup deprecates methods diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java index 4fa1388de..e06dd2a3b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java @@ -9,12 +9,15 @@ import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; +import java.util.Random; import java.util.concurrent.ExecutionException; public class LinkedIn20Example { private static final String NETWORK_NAME = "LinkedIn"; - private static final String PROTECTED_RESOURCE_URL = "https://api.linkedin.com/v1/people/~:(%s)"; + private static final String PROTECTED_RESOURCE_URL = "https://api.linkedin.com/v2/me"; + private static final String PROTECTED_EMAIL_RESOURCE_URL + = "https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))"; private LinkedIn20Example() { } @@ -26,7 +29,7 @@ public static void main(String... args) throws IOException, InterruptedException final String clientSecret = "your client secret"; final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .defaultScope("r_basicprofile r_emailaddress") // replace with desired scope + .defaultScope("r_liteprofile r_emailaddress") // replace with desired scope .callback("http://example.com/callback") .build(LinkedInApi20.instance()); final Scanner in = new Scanner(System.in); @@ -36,7 +39,8 @@ public static void main(String... args) throws IOException, InterruptedException // Obtain the Authorization URL System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl("some_params"); + final String secretState = "secret" + new Random().nextInt(999_999); + final String authorizationUrl = service.getAuthorizationUrl(secretState); System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize ScribeJava here:"); System.out.println(authorizationUrl); @@ -52,28 +56,29 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); - // Now let's go and ask for a protected resource! - System.out.println("Now we're going to access a protected resource..."); - while (true) { - System.out.println("Paste profile query for fetch (firstName, lastName, etc) or 'exit' to stop example"); - System.out.print(">>"); - final String query = in.nextLine(); - System.out.println(); + System.out.println("Now we're going to get the email of the current user..."); + final OAuthRequest emailRequest = new OAuthRequest(Verb.GET, PROTECTED_EMAIL_RESOURCE_URL); + emailRequest.addHeader("x-li-format", "json"); + emailRequest.addHeader("Accept-Language", "ru-RU"); + service.signRequest(accessToken, emailRequest); + final Response emailResponse = service.execute(emailRequest); + System.out.println(); + System.out.println(emailResponse.getCode()); + System.out.println(emailResponse.getBody()); - if ("exit".equals(query)) { - break; - } + System.out.println(); - final OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, query)); - request.addHeader("x-li-format", "json"); - request.addHeader("Accept-Language", "ru-RU"); - service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + System.out.println("Now we're going to access a protected profile resource..."); - System.out.println(); - } + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + request.addHeader("x-li-format", "json"); + request.addHeader("Accept-Language", "ru-RU"); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); } } From 7d2ce91c04bd4ec8d3ce48de7dd6f53522d50db0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 27 May 2019 18:17:28 +0300 Subject: [PATCH 311/481] switch to jackson dependency to parse json responses (thanks to https://github.com/galimru) --- changelog | 1 + pom.xml | 29 +++--- scribejava-apis/pom.xml | 2 +- .../FacebookAccessTokenJsonExtractor.java | 20 ++--- .../apis/fitbit/FitBitJsonTokenExtractor.java | 24 ++--- .../apis/openid/OpenIdJsonTokenExtractor.java | 8 +- .../SalesforceJsonTokenExtractor.java | 8 +- .../apis/vk/VKJsonTokenExtractor.java | 10 +-- .../fitbit/FitBitJsonTokenExtractorTest.java | 3 +- .../AbstractOAuth1JSONTokenExtractor.java | 35 ++++---- .../OAuth2AccessTokenJsonExtractor.java | 90 +++++++++++++------ .../OAuth2AccessTokenJsonExtractorTest.java | 6 ++ .../core/oauth/OAuth20ServiceTest.java | 19 ++-- .../core/oauth/OAuth20ServiceUnit.java | 11 ++- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 16 files changed, 153 insertions(+), 117 deletions(-) diff --git a/changelog b/changelog index 806422173..532b45e92 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * add PMD checks on compile * add all OAuth error codes from supported RFCs (incl. "invalid_token") (thanks to https://github.com/echorebel) * Update LinkedIn Example to API v2 (thanks to https://github.com/peternees) + * switch to jackson dependency to parse json responses (thanks to https://github.com/galimru) [6.5.1] * cleanup deprecates methods diff --git a/pom.xml b/pom.xml index 506ba5237..7898059cb 100644 --- a/pom.xml +++ b/pom.xml @@ -53,22 +53,21 @@ + + com.fasterxml.jackson.core + jackson-databind + 2.9.9 + junit junit 4.12 test - - com.google.code.gson - gson - 2.8.5 - test - com.squareup.okhttp3 mockwebserver - 3.14.0 + 3.14.2 test @@ -78,7 +77,7 @@ org.apache.felix maven-bundle-plugin - 4.1.0 + 4.2.0 bundle-manifest @@ -92,7 +91,7 @@ org.apache.maven.plugins maven-jar-plugin - 3.1.1 + 3.1.2 ${project.build.outputDirectory}/META-INF/MANIFEST.MF @@ -107,7 +106,7 @@ com.puppycrawl.tools checkstyle - 8.18 + 8.20 @@ -122,7 +121,7 @@ org.apache.maven.plugins maven-surefire-plugin - 2.22.1 + 2.22.2 org.apache.maven.plugins @@ -144,7 +143,7 @@ maven-compiler-plugin - 3.8.0 + 3.8.1 UTF-8 ${java.release} @@ -175,7 +174,7 @@ org.apache.maven.plugins maven-source-plugin - 3.0.1 + 3.1.0 attach-sources @@ -228,7 +227,7 @@ org.apache.maven.plugins maven-pmd-plugin - 3.11.0 + 3.12.0 net.sourceforge.pmd @@ -274,7 +273,7 @@ 7 - 6.12.0 + 6.14.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index fbcbf7f41..6f0e6e21d 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -8,7 +8,7 @@ 6.5.2-SNAPSHOT ../pom.xml - + com.github.scribejava scribejava-apis ScribeJava APIs diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java index 62326e099..f7b783f6f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java @@ -1,18 +1,14 @@ package com.github.scribejava.apis.facebook; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import java.util.regex.Pattern; +import java.io.IOException; +import java.util.Map; /** * non standard Facebook Extractor */ public class FacebookAccessTokenJsonExtractor extends OAuth2AccessTokenJsonExtractor { - private static final Pattern MESSAGE_REGEX_PATTERN = Pattern.compile("\"message\"\\s*:\\s*\"([^\"]*?)\""); - private static final Pattern TYPE_REGEX_PATTERN = Pattern.compile("\"type\"\\s*:\\s*\"([^\"]*?)\""); - private static final Pattern CODE_REGEX_PATTERN = Pattern.compile("\"code\"\\s*:\\s*\"?([^\",}]*?)[\",}]"); - private static final Pattern FBTRACE_ID_REGEX_PATTERN = Pattern.compile("\"fbtrace_id\"\\s*:\\s*\"([^\"]*?)\""); - protected FacebookAccessTokenJsonExtractor() { } @@ -35,13 +31,13 @@ public static FacebookAccessTokenJsonExtractor instance() { * ID.","type":"OAuthException","code":101,"fbtrace_id":"CvDR+X4WWIx"}}' */ @Override - public void generateError(String response) { - extractParameter(response, MESSAGE_REGEX_PATTERN, false); + public void generateError(String rawResponse) throws IOException { + @SuppressWarnings("unchecked") + final Map response = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER + .readValue(rawResponse, Map.class); - throw new FacebookAccessTokenErrorResponse(extractParameter(response, MESSAGE_REGEX_PATTERN, false), - extractParameter(response, TYPE_REGEX_PATTERN, false), - extractParameter(response, CODE_REGEX_PATTERN, false), - extractParameter(response, FBTRACE_ID_REGEX_PATTERN, false), response); + throw new FacebookAccessTokenErrorResponse(response.get("message"), response.get("type"), response.get("code"), + response.get("fbtrace_id"), rawResponse); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java index 1f9f4b5dc..2923c3d42 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java @@ -3,14 +3,12 @@ import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; import com.github.scribejava.core.oauth2.OAuth2Error; - -import java.util.regex.Pattern; +import java.io.IOException; +import java.util.List; +import java.util.Map; public class FitBitJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { - private static final Pattern USER_ID_REGEX_PATTERN = Pattern.compile("\"user_id\"\\s*:\\s*\"(\\S*?)\""); - private static final Pattern ERROR_REGEX_PATTERN = Pattern.compile("\"errorType\"\\s*:\\s*\"(\\S*?)\""); - private static final Pattern ERROR_DESCRIPTION_REGEX_PATTERN = Pattern.compile("\"message\"\\s*:\\s*\"([^\"]*?)\""); protected FitBitJsonTokenExtractor() { } @@ -25,27 +23,29 @@ public static FitBitJsonTokenExtractor instance() { @Override protected FitBitOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, String response) { + String refreshToken, String scope, Map response, String rawResponse) { return new FitBitOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, - extractParameter(response, USER_ID_REGEX_PATTERN, false), response); + response.get("user_id"), rawResponse); } /** * Related documentation: https://dev.fitbit.com/build/reference/web-api/oauth2/ */ @Override - public void generateError(String response) { - final String errorInString = extractParameter(response, ERROR_REGEX_PATTERN, true); - final String errorDescription = extractParameter(response, ERROR_DESCRIPTION_REGEX_PATTERN, false); + public void generateError(String rawResponse) throws IOException { + @SuppressWarnings("unchecked") + final Map>> response = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER + .readValue(rawResponse, Map.class); + final Map errorResponse = response.get("errors").get(0); OAuth2Error errorCode; try { - errorCode = OAuth2Error.parseFrom(errorInString); + errorCode = OAuth2Error.parseFrom(extractRequiredParameter(errorResponse, "errorType", rawResponse)); } catch (IllegalArgumentException iaE) { //non oauth standard error code errorCode = null; } - throw new OAuth2AccessTokenErrorResponse(errorCode, errorDescription, null, response); + throw new OAuth2AccessTokenErrorResponse(errorCode, errorResponse.get("message"), null, rawResponse); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java index bec8b0613..2a750dbcb 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java @@ -1,15 +1,13 @@ package com.github.scribejava.apis.openid; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import java.util.regex.Pattern; +import java.util.Map; /** * additionally parses OpenID id_token */ public class OpenIdJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { - private static final Pattern ID_TOKEN_REGEX_PATTERN = Pattern.compile("\"id_token\"\\s*:\\s*\"(\\S*?)\""); - protected OpenIdJsonTokenExtractor() { } @@ -24,8 +22,8 @@ public static OpenIdJsonTokenExtractor instance() { @Override protected OpenIdOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, String response) { + String refreshToken, String scope, Map response, String rawResponse) { return new OpenIdOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, - extractParameter(response, ID_TOKEN_REGEX_PATTERN, false), response); + response.get("id_token"), rawResponse); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java index 841276724..3876b587d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis.salesforce; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import java.util.regex.Pattern; +import java.util.Map; /** * This extractor parses in addition to the standard Extractor the instance_url @@ -9,8 +9,6 @@ */ public class SalesforceJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { - private static final Pattern INSTANCE_URL_REGEX_PATTERN = Pattern.compile("\"instance_url\"\\s*:\\s*\"(\\S*?)\""); - protected SalesforceJsonTokenExtractor() { } @@ -25,8 +23,8 @@ public static SalesforceJsonTokenExtractor instance() { @Override protected SalesforceToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, String response) { + String refreshToken, String scope, Map response, String rawResponse) { return new SalesforceToken(accessToken, tokenType, expiresIn, refreshToken, scope, - extractParameter(response, INSTANCE_URL_REGEX_PATTERN, true), response); + extractRequiredParameter(response, "instance_url", rawResponse), rawResponse); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java index 4e658b061..277904ec6 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java @@ -1,15 +1,13 @@ package com.github.scribejava.apis.vk; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import java.util.regex.Pattern; +import java.util.Map; /** * additionally parses email */ public class VKJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { - private static final Pattern EMAIL_REGEX_PATTERN = Pattern.compile("\"email\"\\s*:\\s*\"(\\S*?)\""); - protected VKJsonTokenExtractor() { } @@ -24,8 +22,8 @@ public static VKJsonTokenExtractor instance() { @Override protected VKOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, String response) { - return new VKOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, - extractParameter(response, EMAIL_REGEX_PATTERN, false), response); + String refreshToken, String scope, Map response, String rawResponse) { + return new VKOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, response.get("email"), + rawResponse); } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java index d7572816b..e717dbd7b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java @@ -2,6 +2,7 @@ import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; import com.github.scribejava.core.oauth2.OAuth2Error; +import java.io.IOException; import org.hamcrest.FeatureMatcher; import org.junit.Rule; @@ -23,7 +24,7 @@ public class FitBitJsonTokenExtractorTest { public ExpectedException thrown = ExpectedException.none(); @Test - public void testErrorExtraction() { + public void testErrorExtraction() throws IOException { final FitBitJsonTokenExtractor extractor = new FitBitJsonTokenExtractor(); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java index 16f684855..68c7fdac0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java @@ -1,39 +1,38 @@ package com.github.scribejava.core.extractors; +import com.fasterxml.jackson.databind.ObjectMapper; import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.OAuth1Token; +import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.utils.OAuthEncoder; import com.github.scribejava.core.utils.Preconditions; import java.io.IOException; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import java.util.Map; public abstract class AbstractOAuth1JSONTokenExtractor implements TokenExtractor { - private static final Pattern OAUTH_TOKEN_PATTERN = Pattern.compile("\"oauth_token\"\\s*:\\s*\"(\\S*?)\""); - private static final Pattern OAUTH_TOKEN_SECRET_PATTERN - = Pattern.compile("\"oauth_token_secret\"\\s*:\\s*\"(\\S*?)\""); + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); @Override public T extract(Response response) throws IOException { - final String body = response.getBody(); - Preconditions.checkEmptyString(body, "Response body is incorrect. Can't extract a token from an empty string"); - final String token = extract(body, OAUTH_TOKEN_PATTERN); - final String secret = extract(body, OAUTH_TOKEN_SECRET_PATTERN); - return createToken(token, secret, body); - } + final String rawBody = response.getBody(); + Preconditions.checkEmptyString(rawBody, + "Response body is incorrect. Can't extract a token from an empty string"); + + @SuppressWarnings("unchecked") + final Map body = OBJECT_MAPPER.readValue(rawBody, Map.class); - private String extract(String response, Pattern p) { - final Matcher matcher = p.matcher(response); - if (matcher.find() && matcher.groupCount() >= 1) { - return OAuthEncoder.decode(matcher.group(1)); - } else { + final String token = body.get(OAuthConstants.TOKEN); + final String secret = body.get(OAuthConstants.TOKEN_SECRET); + + if (token == null || secret == null) { throw new OAuthException("Response body is incorrect. Can't extract token and secret from this: '" - + response + '\'', null); + + rawBody + '\'', null); } + + return createToken(token, secret, rawBody); } protected abstract T createToken(String token, String secret, String response); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index 792ed613f..fc7be6e0f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.extractors; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.net.URI; import java.util.regex.Matcher; @@ -7,24 +8,18 @@ import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; +import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.oauth2.OAuth2Error; import com.github.scribejava.core.utils.Preconditions; +import java.util.Map; /** * JSON (default) implementation of {@link TokenExtractor} for OAuth 2.0 */ public class OAuth2AccessTokenJsonExtractor implements TokenExtractor { - private static final Pattern ACCESS_TOKEN_REGEX_PATTERN = Pattern.compile("\"access_token\"\\s*:\\s*\"(\\S*?)\""); - private static final Pattern TOKEN_TYPE_REGEX_PATTERN = Pattern.compile("\"token_type\"\\s*:\\s*\"(\\S*?)\""); - private static final Pattern EXPIRES_IN_REGEX_PATTERN = Pattern.compile("\"expires_in\"\\s*:\\s*\"?(\\d*?)\"?\\D"); - private static final Pattern REFRESH_TOKEN_REGEX_PATTERN = Pattern.compile("\"refresh_token\"\\s*:\\s*\"(\\S*?)\""); - private static final Pattern SCOPE_REGEX_PATTERN = Pattern.compile("\"scope\"\\s*:\\s*\"([^\"]*?)\""); - private static final Pattern ERROR_REGEX_PATTERN = Pattern.compile("\"error\"\\s*:\\s*\"(\\S*?)\""); - private static final Pattern ERROR_DESCRIPTION_REGEX_PATTERN - = Pattern.compile("\"error_description\"\\s*:\\s*\"([^\"]*?)\""); - private static final Pattern ERROR_URI_REGEX_PATTERN = Pattern.compile("\"error_uri\"\\s*:\\s*\"(\\S*?)\""); + protected static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); protected OAuth2AccessTokenJsonExtractor() { } @@ -52,12 +47,14 @@ public OAuth2AccessToken extract(Response response) throws IOException { /** * Related documentation: https://tools.ietf.org/html/rfc6749#section-5.2 * - * @param response response + * @param rawResponse response + * @throws IOException IOException */ - public void generateError(String response) { - final String errorInString = extractParameter(response, ERROR_REGEX_PATTERN, true); - final String errorDescription = extractParameter(response, ERROR_DESCRIPTION_REGEX_PATTERN, false); - final String errorUriInString = extractParameter(response, ERROR_URI_REGEX_PATTERN, false); + public void generateError(String rawResponse) throws IOException { + @SuppressWarnings("unchecked") + final Map response = OBJECT_MAPPER.readValue(rawResponse, Map.class); + + final String errorUriInString = response.get("error_uri"); URI errorUri; try { errorUri = errorUriInString == null ? null : URI.create(errorUriInString); @@ -67,36 +64,67 @@ public void generateError(String response) { OAuth2Error errorCode; try { - errorCode = OAuth2Error.parseFrom(errorInString); + errorCode = OAuth2Error.parseFrom(extractRequiredParameter(response, "error", rawResponse)); } catch (IllegalArgumentException iaE) { //non oauth standard error code errorCode = null; } - throw new OAuth2AccessTokenErrorResponse(errorCode, errorDescription, errorUri, response); + throw new OAuth2AccessTokenErrorResponse(errorCode, response.get("error_description"), errorUri, rawResponse); } - private OAuth2AccessToken createToken(String response) { - final String accessToken = extractParameter(response, ACCESS_TOKEN_REGEX_PATTERN, true); - final String tokenType = extractParameter(response, TOKEN_TYPE_REGEX_PATTERN, false); - final String expiresInString = extractParameter(response, EXPIRES_IN_REGEX_PATTERN, false); + private OAuth2AccessToken createToken(String rawResponse) throws IOException { + + @SuppressWarnings("unchecked") + final Map response = OBJECT_MAPPER.readValue(rawResponse, Map.class); + + final String expiresInString = response.get("expires_in"); Integer expiresIn; try { expiresIn = expiresInString == null ? null : Integer.valueOf(expiresInString); } catch (NumberFormatException nfe) { expiresIn = null; } - final String refreshToken = extractParameter(response, REFRESH_TOKEN_REGEX_PATTERN, false); - final String scope = extractParameter(response, SCOPE_REGEX_PATTERN, false); - return createToken(accessToken, tokenType, expiresIn, refreshToken, scope, response); + return createToken(extractRequiredParameter(response, OAuthConstants.ACCESS_TOKEN, rawResponse), + response.get("token_type"), expiresIn, response.get(OAuthConstants.REFRESH_TOKEN), + response.get(OAuthConstants.SCOPE), response, rawResponse); + } + + protected OAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, + String refreshToken, String scope, Map response, String rawResponse) { + return createToken(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); } + /** + * + * @param accessToken accessToken + * @param tokenType tokenType + * @param expiresIn expiresIn + * @param refreshToken refreshToken + * @param scope scope + * @param rawResponse rawResponse + * @return OAuth2AccessToken + * @deprecated use {@link #createToken(java.lang.String, java.lang.String, java.lang.Integer, java.lang.String, + * java.lang.String, java.util.Map, java.lang.String)} + */ + @Deprecated protected OAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, String response) { - return new OAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, response); + String refreshToken, String scope, String rawResponse) { + return new OAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); } + /** + * + * @param response response + * @param regexPattern regexPattern + * @param required required + * @return parameter value + * @throws OAuthException OAuthException + * @deprecated use {@link #extractRequiredParameter(java.util.Map, java.lang.String, java.lang.String) } or + * {@link java.util.Map#get(java.lang.Object) } + */ + @Deprecated protected static String extractParameter(String response, Pattern regexPattern, boolean required) throws OAuthException { final Matcher matcher = regexPattern.matcher(response); @@ -111,4 +139,16 @@ protected static String extractParameter(String response, Pattern regexPattern, return null; } + + protected static String extractRequiredParameter(Map response, String parameterName, + String rawResponse) throws OAuthException { + final String value = response.get(parameterName); + + if (value == null) { + throw new OAuthException("Response body is incorrect. Can't extract a '" + parameterName + + "' from this: '" + rawResponse + "'", null); + } + + return value; + } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java index 0202c3c20..9324b3e4f 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java @@ -72,6 +72,12 @@ public void shouldThrowExceptionIfResponseIsError() throws IOException { } } + @Test + public void testEscapedJsonInResponse() throws IOException { + final OAuth2AccessToken token = extractor.extract(ok("{ \"access_token\":\"I0122HKLEM2\\/MV3ABKFTDT3T5X\"}")); + assertEquals("I0122HKLEM2/MV3ABKFTDT3T5X", token.getAccessToken()); + } + private static Response ok(String body) { return new Response(200, /* message */ null, /* headers */ Collections.emptyMap(), body); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java index 3590e6b5d..56e6361df 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java @@ -1,12 +1,11 @@ package com.github.scribejava.core.oauth; +import com.fasterxml.jackson.databind.ObjectMapper; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.java8.Base64; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2Authorization; import com.github.scribejava.core.model.OAuthConstants; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import java.io.IOException; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertEquals; @@ -18,6 +17,7 @@ public class OAuth20ServiceTest { + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); private final Base64.Encoder base64Encoder = Base64.getEncoder(); @Test @@ -27,11 +27,10 @@ public void shouldProduceCorrectRequestSync() throws IOException, InterruptedExc .build(new OAuth20ApiUnit()); final OAuth2AccessToken token = service.getAccessTokenPasswordGrant("user1", "password1"); - final Gson json = new Gson(); - assertNotNull(token); - final Map map = json.fromJson(token.getRawResponse(), new TypeTokenImpl().getType()); + @SuppressWarnings("unchecked") + final Map map = OBJECT_MAPPER.readValue(token.getRawResponse(), Map.class); assertEquals(OAuth20ServiceUnit.TOKEN, map.get(OAuthConstants.ACCESS_TOKEN)); assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); @@ -47,17 +46,17 @@ public void shouldProduceCorrectRequestSync() throws IOException, InterruptedExc } @Test - public void shouldProduceCorrectRequestAsync() throws ExecutionException, InterruptedException { + public void shouldProduceCorrectRequestAsync() throws ExecutionException, InterruptedException, IOException { final OAuth20Service service = new ServiceBuilder("your_api_key") .apiSecret("your_api_secret") .build(new OAuth20ApiUnit()); final OAuth2AccessToken token = service.getAccessTokenPasswordGrantAsync("user1", "password1").get(); - final Gson json = new Gson(); assertNotNull(token); - final Map map = json.fromJson(token.getRawResponse(), new TypeTokenImpl().getType()); + @SuppressWarnings("unchecked") + final Map map = OBJECT_MAPPER.readValue(token.getRawResponse(), Map.class); assertEquals(OAuth20ServiceUnit.TOKEN, map.get(OAuthConstants.ACCESS_TOKEN)); assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); @@ -117,9 +116,5 @@ public void testOAuthExtractAuthorization() { authorization = service.extractAuthorization("https://cl.ex.com/cb"); assertEquals(null, authorization.getCode()); assertEquals(null, authorization.getState()); - - } - - private static class TypeTokenImpl extends TypeToken> { } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index fe68d3873..2811088dc 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -1,5 +1,7 @@ package com.github.scribejava.core.oauth; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; @@ -8,7 +10,6 @@ import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Parameter; -import com.google.gson.Gson; import java.util.HashMap; import java.util.Map; @@ -19,6 +20,7 @@ class OAuth20ServiceUnit extends OAuth20Service { static final String TOKEN = "ae82980abab675c646a070686d5558ad"; static final String STATE = "123"; static final String EXPIRES = "3600"; + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { @@ -31,7 +33,6 @@ protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) { } private String prepareRawResponse(OAuthRequest request) { - final Gson json = new Gson(); final Map response = new HashMap<>(); response.put(OAuthConstants.ACCESS_TOKEN, TOKEN); response.put(OAuthConstants.STATE, STATE); @@ -44,7 +45,11 @@ private String prepareRawResponse(OAuthRequest request) { response.put("query-" + param.getKey(), param.getValue()); } - return json.toJson(response); + try { + return OBJECT_MAPPER.writeValueAsString(response); + } catch (JsonProcessingException ex) { + throw new IllegalStateException("smth wrong with Jackson?"); + } } @Override diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 02b290379..93d57ee84 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -23,7 +23,7 @@ org.apache.httpcomponents httpclient - 4.5.7 + 4.5.8 org.apache.httpcomponents diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index d18c6f9e2..25ab4c0d9 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 3.14.0 + 3.14.2 com.github.scribejava From f7aaa7cd30f6b646ecba4380f7838394cdaf0c4c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 May 2019 15:33:04 +0300 Subject: [PATCH 312/481] fixes after switching to jackson --- .../FacebookAccessTokenErrorResponse.java | 40 ++++++++++++--- .../FacebookAccessTokenJsonExtractor.java | 10 ++-- .../apis/fitbit/FitBitJsonTokenExtractor.java | 17 +++---- .../apis/openid/OpenIdJsonTokenExtractor.java | 6 +-- .../SalesforceJsonTokenExtractor.java | 6 +-- .../apis/vk/VKJsonTokenExtractor.java | 9 ++-- .../apis/examples/AsanaExample.java | 3 +- .../apis/examples/Box20Example.java | 5 +- .../apis/examples/DataportenExample.java | 3 +- .../apis/examples/DiscordExample.java | 3 +- .../examples/FacebookAsyncApacheExample.java | 3 +- .../examples/FacebookAsyncNingExample.java | 3 +- .../apis/examples/FacebookExample.java | 3 +- .../apis/examples/FitbitApi20Example.java | 3 +- .../apis/examples/Foursquare2Example.java | 3 +- .../examples/GitHubAsyncOkHttpExample.java | 3 +- .../apis/examples/GitHubExample.java | 3 +- .../examples/Google20AsyncAHCExample.java | 5 +- .../apis/examples/Google20Example.java | 5 +- .../apis/examples/Google20RevokeExample.java | 5 +- .../examples/Google20WithPKCEExample.java | 5 +- .../scribejava/apis/examples/HHExample.java | 3 +- .../apis/examples/HiOrgServerExample.java | 3 +- .../apis/examples/KeycloakExample.java | 3 +- .../apis/examples/LinkedIn20Example.java | 3 +- .../scribejava/apis/examples/LiveExample.java | 3 +- .../apis/examples/MailruAsyncExample.java | 3 +- .../apis/examples/MailruExample.java | 3 +- ...icrosoftAzureActiveDirectory20Example.java | 3 +- .../MicrosoftAzureActiveDirectoryExample.java | 3 +- .../apis/examples/NaverExample.java | 3 +- .../apis/examples/OdnoklassnikiExample.java | 4 +- .../apis/examples/PinterestExample.java | 3 +- .../apis/examples/RenrenExample.java | 3 +- .../apis/examples/StackExchangeExample.java | 3 +- .../apis/examples/TutByExample.java | 3 +- .../apis/examples/ViadeoExample.java | 3 +- .../apis/examples/VkontakteExample.java | 3 +- .../VkontakteExternalHttpExample.java | 3 +- .../apis/examples/Yahoo20Example.java | 3 +- .../FacebookAccessTokenJsonExtractorTest.java | 36 +++++++++++++ .../AbstractOAuth1JSONTokenExtractor.java | 11 ++-- .../OAuth2AccessTokenJsonExtractor.java | 51 +++++++++---------- .../scribejava/core/oauth/OAuth20Service.java | 22 +++++--- .../OAuth2AccessTokenJsonExtractorTest.java | 9 +++- .../core/oauth/OAuth20ServiceTest.java | 32 ++++++------ .../core/oauth/OAuth20ServiceUnit.java | 4 +- 47 files changed, 199 insertions(+), 167 deletions(-) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java index 30c049a3f..3fca57c85 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java @@ -19,15 +19,34 @@ public class FacebookAccessTokenErrorResponse extends OAuthException { private static final long serialVersionUID = -1277129766099856895L; private final String type; - private final String code; + private final int codeInt; private final String fbtraceId; private final String rawResponse; + /** + * @param message message + * @param type type + * @param code code + * @param fbtraceId fbtraceId + * @param rawResponse rawResponse + * @deprecated use {@link #FacebookAccessTokenErrorResponse(java.lang.String, java.lang.String, int, + * java.lang.String, java.lang.String)} + */ + @Deprecated public FacebookAccessTokenErrorResponse(String message, String type, String code, String fbtraceId, String rawResponse) { super(message); this.type = type; - this.code = code; + this.codeInt = Integer.parseInt(code); + this.fbtraceId = fbtraceId; + this.rawResponse = rawResponse; + } + + public FacebookAccessTokenErrorResponse(String message, String type, int code, String fbtraceId, + String rawResponse) { + super(message); + this.type = type; + this.codeInt = code; this.fbtraceId = fbtraceId; this.rawResponse = rawResponse; } @@ -36,8 +55,17 @@ public String getType() { return type; } + /** + * @return code + * @deprecated use {@link #getCodeInt() } + */ + @Deprecated public String getCode() { - return code; + return Integer.toString(codeInt); + } + + public int getCodeInt() { + return codeInt; } public String getFbtraceId() { @@ -54,7 +82,7 @@ public int hashCode() { hash = 83 * hash + Objects.hashCode(rawResponse); hash = 83 * hash + Objects.hashCode(getMessage()); hash = 83 * hash + Objects.hashCode(type); - hash = 83 * hash + Objects.hashCode(code); + hash = 83 * hash + Objects.hashCode(codeInt); hash = 83 * hash + Objects.hashCode(fbtraceId); return hash; } @@ -80,7 +108,7 @@ public boolean equals(Object obj) { if (!Objects.equals(type, other.getType())) { return false; } - if (!Objects.equals(code, other.getCode())) { + if (codeInt != other.getCodeInt()) { return false; } return Objects.equals(fbtraceId, other.getFbtraceId()); @@ -88,7 +116,7 @@ public boolean equals(Object obj) { @Override public String toString() { - return "FacebookAccessTokenErrorResponse{'type'='" + type + "', 'code'='" + code + return "FacebookAccessTokenErrorResponse{'type'='" + type + "', 'codeInt'='" + codeInt + "', 'fbtraceId'='" + fbtraceId + "', 'rawResponse'='" + rawResponse + "', 'message'='" + getMessage() + "'}"; } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java index f7b783f6f..7171c9fbd 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java @@ -1,8 +1,8 @@ package com.github.scribejava.apis.facebook; +import com.fasterxml.jackson.databind.JsonNode; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import java.io.IOException; -import java.util.Map; /** * non standard Facebook Extractor @@ -32,12 +32,10 @@ public static FacebookAccessTokenJsonExtractor instance() { */ @Override public void generateError(String rawResponse) throws IOException { - @SuppressWarnings("unchecked") - final Map response = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER - .readValue(rawResponse, Map.class); + final JsonNode errorNode = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER.readTree(rawResponse).get("error"); - throw new FacebookAccessTokenErrorResponse(response.get("message"), response.get("type"), response.get("code"), - response.get("fbtrace_id"), rawResponse); + throw new FacebookAccessTokenErrorResponse(errorNode.get("message").asText(), errorNode.get("type").asText(), + errorNode.get("code").asInt(), errorNode.get("fbtrace_id").asText(), rawResponse); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java index 2923c3d42..3ec56f5be 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java @@ -1,11 +1,10 @@ package com.github.scribejava.apis.fitbit; +import com.fasterxml.jackson.databind.JsonNode; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; import com.github.scribejava.core.oauth2.OAuth2Error; import java.io.IOException; -import java.util.List; -import java.util.Map; public class FitBitJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { @@ -23,9 +22,9 @@ public static FitBitJsonTokenExtractor instance() { @Override protected FitBitOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, Map response, String rawResponse) { + String refreshToken, String scope, JsonNode response, String rawResponse) { return new FitBitOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, - response.get("user_id"), rawResponse); + response.get("user_id").asText(), rawResponse); } /** @@ -33,19 +32,17 @@ protected FitBitOAuth2AccessToken createToken(String accessToken, String tokenTy */ @Override public void generateError(String rawResponse) throws IOException { - @SuppressWarnings("unchecked") - final Map>> response = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER - .readValue(rawResponse, Map.class); + final JsonNode errorNode = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER.readTree(rawResponse) + .get("errors").get(0); - final Map errorResponse = response.get("errors").get(0); OAuth2Error errorCode; try { - errorCode = OAuth2Error.parseFrom(extractRequiredParameter(errorResponse, "errorType", rawResponse)); + errorCode = OAuth2Error.parseFrom(extractRequiredParameter(errorNode, "errorType", rawResponse).asText()); } catch (IllegalArgumentException iaE) { //non oauth standard error code errorCode = null; } - throw new OAuth2AccessTokenErrorResponse(errorCode, errorResponse.get("message"), null, rawResponse); + throw new OAuth2AccessTokenErrorResponse(errorCode, errorNode.get("message").asText(), null, rawResponse); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java index 2a750dbcb..2b1be532c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis.openid; +import com.fasterxml.jackson.databind.JsonNode; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import java.util.Map; /** * additionally parses OpenID id_token @@ -22,8 +22,8 @@ public static OpenIdJsonTokenExtractor instance() { @Override protected OpenIdOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, Map response, String rawResponse) { + String refreshToken, String scope, JsonNode response, String rawResponse) { return new OpenIdOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, - response.get("id_token"), rawResponse); + response.get("id_token").asText(), rawResponse); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java index 3876b587d..62a3294cf 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/salesforce/SalesforceJsonTokenExtractor.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis.salesforce; +import com.fasterxml.jackson.databind.JsonNode; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import java.util.Map; /** * This extractor parses in addition to the standard Extractor the instance_url @@ -23,8 +23,8 @@ public static SalesforceJsonTokenExtractor instance() { @Override protected SalesforceToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, Map response, String rawResponse) { + String refreshToken, String scope, JsonNode response, String rawResponse) { return new SalesforceToken(accessToken, tokenType, expiresIn, refreshToken, scope, - extractRequiredParameter(response, "instance_url", rawResponse), rawResponse); + extractRequiredParameter(response, "instance_url", rawResponse).asText(), rawResponse); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java index 277904ec6..a3d14aacf 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.java @@ -1,7 +1,7 @@ package com.github.scribejava.apis.vk; +import com.fasterxml.jackson.databind.JsonNode; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; -import java.util.Map; /** * additionally parses email @@ -22,8 +22,9 @@ public static VKJsonTokenExtractor instance() { @Override protected VKOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, Map response, String rawResponse) { - return new VKOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, response.get("email"), - rawResponse); + String refreshToken, String scope, JsonNode response, String rawResponse) { + final JsonNode email = response.get("email"); + return new VKOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, + email == null ? null : email.asText(), rawResponse); } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java index 1c5bf684d..4320fbe6e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java @@ -42,8 +42,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index edbbd1663..4dd9fad9f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -42,7 +42,7 @@ public static void main(String... args) throws IOException, InterruptedException //pass access_type=offline to get refresh token final Map additionalParams = new HashMap<>(); additionalParams.put("access_type", "offline"); - //force to reget refresh token (if usera are asked not the first time) + //force to reget refresh token (if user are asked not the first time) additionalParams.put("prompt", "consent"); final String authorizationUrl = service.createAuthorizationUrlBuilder() .state(secretState) @@ -68,8 +68,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java index 1878983eb..72dbba843 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java @@ -58,8 +58,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java index b574034c7..facca275b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java @@ -61,8 +61,7 @@ public static void main(String... args) throws IOException, ExecutionException, System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + accessToken diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java index c2e55187e..337a11e40 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java @@ -62,8 +62,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code).get(); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index 6c9b64436..073df9ebe 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -70,8 +70,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessTokenAsync(code).get(); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index e4e7ca180..cd9a7db9b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -59,8 +59,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java index 0be7c1b6e..20ca7372b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java @@ -48,8 +48,7 @@ public static void main(String... args) throws Exception { final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken oauth2AccessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(if your curious it looks like this: " + oauth2AccessToken diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index 3aa3ab38b..69d9277f0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -44,8 +44,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java index 7559f9188..abecfd03b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java @@ -62,8 +62,7 @@ public static void main(String... args) throws IOException, ExecutionException, System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index d9fa467be..59302a752 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -58,8 +58,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index 6dc0dc624..f9214f05f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -55,7 +55,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx //https://developers.google.com/identity/protocols/OAuth2WebServer#preparing-to-start-the-oauth-20-flow final Map additionalParams = new HashMap<>(); additionalParams.put("access_type", "offline"); - //force to reget refresh token (if usera are asked not the first time) + //force to reget refresh token (if user are asked not the first time) additionalParams.put("prompt", "consent"); final String authorizationUrl = service.createAuthorizationUrlBuilder() .state(secretState) @@ -82,8 +82,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 4b141c42b..4c23c3287 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -44,7 +44,7 @@ public static void main(String... args) throws IOException, InterruptedException //https://developers.google.com/identity/protocols/OAuth2WebServer#preparing-to-start-the-oauth-20-flow final Map additionalParams = new HashMap<>(); additionalParams.put("access_type", "offline"); - //force to reget refresh token (if usera are asked not the first time) + //force to reget refresh token (if user are asked not the first time) additionalParams.put("prompt", "consent"); final String authorizationUrl = service.createAuthorizationUrlBuilder() .state(secretState) @@ -70,8 +70,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java index 9f55b43d7..384183553 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java @@ -44,7 +44,7 @@ public static void main(String... args) throws IOException, InterruptedException //https://developers.google.com/identity/protocols/OAuth2WebServer#preparing-to-start-the-oauth-20-flow final Map additionalParams = new HashMap<>(); additionalParams.put("access_type", "offline"); - //force to reget refresh token (if usera are asked not the first time) + //force to reget refresh token (if user are asked not the first time) additionalParams.put("prompt", "consent"); final String authorizationUrl = service.createAuthorizationUrlBuilder() .state(secretState) @@ -70,8 +70,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java index b4d108430..5f9bb3e15 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java @@ -47,7 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException //https://developers.google.com/identity/protocols/OAuth2WebServer#preparing-to-start-the-oauth-20-flow final Map additionalParams = new HashMap<>(); additionalParams.put("access_type", "offline"); - //force to reget refresh token (if usera are asked not the first time) + //force to reget refresh token (if user are asked not the first time) additionalParams.put("prompt", "consent"); final AuthorizationUrlBuilder authorizationUrlBuilder = service.createAuthorizationUrlBuilder() @@ -75,8 +75,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(AccessTokenRequestParams.create(code) .pkceCodeVerifier(authorizationUrlBuilder.getPkce().getCodeVerifier())); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index ae7cafa2d..3e9f7b892 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -46,8 +46,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java index 22846f21d..b2a764883 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java @@ -63,8 +63,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java index 80cf06473..242ba46c6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java @@ -49,8 +49,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java index e06dd2a3b..b77a08c61 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java @@ -49,8 +49,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index fb6712b6a..2e2109e28 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -44,8 +44,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index 6fcb28be8..0dffbd4d3 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -57,8 +57,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index 7c7ea8161..fe5df3e51 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -46,8 +46,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java index b06ae03db..9f9e0afce 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java @@ -42,8 +42,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.print(">>"); final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java index 70dd25a94..4d7e6c40e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java @@ -47,8 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java index 2879cb1f9..260dbec4f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java @@ -60,8 +60,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index 3deb43a30..e97540a19 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -48,9 +48,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); - + System.out.println("Trading the Authorization Code for an Access Token..."); OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index c7fd39149..e6d8922fa 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -45,8 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 61bcd5c6d..1131b87fb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -55,8 +55,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index 564dbc222..a35cda537 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -63,8 +63,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); } - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index 393db2a65..475c7df58 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -45,8 +45,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index c16bd9770..0efdcd448 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -44,8 +44,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java index 2c73d583d..26f7cde06 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java @@ -51,8 +51,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(AccessTokenRequestParams.create(code) .scope(customScope)); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java index c918633c0..3171c8d8c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java @@ -63,8 +63,7 @@ public static void main(String... args) throws IOException, InterruptedException final String code = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(code); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java index e151e8e5b..1a5186286 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java @@ -56,8 +56,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token - System.out.println("Trading the Request Token for an Access Token..."); + System.out.println("Trading the Authorization Code for an Access Token..."); final OAuth2AccessToken accessToken = service.getAccessToken(oauthVerifier); System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java new file mode 100644 index 000000000..3fa402247 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java @@ -0,0 +1,36 @@ +package com.github.scribejava.apis.facebook; + +import com.github.scribejava.core.model.Response; +import java.io.IOException; +import java.util.Collections; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import org.junit.Test; + +public class FacebookAccessTokenJsonExtractorTest { + + private final FacebookAccessTokenJsonExtractor extractor = FacebookAccessTokenJsonExtractor.instance(); + + @Test + public void shouldThrowExceptionIfResponseIsError() throws IOException { + final String body = "{\"error\":" + + "{\"message\":\"This authorization code has been used.\"," + + "\"type\":\"OAuthException\"," + + "\"code\":100," + + "\"fbtrace_id\":\"DtxvtGRaxbB\"}}"; + try { + extractor.extract(error(body)); + fail(); + } catch (FacebookAccessTokenErrorResponse fateR) { + assertEquals("This authorization code has been used.", fateR.getMessage()); + assertEquals("OAuthException", fateR.getType()); + assertEquals(100, fateR.getCodeInt()); + assertEquals("DtxvtGRaxbB", fateR.getFbtraceId()); + assertEquals(body, fateR.getRawResponse()); + } + } + + private static Response error(String body) { + return new Response(400, /* message */ null, /* headers */ Collections.emptyMap(), body); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java index 68c7fdac0..5c42e812a 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractOAuth1JSONTokenExtractor.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.extractors; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.OAuth1Token; @@ -8,7 +9,6 @@ import com.github.scribejava.core.utils.Preconditions; import java.io.IOException; -import java.util.Map; public abstract class AbstractOAuth1JSONTokenExtractor implements TokenExtractor { @@ -21,18 +21,17 @@ public T extract(Response response) throws IOException { Preconditions.checkEmptyString(rawBody, "Response body is incorrect. Can't extract a token from an empty string"); - @SuppressWarnings("unchecked") - final Map body = OBJECT_MAPPER.readValue(rawBody, Map.class); + final JsonNode body = OBJECT_MAPPER.readTree(rawBody); - final String token = body.get(OAuthConstants.TOKEN); - final String secret = body.get(OAuthConstants.TOKEN_SECRET); + final JsonNode token = body.get(OAuthConstants.TOKEN); + final JsonNode secret = body.get(OAuthConstants.TOKEN_SECRET); if (token == null || secret == null) { throw new OAuthException("Response body is incorrect. Can't extract token and secret from this: '" + rawBody + '\'', null); } - return createToken(token, secret, rawBody); + return createToken(token.asText(), secret.asText(), rawBody); } protected abstract T createToken(String token, String secret, String response); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index fc7be6e0f..d626ca159 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.extractors; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.net.URI; @@ -12,7 +13,6 @@ import com.github.scribejava.core.model.Response; import com.github.scribejava.core.oauth2.OAuth2Error; import com.github.scribejava.core.utils.Preconditions; -import java.util.Map; /** * JSON (default) implementation of {@link TokenExtractor} for OAuth 2.0 @@ -51,48 +51,47 @@ public OAuth2AccessToken extract(Response response) throws IOException { * @throws IOException IOException */ public void generateError(String rawResponse) throws IOException { - @SuppressWarnings("unchecked") - final Map response = OBJECT_MAPPER.readValue(rawResponse, Map.class); + final JsonNode response = OBJECT_MAPPER.readTree(rawResponse); - final String errorUriInString = response.get("error_uri"); + final JsonNode errorUriInString = response.get("error_uri"); URI errorUri; try { - errorUri = errorUriInString == null ? null : URI.create(errorUriInString); + errorUri = errorUriInString == null ? null : URI.create(errorUriInString.asText()); } catch (IllegalArgumentException iae) { errorUri = null; } OAuth2Error errorCode; try { - errorCode = OAuth2Error.parseFrom(extractRequiredParameter(response, "error", rawResponse)); + errorCode = OAuth2Error.parseFrom(extractRequiredParameter(response, "error", rawResponse).asText()); } catch (IllegalArgumentException iaE) { //non oauth standard error code errorCode = null; } - throw new OAuth2AccessTokenErrorResponse(errorCode, response.get("error_description"), errorUri, rawResponse); + final JsonNode errorDescription = response.get("error_description"); + + throw new OAuth2AccessTokenErrorResponse(errorCode, errorDescription == null ? null : errorDescription.asText(), + errorUri, rawResponse); } private OAuth2AccessToken createToken(String rawResponse) throws IOException { - @SuppressWarnings("unchecked") - final Map response = OBJECT_MAPPER.readValue(rawResponse, Map.class); + final JsonNode response = OBJECT_MAPPER.readTree(rawResponse); - final String expiresInString = response.get("expires_in"); - Integer expiresIn; - try { - expiresIn = expiresInString == null ? null : Integer.valueOf(expiresInString); - } catch (NumberFormatException nfe) { - expiresIn = null; - } + final JsonNode expiresInNode = response.get("expires_in"); + final JsonNode refreshToken = response.get(OAuthConstants.REFRESH_TOKEN); + final JsonNode scope = response.get(OAuthConstants.SCOPE); + final JsonNode tokenType = response.get("token_type"); - return createToken(extractRequiredParameter(response, OAuthConstants.ACCESS_TOKEN, rawResponse), - response.get("token_type"), expiresIn, response.get(OAuthConstants.REFRESH_TOKEN), - response.get(OAuthConstants.SCOPE), response, rawResponse); + return createToken(extractRequiredParameter(response, OAuthConstants.ACCESS_TOKEN, rawResponse).asText(), + tokenType == null ? null : tokenType.asText(), expiresInNode == null ? null : expiresInNode.asInt(), + refreshToken == null ? null : refreshToken.asText(), scope == null ? null : scope.asText(), response, + rawResponse); } protected OAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, Map response, String rawResponse) { + String refreshToken, String scope, JsonNode response, String rawResponse) { return createToken(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); } @@ -106,7 +105,7 @@ protected OAuth2AccessToken createToken(String accessToken, String tokenType, In * @param rawResponse rawResponse * @return OAuth2AccessToken * @deprecated use {@link #createToken(java.lang.String, java.lang.String, java.lang.Integer, java.lang.String, - * java.lang.String, java.util.Map, java.lang.String)} + * java.lang.String, com.fasterxml.jackson.databind.JsonNode, java.lang.String)} */ @Deprecated protected OAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, @@ -121,8 +120,8 @@ protected OAuth2AccessToken createToken(String accessToken, String tokenType, In * @param required required * @return parameter value * @throws OAuthException OAuthException - * @deprecated use {@link #extractRequiredParameter(java.util.Map, java.lang.String, java.lang.String) } or - * {@link java.util.Map#get(java.lang.Object) } + * @deprecated use {@link #extractRequiredParameter(com.fasterxml.jackson.databind.JsonNode, java.lang.String, + * java.lang.String)} */ @Deprecated protected static String extractParameter(String response, Pattern regexPattern, boolean required) @@ -140,9 +139,9 @@ protected static String extractParameter(String response, Pattern regexPattern, return null; } - protected static String extractRequiredParameter(Map response, String parameterName, - String rawResponse) throws OAuthException { - final String value = response.get(parameterName); + protected static JsonNode extractRequiredParameter(JsonNode errorNode, String parameterName, String rawResponse) + throws OAuthException { + final JsonNode value = errorNode.get(parameterName); if (value == null) { throw new OAuthException("Response body is incorrect. Can't extract a '" + parameterName diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index df4557ea0..c80a6496d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -17,6 +17,8 @@ import java.util.Map; import java.util.concurrent.ExecutionException; import com.github.scribejava.core.revoke.TokenTypeHint; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; public class OAuth20Service extends OAuthService { @@ -411,14 +413,18 @@ public OAuth2Authorization extractAuthorization(String redirectLocation) { for (String param : redirectLocation.substring(redirectLocation.indexOf('?') + 1, end).split("&")) { final String[] keyValue = param.split("="); if (keyValue.length == 2) { - switch (keyValue[0]) { - case "code": - authorization.setCode(keyValue[1]); - break; - case "state": - authorization.setState(keyValue[1]); - break; - default: //just ignore any other param; + try { + switch (keyValue[0]) { + case "code": + authorization.setCode(URLDecoder.decode(keyValue[1], "UTF-8")); + break; + case "state": + authorization.setState(URLDecoder.decode(keyValue[1], "UTF-8")); + break; + default: //just ignore any other param; + } + } catch (UnsupportedEncodingException ueE) { + throw new IllegalStateException("jvm without UTF-8, really?", ueE); } } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java index 9324b3e4f..7114115be 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java @@ -19,7 +19,8 @@ public class OAuth2AccessTokenJsonExtractorTest { @Test public void shouldParseResponse() throws IOException { final OAuth2AccessToken token = extractor.extract( - ok("{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X\"}")); + ok("{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X\", " + + "\"token_type\":\"example\"}")); assertEquals("I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X", token.getAccessToken()); } @@ -27,18 +28,21 @@ public void shouldParseResponse() throws IOException { public void shouldParseScopeFromResponse() throws IOException { OAuth2AccessToken token = extractor.extract( ok("{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T4X\", " + + "\"token_type\":\"example\"," + "\"scope\":\"s1\"}")); assertEquals("I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T4X", token.getAccessToken()); assertEquals("s1", token.getScope()); token = extractor.extract( ok("{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T5X\", " + + "\"token_type\":\"example\"," + "\"scope\":\"s1 s2\"}")); assertEquals("I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T5X", token.getAccessToken()); assertEquals("s1 s2", token.getScope()); token = extractor.extract( ok("{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T6X\", " + + "\"token_type\":\"example\"," + "\"scope\":\"s3 s4\", " + "\"refresh_token\":\"refresh_token1\"}")); assertEquals("I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T6X", token.getAccessToken()); @@ -74,7 +78,8 @@ public void shouldThrowExceptionIfResponseIsError() throws IOException { @Test public void testEscapedJsonInResponse() throws IOException { - final OAuth2AccessToken token = extractor.extract(ok("{ \"access_token\":\"I0122HKLEM2\\/MV3ABKFTDT3T5X\"}")); + final OAuth2AccessToken token = extractor.extract(ok("{ \"access_token\":\"I0122HKLEM2\\/MV3ABKFTDT3T5X\"," + + "\"token_type\":\"example\"}")); assertEquals("I0122HKLEM2/MV3ABKFTDT3T5X", token.getAccessToken()); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java index 56e6361df..7dfe361f0 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.oauth; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.java8.Base64; @@ -12,7 +13,6 @@ import org.junit.Test; import java.nio.charset.Charset; -import java.util.Map; import java.util.concurrent.ExecutionException; public class OAuth20ServiceTest { @@ -29,20 +29,19 @@ public void shouldProduceCorrectRequestSync() throws IOException, InterruptedExc final OAuth2AccessToken token = service.getAccessTokenPasswordGrant("user1", "password1"); assertNotNull(token); - @SuppressWarnings("unchecked") - final Map map = OBJECT_MAPPER.readValue(token.getRawResponse(), Map.class); + final JsonNode response = OBJECT_MAPPER.readTree(token.getRawResponse()); - assertEquals(OAuth20ServiceUnit.TOKEN, map.get(OAuthConstants.ACCESS_TOKEN)); - assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); + assertEquals(OAuth20ServiceUnit.TOKEN, response.get(OAuthConstants.ACCESS_TOKEN).asText()); + assertEquals(OAuth20ServiceUnit.EXPIRES, response.get("expires_in").asInt()); final String authorize = base64Encoder.encodeToString( String.format("%s:%s", service.getApiKey(), service.getApiSecret()).getBytes(Charset.forName("UTF-8"))); - assertEquals(OAuthConstants.BASIC + ' ' + authorize, map.get(OAuthConstants.HEADER)); + assertEquals(OAuthConstants.BASIC + ' ' + authorize, response.get(OAuthConstants.HEADER).asText()); - assertEquals("user1", map.get("query-username")); - assertEquals("password1", map.get("query-password")); - assertEquals("password", map.get("query-grant_type")); + assertEquals("user1", response.get("query-username").asText()); + assertEquals("password1", response.get("query-password").asText()); + assertEquals("password", response.get("query-grant_type").asText()); } @Test @@ -55,20 +54,19 @@ public void shouldProduceCorrectRequestAsync() throws ExecutionException, Interr assertNotNull(token); - @SuppressWarnings("unchecked") - final Map map = OBJECT_MAPPER.readValue(token.getRawResponse(), Map.class); + final JsonNode response = OBJECT_MAPPER.readTree(token.getRawResponse()); - assertEquals(OAuth20ServiceUnit.TOKEN, map.get(OAuthConstants.ACCESS_TOKEN)); - assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in")); + assertEquals(OAuth20ServiceUnit.TOKEN, response.get(OAuthConstants.ACCESS_TOKEN).asText()); + assertEquals(OAuth20ServiceUnit.EXPIRES, response.get("expires_in").asInt()); final String authorize = base64Encoder.encodeToString( String.format("%s:%s", service.getApiKey(), service.getApiSecret()).getBytes(Charset.forName("UTF-8"))); - assertEquals(OAuthConstants.BASIC + ' ' + authorize, map.get(OAuthConstants.HEADER)); + assertEquals(OAuthConstants.BASIC + ' ' + authorize, response.get(OAuthConstants.HEADER).asText()); - assertEquals("user1", map.get("query-username")); - assertEquals("password1", map.get("query-password")); - assertEquals("password", map.get("query-grant_type")); + assertEquals("user1", response.get("query-username").asText()); + assertEquals("password1", response.get("query-password").asText()); + assertEquals("password", response.get("query-grant_type").asText()); } @Test diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index 2811088dc..46cf9ee28 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -19,7 +19,7 @@ class OAuth20ServiceUnit extends OAuth20Service { static final String TOKEN = "ae82980abab675c646a070686d5558ad"; static final String STATE = "123"; - static final String EXPIRES = "3600"; + static final int EXPIRES = 3600; private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, @@ -33,7 +33,7 @@ protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) { } private String prepareRawResponse(OAuthRequest request) { - final Map response = new HashMap<>(); + final Map response = new HashMap<>(); response.put(OAuthConstants.ACCESS_TOKEN, TOKEN); response.put(OAuthConstants.STATE, STATE); response.put("expires_in", EXPIRES); From aefa8d6a809de0390f2bab981fe08dad00c6545a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 May 2019 17:20:21 +0300 Subject: [PATCH 313/481] prepare v6.6.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5ebf4674c..393a0017b 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.5.1 + 6.6.0 ``` @@ -138,7 +138,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.5.1 + 6.6.0 ``` diff --git a/changelog b/changelog index 532b45e92..d0659e450 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.6.0] * add PMD checks on compile * add all OAuth error codes from supported RFCs (incl. "invalid_token") (thanks to https://github.com/echorebel) * Update LinkedIn Example to API v2 (thanks to https://github.com/peternees) From 5f031fc989ed98bdc23e8c6ab3920db4abb6d131 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 May 2019 17:21:47 +0300 Subject: [PATCH 314/481] [maven-release-plugin] prepare release scribejava-6.6.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 7898059cb..5fb759ffb 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.5.2-SNAPSHOT + 6.6.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.6.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 6f0e6e21d..d0e738d7f 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.2-SNAPSHOT + 6.6.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 61cf7df26..3fe28bf80 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.2-SNAPSHOT + 6.6.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index f3de40bc2..c927bd762 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.2-SNAPSHOT + 6.6.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 93d57ee84..627322daf 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.2-SNAPSHOT + 6.6.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 185088deb..e9da28657 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.2-SNAPSHOT + 6.6.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 25ab4c0d9..eefca488a 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.5.2-SNAPSHOT + 6.6.0 ../pom.xml From ad059f67bea63fb1fa79f6de08ba953e9ec7cb85 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 May 2019 17:22:28 +0300 Subject: [PATCH 315/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 5fb759ffb..9adb2c52a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.6.0 + 6.6.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.6.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index d0e738d7f..b2c0e128b 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.0 + 6.6.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 3fe28bf80..c460ec225 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.0 + 6.6.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index c927bd762..dde3bc9f1 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.0 + 6.6.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 627322daf..962a8339c 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.0 + 6.6.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index e9da28657..b094f19c6 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.0 + 6.6.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index eefca488a..efe512e3e 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.0 + 6.6.1-SNAPSHOT ../pom.xml From 5e2f639582e35dd3b242fa76a41186840d12ce73 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 May 2019 18:11:26 +0300 Subject: [PATCH 316/481] prepare 6.6.1 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 393a0017b..764b5827e 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.6.0 + 6.6.1 ``` @@ -138,7 +138,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.6.0 + 6.6.1 ``` diff --git a/changelog b/changelog index d0659e450..a5690d4f2 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[6.6.0] +[6.6.1] * add PMD checks on compile * add all OAuth error codes from supported RFCs (incl. "invalid_token") (thanks to https://github.com/echorebel) * Update LinkedIn Example to API v2 (thanks to https://github.com/peternees) From f4894e2dd7222f52bf304d98ede71c752402dd21 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 May 2019 18:12:49 +0300 Subject: [PATCH 317/481] [maven-release-plugin] prepare release scribejava-6.6.1 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 9adb2c52a..60f615338 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.6.1-SNAPSHOT + 6.6.1 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.6.1 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index b2c0e128b..6e81d8408 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1-SNAPSHOT + 6.6.1 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index c460ec225..3e009a6e8 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1-SNAPSHOT + 6.6.1 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index dde3bc9f1..8af0dc5c1 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1-SNAPSHOT + 6.6.1 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 962a8339c..ded1494a5 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1-SNAPSHOT + 6.6.1 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index b094f19c6..63635622f 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1-SNAPSHOT + 6.6.1 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index efe512e3e..f5a779a4d 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1-SNAPSHOT + 6.6.1 ../pom.xml From fe831d41846ed3db8af3a60bac7b7934422da49c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 May 2019 18:12:55 +0300 Subject: [PATCH 318/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 60f615338..c7e0f6573 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.6.1 + 6.6.2-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.6.1 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 6e81d8408..e0f72e38b 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1 + 6.6.2-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 3e009a6e8..07f9b4ce0 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1 + 6.6.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 8af0dc5c1..d1ed71ece 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1 + 6.6.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index ded1494a5..c8bdfe85e 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1 + 6.6.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 63635622f..43d27b216 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1 + 6.6.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index f5a779a4d..d511ff769 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.1 + 6.6.2-SNAPSHOT ../pom.xml From 86d8986113f8ab89f595f0238cdee0a509a3791e Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 May 2019 19:25:43 +0300 Subject: [PATCH 319/481] prepare v6.6.2 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 764b5827e..e5031e7e8 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.6.1 + 6.6.2 ``` @@ -138,7 +138,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.6.1 + 6.6.2 ``` diff --git a/changelog b/changelog index a5690d4f2..f8da95ca0 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[6.6.1] +[6.6.2] * add PMD checks on compile * add all OAuth error codes from supported RFCs (incl. "invalid_token") (thanks to https://github.com/echorebel) * Update LinkedIn Example to API v2 (thanks to https://github.com/peternees) From 8e5ad0760c94c28e944fd034ad5a511de079c0e8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 May 2019 19:27:23 +0300 Subject: [PATCH 320/481] [maven-release-plugin] prepare release scribejava-6.6.2 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index c7e0f6573..15cecb02a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.6.2-SNAPSHOT + 6.6.2 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.6.2 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index e0f72e38b..b9308c7d4 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2-SNAPSHOT + 6.6.2 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 07f9b4ce0..372e52e50 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2-SNAPSHOT + 6.6.2 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index d1ed71ece..efcda092f 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2-SNAPSHOT + 6.6.2 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index c8bdfe85e..a322a0930 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2-SNAPSHOT + 6.6.2 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 43d27b216..015df9cc6 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2-SNAPSHOT + 6.6.2 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index d511ff769..0d8719050 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2-SNAPSHOT + 6.6.2 ../pom.xml From 6aaf652b79240e09103d238c1f0b23a02c89b81f Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 28 May 2019 19:27:29 +0300 Subject: [PATCH 321/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 15cecb02a..f2cfc0943 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.6.2 + 6.6.3-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.6.2 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index b9308c7d4..9d597784c 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2 + 6.6.3-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 372e52e50..1091ca710 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2 + 6.6.3-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index efcda092f..5fc7c4c7b 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2 + 6.6.3-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index a322a0930..3187a84b2 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2 + 6.6.3-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 015df9cc6..4b1df3e2b 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2 + 6.6.3-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 0d8719050..82a8e7d64 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.2 + 6.6.3-SNAPSHOT ../pom.xml From 5abbcecd2c376214e5d3202133b5004144d728a4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 29 May 2019 09:53:44 +0300 Subject: [PATCH 322/481] drop deprecated methods --- .../FacebookAccessTokenErrorResponse.java | 28 -------- .../OAuth2AccessTokenJsonExtractor.java | 46 ------------- .../model/OAuth2AccessTokenErrorResponse.java | 68 ------------------- .../scribejava/core/revoke/TokenTypeHint.java | 12 ---- .../OAuth2AccessTokenJsonExtractorTest.java | 1 - 5 files changed, 155 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java index 3fca57c85..b792ad636 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java @@ -23,25 +23,6 @@ public class FacebookAccessTokenErrorResponse extends OAuthException { private final String fbtraceId; private final String rawResponse; - /** - * @param message message - * @param type type - * @param code code - * @param fbtraceId fbtraceId - * @param rawResponse rawResponse - * @deprecated use {@link #FacebookAccessTokenErrorResponse(java.lang.String, java.lang.String, int, - * java.lang.String, java.lang.String)} - */ - @Deprecated - public FacebookAccessTokenErrorResponse(String message, String type, String code, String fbtraceId, - String rawResponse) { - super(message); - this.type = type; - this.codeInt = Integer.parseInt(code); - this.fbtraceId = fbtraceId; - this.rawResponse = rawResponse; - } - public FacebookAccessTokenErrorResponse(String message, String type, int code, String fbtraceId, String rawResponse) { super(message); @@ -55,15 +36,6 @@ public String getType() { return type; } - /** - * @return code - * @deprecated use {@link #getCodeInt() } - */ - @Deprecated - public String getCode() { - return Integer.toString(codeInt); - } - public int getCodeInt() { return codeInt; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index d626ca159..b1b8c4536 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -4,8 +4,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.net.URI; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; @@ -92,53 +90,9 @@ private OAuth2AccessToken createToken(String rawResponse) throws IOException { protected OAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, JsonNode response, String rawResponse) { - return createToken(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); - } - - /** - * - * @param accessToken accessToken - * @param tokenType tokenType - * @param expiresIn expiresIn - * @param refreshToken refreshToken - * @param scope scope - * @param rawResponse rawResponse - * @return OAuth2AccessToken - * @deprecated use {@link #createToken(java.lang.String, java.lang.String, java.lang.Integer, java.lang.String, - * java.lang.String, com.fasterxml.jackson.databind.JsonNode, java.lang.String)} - */ - @Deprecated - protected OAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, String rawResponse) { return new OAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); } - /** - * - * @param response response - * @param regexPattern regexPattern - * @param required required - * @return parameter value - * @throws OAuthException OAuthException - * @deprecated use {@link #extractRequiredParameter(com.fasterxml.jackson.databind.JsonNode, java.lang.String, - * java.lang.String)} - */ - @Deprecated - protected static String extractParameter(String response, Pattern regexPattern, boolean required) - throws OAuthException { - final Matcher matcher = regexPattern.matcher(response); - if (matcher.find()) { - return matcher.group(1); - } - - if (required) { - throw new OAuthException("Response body is incorrect. Can't extract a '" + regexPattern.pattern() - + "' from this: '" + response + "'", null); - } - - return null; - } - protected static JsonNode extractRequiredParameter(JsonNode errorNode, String parameterName, String rawResponse) throws OAuthException { final JsonNode value = errorNode.get(parameterName); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java index 8d78f15c6..f36572e0a 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java @@ -12,73 +12,14 @@ public class OAuth2AccessTokenErrorResponse extends OAuthException { private static final long serialVersionUID = 2309424849700276816L; - /** - * @deprecated use {@link com.github.scribejava.core.oauth2.OAuth2Error} - */ - @Deprecated - public enum ErrorCode { - INVALID_REQUEST("invalid_request"), - INVALID_CLIENT("invalid_client"), - INVALID_GRANT("invalid_grant"), - UNAUTHORIZED_CLIENT("unauthorized_client"), - UNSUPPORTED_GRANT_TYPE("unsupported_grant_type"), - INVALID_SCOPE("invalid_scope"), - /** - * @see RFC 7009, 2.2.1. Error Response - */ - UNSUPPORTED_TOKEN_TYPE("unsupported_token_type"); - - private final String errorCodeString; - - ErrorCode(String errorCodeString) { - this.errorCodeString = errorCodeString; - } - - public static ErrorCode parseFrom(String errorCodeString) { - for (ErrorCode errorCode : ErrorCode.values()) { - if (errorCode.errorCodeString.equals(errorCodeString)) { - return errorCode; - } - } - throw new IllegalArgumentException("there is no knowlege about '" + errorCodeString + "' ErrorCode"); - } - } - - private final ErrorCode errorCode; private final OAuth2Error error; private final String errorDescription; private final URI errorUri; private final String rawResponse; - /** - * @param errorCode errorCode - * @param errorDescription errorDescription - * @param errorUri errorUri - * @param rawResponse rawResponse - * @deprecated use {@link #OAuth2AccessTokenErrorResponse(com.github.scribejava.core.oauth2.OAuth2Error, - * java.lang.String, java.net.URI, java.lang.String)} - */ - @Deprecated - public OAuth2AccessTokenErrorResponse(ErrorCode errorCode, String errorDescription, URI errorUri, - String rawResponse) { - super(rawResponse); - this.errorCode = errorCode; - this.error = OAuth2Error.parseFrom(errorCode.errorCodeString); - this.errorDescription = errorDescription; - this.errorUri = errorUri; - this.rawResponse = rawResponse; - } - public OAuth2AccessTokenErrorResponse(OAuth2Error error, String errorDescription, URI errorUri, String rawResponse) { super(rawResponse); - ErrorCode oldErrorCode; - try { - oldErrorCode = ErrorCode.parseFrom(error.getErrorString()); - } catch (IllegalArgumentException iaE) { - oldErrorCode = null; - } - this.errorCode = oldErrorCode; this.error = error; this.errorDescription = errorDescription; this.errorUri = errorUri; @@ -89,15 +30,6 @@ public OAuth2Error getError() { return error; } - /** - * @return error code - * @deprecated use {@link #getError() } - */ - @Deprecated - public ErrorCode getErrorCode() { - return errorCode; - } - public String getErrorDescription() { return errorDescription; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java index c041d3efc..79de78d26 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/TokenTypeHint.java @@ -20,16 +20,4 @@ public enum TokenTypeHint { public String getValue() { return value; } - - /** - * @return value - * @deprecated use {@link #getValue() } to get a lower-cased value as in reference (RFC7009), otherwise you can - * continue using this method. Note, that returned value will be UPPER-cased (not overrided toString method) in the - * next release. - */ - @Override - @Deprecated - public String toString() { - return value; - } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java index 7114115be..dcc81929c 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java @@ -70,7 +70,6 @@ public void shouldThrowExceptionIfResponseIsError() throws IOException { extractor.extract(error(body)); fail(); } catch (OAuth2AccessTokenErrorResponse oaer) { - assertEquals(OAuth2AccessTokenErrorResponse.ErrorCode.INVALID_GRANT, oaer.getErrorCode()); assertEquals(OAuth2Error.INVALID_GRANT, oaer.getError()); assertEquals("unknown, invalid, or expired refresh token", oaer.getErrorDescription()); } From dc8cfc3547884259e84a95a5d9fa8920501b3ce7 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 13 Jun 2019 12:27:47 +0300 Subject: [PATCH 323/481] fix NPE for OpenId providers --- changelog | 3 +++ pom.xml | 6 +++--- .../scribejava/apis/openid/OpenIdJsonTokenExtractor.java | 3 ++- scribejava-httpclient-ahc/pom.xml | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/changelog b/changelog index f8da95ca0..aa15ea4ee 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * fix NPE for OpenId providers + [6.6.2] * add PMD checks on compile * add all OAuth error codes from supported RFCs (incl. "invalid_token") (thanks to https://github.com/echorebel) diff --git a/pom.xml b/pom.xml index f2cfc0943..7cea981bd 100644 --- a/pom.xml +++ b/pom.xml @@ -101,12 +101,12 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.0.0 + 3.1.0 com.puppycrawl.tools checkstyle - 8.20 + 8.21 @@ -273,7 +273,7 @@ 7 - 6.14.0 + 6.15.0 diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java index 2b1be532c..1fc441a70 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/openid/OpenIdJsonTokenExtractor.java @@ -23,7 +23,8 @@ public static OpenIdJsonTokenExtractor instance() { @Override protected OpenIdOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, JsonNode response, String rawResponse) { + final JsonNode idToken = response.get("id_token"); return new OpenIdOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, - response.get("id_token").asText(), rawResponse); + idToken == null ? null : idToken.asText(), rawResponse); } } diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 5fc7c4c7b..652c0eae1 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.8.1 + 2.10.0 com.github.scribejava From 0f901f5645876117b4b0d7e3ef6a05953c52ef42 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 13 Jun 2019 13:30:24 +0300 Subject: [PATCH 324/481] prepare v6.6.3 --- README.md | 4 ++-- changelog | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e5031e7e8..a5cfc2014 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.6.2 + 6.6.3 ``` @@ -138,7 +138,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.6.2 + 6.6.3 ``` diff --git a/changelog b/changelog index aa15ea4ee..ffcd2d9d9 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,6 @@ -[SNAPSHOT] +[6.6.3] * fix NPE for OpenId providers - + [6.6.2] * add PMD checks on compile * add all OAuth error codes from supported RFCs (incl. "invalid_token") (thanks to https://github.com/echorebel) From 383aae83accb76997d746aa77c69278c74b0ee04 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 13 Jun 2019 13:31:54 +0300 Subject: [PATCH 325/481] [maven-release-plugin] prepare release scribejava-6.6.3 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 7cea981bd..c6e2e796d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.6.3-SNAPSHOT + 6.6.3 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.6.3 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 9d597784c..f95ad9815 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3-SNAPSHOT + 6.6.3 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 1091ca710..e54187d5f 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3-SNAPSHOT + 6.6.3 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 652c0eae1..afa16aaf2 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3-SNAPSHOT + 6.6.3 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 3187a84b2..122d0e9b1 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3-SNAPSHOT + 6.6.3 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 4b1df3e2b..9f947c8e9 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3-SNAPSHOT + 6.6.3 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 82a8e7d64..3f1b6a524 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3-SNAPSHOT + 6.6.3 ../pom.xml From fce41f9f0a6ce175b8af35722c870843910ee155 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 13 Jun 2019 13:32:00 +0300 Subject: [PATCH 326/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index c6e2e796d..912e6bc49 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.6.3 + 6.6.4-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.6.3 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index f95ad9815..3b4aae7d0 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3 + 6.6.4-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index e54187d5f..2f97a4b6b 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3 + 6.6.4-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index afa16aaf2..586d72f06 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3 + 6.6.4-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 122d0e9b1..1b59210c0 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3 + 6.6.4-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 9f947c8e9..8f45e0314 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3 + 6.6.4-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 3f1b6a524..15173147d 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.3 + 6.6.4-SNAPSHOT ../pom.xml From d717dca2243f8563c0b3100a8f9668d2bc180bdc Mon Sep 17 00:00:00 2001 From: Steve Martin De Souza <4013768+stevedes77@users.noreply.github.com> Date: Sun, 21 Jul 2019 14:34:43 +0900 Subject: [PATCH 327/481] Add OAuth2 API for Meetup.com --- README.md | 2 +- changelog | 3 + .../github/scribejava/apis/MeetupApi20.java | 34 ++++++++++ .../apis/examples/Meetup20Example.java | 66 +++++++++++++++++++ 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi20.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java diff --git a/README.md b/README.md index a5cfc2014..3d4c6122e 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ ScribeJava support out-of-box several HTTP clients: * LinkedIn (https://www.linkedin.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java), [example with custom scopes](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java) * Mail.Ru (https://mail.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java), [example with Async Ning HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java) * MediaWiki (https://www.mediawiki.org/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java) -* Meetup (http://www.meetup.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java) +* Meetup (http://www.meetup.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java) * Microsoft Azure Active Directory (Azure AD) (http://azure.microsoft.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java) * Microsoft Azure Active Directory (Azure AD) 2.0 (http://azure.microsoft.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java) * Microsoft Live (https://login.live.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java) diff --git a/changelog b/changelog index ffcd2d9d9..23d5ea51e 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * Add OAuth2 support for Meetup.com + [6.6.3] * fix NPE for OpenId providers diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi20.java new file mode 100644 index 000000000..ce09e931d --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MeetupApi20.java @@ -0,0 +1,34 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; + +public class MeetupApi20 extends DefaultApi20 { + + protected MeetupApi20() { + } + + private static class InstanceHolder { + private static final MeetupApi20 INSTANCE = new MeetupApi20(); + } + + public static MeetupApi20 instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://secure.meetup.com/oauth2/access"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://secure.meetup.com/oauth2/authorize"; + } + + @Override + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java new file mode 100644 index 000000000..02d125d42 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java @@ -0,0 +1,66 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.MeetupApi20; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.*; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.IOException; +import java.util.Random; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public class Meetup20Example { + + private static final String NETWORK_NAME = "Meetup"; + private static final String PROTECTED_RESOURCE_URL = " https://api.meetup.com/self/groups"; + + private Meetup20Example() { + } + + @SuppressWarnings("PMD.SystemPrintln") + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your Meetup consumer id and secret + final String consumerKey = "your consumer key"; + final String consumerSecret = "your consumer secret"; + final OAuth20Service service = new ServiceBuilder(consumerKey) + .apiSecret(consumerSecret) + .defaultScope("basic") // replace with desired scopes + .callback("http://example.com/callback") // replace with appropriate URI for your consumer, + // see https://www.meetup.com/meetup_api/auth/#redirect_uris + .build(MeetupApi20.instance()); + final Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String secretState = "secret" + new Random().nextInt(999_999); + final String authorizationUrl = service.getAuthorizationUrl(secretState); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("Trading the Authorization Code for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + System.out.println("Now we're going to the user's groups...."); + + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + final Response response = service.execute(request); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + } +} From 5d9939034fe7bce54ba6d40f5e8e6d5d98b0fe39 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 22 Jul 2019 15:33:30 +0300 Subject: [PATCH 328/481] Add OAuth2 support for Meetup.com (thanks to https://github.com/stevedes77) --- README.md | 2 +- changelog | 2 +- .../com/github/scribejava/apis/examples/Meetup20Example.java | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3d4c6122e..067d0ba87 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ ScribeJava support out-of-box several HTTP clients: * LinkedIn (https://www.linkedin.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java), [example with custom scopes](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java) * Mail.Ru (https://mail.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java), [example with Async Ning HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java) * MediaWiki (https://www.mediawiki.org/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java) -* Meetup (http://www.meetup.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java) +* Meetup (https://www.meetup.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java) * Microsoft Azure Active Directory (Azure AD) (http://azure.microsoft.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java) * Microsoft Azure Active Directory (Azure AD) 2.0 (http://azure.microsoft.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java) * Microsoft Live (https://login.live.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java) diff --git a/changelog b/changelog index 23d5ea51e..2097f8374 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,5 @@ [SNAPSHOT] - * Add OAuth2 support for Meetup.com + * Add OAuth2 support for Meetup.com (thanks to https://github.com/stevedes77) [6.6.3] * fix NPE for OpenId providers diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java index 02d125d42..1c83722a0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java @@ -2,7 +2,10 @@ import com.github.scribejava.apis.MeetupApi20; import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.core.model.*; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; From c2023397cf81452d755a5401fe95b1d47dbde48a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 22 Jul 2019 16:58:40 +0300 Subject: [PATCH 329/481] upgrade okhttp to 4.0.1 and security fix for jackson-databind 2.9.9.1 --- changelog | 1 + pom.xml | 10 +++++----- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- .../scribejava/httpclient/okhttp/OkHttpHttpClient.java | 6 +++--- .../okhttp/OAuthAsyncCompletionHandlerTest.java | 6 +++--- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/changelog b/changelog index 2097f8374..10af8fe8c 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * Add OAuth2 support for Meetup.com (thanks to https://github.com/stevedes77) + * upgrade okhttp to 4.0.1 and security fix for jackson-databind 2.9.9.1 [6.6.3] * fix NPE for OpenId providers diff --git a/pom.xml b/pom.xml index 912e6bc49..1c54a74d2 100644 --- a/pom.xml +++ b/pom.xml @@ -56,7 +56,7 @@ com.fasterxml.jackson.core jackson-databind - 2.9.9 + 2.9.9.1 junit @@ -67,7 +67,7 @@ com.squareup.okhttp3 mockwebserver - 3.14.2 + 4.0.1 test @@ -106,7 +106,7 @@ com.puppycrawl.tools checkstyle - 8.21 + 8.22 @@ -187,7 +187,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.1.0 + 3.1.1 ${java.home}/bin/javadoc UTF-8 @@ -273,7 +273,7 @@ 7 - 6.15.0 + 6.16.0 diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 586d72f06..7913ad0ff 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.10.0 + 2.10.1 com.github.scribejava diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 1b59210c0..d8cf139bf 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -23,7 +23,7 @@ org.apache.httpcomponents httpclient - 4.5.8 + 4.5.9 org.apache.httpcomponents diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 15173147d..22f16acec 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 3.14.2 + 4.0.1 com.github.scribejava diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 4f3e7e434..67df4b089 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -165,19 +165,19 @@ private enum BodyType { BYTE_ARRAY { @Override RequestBody createBody(MediaType mediaType, Object bodyContents) { - return RequestBody.create(mediaType, (byte[]) bodyContents); + return RequestBody.create((byte[]) bodyContents, mediaType); } }, STRING { @Override RequestBody createBody(MediaType mediaType, Object bodyContents) { - return RequestBody.create(mediaType, (String) bodyContents); + return RequestBody.create((String) bodyContents, mediaType); } }, FILE { @Override RequestBody createBody(MediaType mediaType, Object bodyContents) { - return RequestBody.create(mediaType, (File) bodyContents); + return RequestBody.create((File) bodyContents, mediaType); } }; diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java index 645c45557..93d3c01f1 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java @@ -78,7 +78,7 @@ public void shouldReleaseLatchOnSuccess() throws Exception { .protocol(Protocol.HTTP_1_1) .code(200) .message("ok") - .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])) + .body(ResponseBody.create(new byte[0], MediaType.get("text/plain"))) .build(); handler.onResponse(call, response); assertNotNull(callback.getResponse()); @@ -98,7 +98,7 @@ public void shouldReleaseLatchOnIOException() throws Exception { .protocol(Protocol.HTTP_1_1) .code(200) .message("ok") - .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])) + .body(ResponseBody.create(new byte[0], MediaType.get("text/plain"))) .build(); handler.onResponse(call, response); assertNull(callback.getResponse()); @@ -124,7 +124,7 @@ public void shouldReportOAuthException() throws Exception { .protocol(Protocol.HTTP_1_1) .code(200) .message("ok") - .body(ResponseBody.create(MediaType.get("text/plain"), new byte[0])) + .body(ResponseBody.create(new byte[0], MediaType.get("text/plain"))) .build(); handler.onResponse(call, response); assertNull(callback.getResponse()); From ee344bb146dc45df831da27ef93dc35ad62a7a58 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 22 Jul 2019 17:09:16 +0300 Subject: [PATCH 330/481] prepare v6.7.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 067d0ba87..b1ef40366 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.6.3 + 6.7.0 ``` @@ -138,7 +138,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.6.3 + 6.7.0 ``` diff --git a/changelog b/changelog index 10af8fe8c..17adb113e 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.7.0] * Add OAuth2 support for Meetup.com (thanks to https://github.com/stevedes77) * upgrade okhttp to 4.0.1 and security fix for jackson-databind 2.9.9.1 From 17df0f844077dbb0e3c88b2f6b2b1a50bf67646a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 22 Jul 2019 17:10:51 +0300 Subject: [PATCH 331/481] [maven-release-plugin] prepare release scribejava-6.7.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 1c54a74d2..a5c60ce49 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.6.4-SNAPSHOT + 6.7.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.7.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 3b4aae7d0..ed433de6a 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.4-SNAPSHOT + 6.7.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 2f97a4b6b..778ccecc0 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.4-SNAPSHOT + 6.7.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 7913ad0ff..ada37d03d 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.4-SNAPSHOT + 6.7.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index d8cf139bf..d6a37e376 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.4-SNAPSHOT + 6.7.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 8f45e0314..85c71889d 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.4-SNAPSHOT + 6.7.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 22f16acec..0b9e9510c 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.6.4-SNAPSHOT + 6.7.0 ../pom.xml From 387f95819adfe407e46cdb428be67f16112f4b28 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 22 Jul 2019 17:11:03 +0300 Subject: [PATCH 332/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index a5c60ce49..2e3434293 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.7.0 + 6.7.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.7.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index ed433de6a..2fe76f005 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.0 + 6.7.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 778ccecc0..3b8cfb6d0 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.0 + 6.7.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index ada37d03d..3eb2f9511 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.0 + 6.7.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index d6a37e376..38e123910 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.0 + 6.7.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 85c71889d..b99eb1bca 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.0 + 6.7.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 0b9e9510c..838b87ac5 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.0 + 6.7.1-SNAPSHOT ../pom.xml From 6e85a3bc7335e5732c009429747c49561314b153 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 30 Jul 2019 15:14:08 +0300 Subject: [PATCH 333/481] always set Content-Length header in case of method defines a meaning for an enclosed payload body. --- .../core/httpclient/jdk/JDKHttpClient.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index ee459cf51..9a9dbef4b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -192,7 +192,10 @@ private static void addHeaders(HttpURLConnection connection, Map private static void addBody(HttpURLConnection connection, byte[] content, boolean requiresBody) throws IOException { final int contentLength = content.length; if (requiresBody || contentLength > 0) { - prepareConnectionForBodyAndGetOutputStream(connection, contentLength).write(content); + final OutputStream outputStream = prepareConnectionForBodyAndGetOutputStream(connection, contentLength); + if (contentLength > 0) { + outputStream.write(content); + } } } @@ -205,9 +208,10 @@ private static void addBody(HttpURLConnection connection, MultipartPayload multi if (requiresBody) { final ByteArrayOutputStream os = getPayload(multipartPayload); - - if (os.size() > 0) { - os.writeTo(prepareConnectionForBodyAndGetOutputStream(connection, os.size())); + final int contentLength = os.size(); + final OutputStream outputStream = prepareConnectionForBodyAndGetOutputStream(connection, contentLength); + if (contentLength > 0) { + os.writeTo(outputStream); } } } @@ -261,8 +265,11 @@ private static OutputStream prepareConnectionForBodyAndGetOutputStream(HttpURLCo if (connection.getRequestProperty(CONTENT_TYPE) == null) { connection.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } - connection.setDoOutput(true); - return connection.getOutputStream(); + if (contentLength > 0) { + connection.setDoOutput(true); + return connection.getOutputStream(); + } else { + return null; + } } - } From f6c5fc49146e9624aa9e57e0714991482a7fea74 Mon Sep 17 00:00:00 2001 From: Robert Barbey Date: Thu, 1 Aug 2019 00:04:28 +0200 Subject: [PATCH 334/481] Pulled up `debugStream` into `OAuthService` - this way both `OAuth10aService` and `OAuth20Service` can use it - adjusted constructors for various `*Api` and corresponding `*Service` implementations --- .../github/scribejava/apis/FacebookApi.java | 9 ++++++--- .../com/github/scribejava/apis/ImgurApi.java | 9 ++++++--- .../com/github/scribejava/apis/MailruApi.java | 9 ++++++--- .../scribejava/apis/OdnoklassnikiApi.java | 10 ++++++---- .../github/scribejava/apis/WunderlistAPI.java | 9 ++++++--- .../apis/facebook/FacebookService.java | 8 ++++++-- .../apis/imgur/ImgurOAuthService.java | 8 ++++++-- .../apis/mailru/MailruOAuthService.java | 8 ++++++-- .../OdnoklassnikiOAuthService.java | 9 ++++++--- .../wunderlist/WunderlistOAuthService.java | 9 ++++++--- .../core/builder/ServiceBuilder.java | 8 ++++---- .../core/builder/api/DefaultApi20.java | 7 +++++-- .../scribejava/core/oauth/OAuth10aService.java | 15 +-------------- .../scribejava/core/oauth/OAuth20Service.java | 6 ++++-- .../scribejava/core/oauth/OAuthService.java | 18 ++++++++++++++++-- .../scribejava/core/AbstractClientTest.java | 3 ++- .../scribejava/core/oauth/OAuth20ApiUnit.java | 9 ++++++--- .../core/oauth/OAuth20ServiceUnit.java | 7 +++++-- 18 files changed, 103 insertions(+), 58 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index a7d81e8b1..9c3ee7a46 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -1,5 +1,7 @@ package com.github.scribejava.apis; +import java.io.OutputStream; + import com.github.scribejava.apis.facebook.FacebookAccessTokenJsonExtractor; import com.github.scribejava.apis.facebook.FacebookService; import com.github.scribejava.core.builder.api.DefaultApi20; @@ -71,8 +73,9 @@ public ClientAuthentication getClientAuthentication() { @Override public FacebookService createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new FacebookService(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, - httpClientConfig, httpClient); + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return new FacebookService(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, + userAgent, httpClientConfig, httpClient); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index 0a7aced8f..6c45b1d79 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -6,6 +6,8 @@ import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.ParameterList; + +import java.io.OutputStream; import java.util.Map; public class ImgurApi extends DefaultApi20 { @@ -55,9 +57,10 @@ protected String getAuthorizationBaseUrl() { @Override public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new ImgurOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, - httpClientConfig, httpClient); + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return new ImgurOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, + userAgent, httpClientConfig, httpClient); } public static boolean isOob(String callback) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index c10dd0bab..dc1519f50 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -1,5 +1,7 @@ package com.github.scribejava.apis; +import java.io.OutputStream; + import com.github.scribejava.apis.mailru.MailruOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; @@ -30,8 +32,9 @@ protected String getAuthorizationBaseUrl() { @Override public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new MailruOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, - httpClientConfig, httpClient); + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return new MailruOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, + userAgent, httpClientConfig, httpClient); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index d1cdcedb0..d6bfe7690 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -1,5 +1,7 @@ package com.github.scribejava.apis; +import java.io.OutputStream; + import com.github.scribejava.apis.odnoklassniki.OdnoklassnikiOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; @@ -34,10 +36,10 @@ protected String getAuthorizationBaseUrl() { @Override public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, - String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - return new OdnoklassnikiOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, - httpClientConfig, httpClient); + String defaultScope, String responseType, OutputStream debugStream, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + return new OdnoklassnikiOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, + userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java index 89f070fa4..7283c3ecf 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java @@ -1,5 +1,7 @@ package com.github.scribejava.apis; +import java.io.OutputStream; + import com.github.scribejava.apis.wunderlist.WunderlistOAuthService; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; @@ -49,8 +51,9 @@ public ClientAuthentication getClientAuthentication() { @Override public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new WunderlistOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, - httpClientConfig, httpClient); + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return new WunderlistOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, + userAgent, httpClientConfig, httpClient); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java index 728d9349a..f1f79ad88 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java @@ -5,6 +5,8 @@ import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.OutputStream; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.Formatter; @@ -14,8 +16,10 @@ public class FacebookService extends OAuth20Service { public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, + httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java index a37d71cbf..589354891 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java @@ -1,5 +1,7 @@ package com.github.scribejava.apis.imgur; +import java.io.OutputStream; + import com.github.scribejava.apis.ImgurApi; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; @@ -13,8 +15,10 @@ public class ImgurOAuthService extends OAuth20Service { public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, + httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java index b3f8c4770..ab8294139 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java @@ -8,6 +8,8 @@ import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.security.MessageDigest; @@ -17,8 +19,10 @@ public class MailruOAuthService extends OAuth20Service { public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, + httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java index c168aafcc..a06b3f0c2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java @@ -7,6 +7,8 @@ import com.github.scribejava.core.model.Parameter; import com.github.scribejava.core.model.ParameterList; import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; @@ -20,9 +22,10 @@ public class OdnoklassnikiOAuthService extends OAuth20Service { public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, - String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); + String defaultScope, String responseType, OutputStream debugStream, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, + httpClient); } @Override diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java index 94e72b044..06a248d9c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java @@ -1,5 +1,7 @@ package com.github.scribejava.apis.wunderlist; +import java.io.OutputStream; + import com.github.scribejava.apis.WunderlistAPI; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; @@ -9,9 +11,10 @@ public class WunderlistOAuthService extends OAuth20Service { public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, - String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); + String defaultScope, String responseType, OutputStream debugStream, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, + httpClient); } @Override diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index bbc68b571..c35e0429d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -68,7 +68,7 @@ public ServiceBuilderOAuth10a withScope(String scope) { } @Override - public ServiceBuilderOAuth10a debugStream(OutputStream debugStream) { + public ServiceBuilder debugStream(OutputStream debugStream) { Preconditions.checkNotNull(debugStream, "debug stream can't be null"); this.debugStream = debugStream; return this; @@ -101,7 +101,7 @@ public ServiceBuilder userAgent(String userAgent) { } @Override - public ServiceBuilderOAuth10a debug() { + public ServiceBuilder debug() { return debugStream(System.out); } @@ -113,7 +113,7 @@ public OAuth10aService build(DefaultApi10a api) { @Override public OAuth20Service build(DefaultApi20 api) { - return api.createService(apiKey, apiSecret, callback, scope, responseType, userAgent, httpClientConfig, - httpClient); + return api.createService(apiKey, apiSecret, callback, scope, responseType, debugStream, userAgent, + httpClientConfig, httpClient); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 92ad8fab7..64ad82f00 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -13,6 +13,8 @@ import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureAuthorizationRequestHeaderField; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.HttpBasicAuthenticationScheme; + +import java.io.OutputStream; import java.util.Map; /** @@ -106,8 +108,9 @@ public String getAuthorizationUrl(String responseType, String apiKey, String cal } public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OAuth20Service(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return new OAuth20Service(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, httpClient); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index 3e67bf1ad..401cba8c9 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -22,14 +22,12 @@ public class OAuth10aService extends OAuthService { private static final String VERSION = "1.0"; - private final OutputStream debugStream; private final DefaultApi10a api; private final String scope; public OAuth10aService(DefaultApi10a api, String apiKey, String apiSecret, String callback, String scope, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(apiKey, apiSecret, callback, userAgent, httpClientConfig, httpClient); - this.debugStream = debugStream; + super(apiKey, apiSecret, callback, debugStream, userAgent, httpClientConfig, httpClient); this.api = api; this.scope = scope; } @@ -192,15 +190,4 @@ protected void appendSignature(OAuthRequest request) { public DefaultApi10a getApi() { return api; } - - public void log(String messagePattern, Object... params) { - if (debugStream != null) { - final String message = String.format(messagePattern, params) + '\n'; - try { - debugStream.write(message.getBytes("UTF8")); - } catch (IOException | RuntimeException e) { - throw new RuntimeException("there were problems while writting to the debug stream", e); - } - } - } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index c80a6496d..ada132d43 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -1,6 +1,7 @@ package com.github.scribejava.core.oauth; import java.io.IOException; +import java.io.OutputStream; import java.util.concurrent.Future; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; @@ -28,8 +29,9 @@ public class OAuth20Service extends OAuthService { private final String defaultScope; public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(apiKey, apiSecret, callback, userAgent, httpClientConfig, httpClient); + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(apiKey, apiSecret, callback, debugStream, userAgent, httpClientConfig, httpClient); this.responseType = responseType; this.api = api; this.defaultScope = defaultScope; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index 4d514381d..cb8680b1f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -12,6 +12,7 @@ import java.io.File; import java.io.IOException; +import java.io.OutputStream; import java.util.ServiceLoader; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -23,12 +24,14 @@ public abstract class OAuthService implements Closeable { private final String callback; private final String userAgent; private final HttpClient httpClient; + private final OutputStream debugStream; - public OAuthService(String apiKey, String apiSecret, String callback, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { + public OAuthService(String apiKey, String apiSecret, String callback, OutputStream debugStream, + String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { this.apiKey = apiKey; this.apiSecret = apiSecret; this.callback = callback; + this.debugStream = debugStream; this.userAgent = userAgent; if (httpClientConfig == null && httpClient == null) { @@ -112,4 +115,15 @@ public Response execute(OAuthRequest request) throws InterruptedException, Execu request.getByteArrayPayload()); } } + + public void log(String messagePattern, Object... params) { + if (debugStream != null) { + final String message = String.format(messagePattern, params) + '\n'; + try { + debugStream.write(message.getBytes("UTF8")); + } catch (IOException | RuntimeException e) { + throw new RuntimeException("there were problems while writting to the debug stream", e); + } + } + } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java index ac4705974..dd94008f6 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java @@ -44,7 +44,8 @@ public Response getResponse() { @Before public void setUp() { - oAuthService = new OAuth20Service(null, "test", "test", null, null, null, null, null, createNewClient()); + oAuthService = new OAuth20Service(null, "test", "test", null, null, null, System.out, null, null, + createNewClient()); } @After diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java index 9b8df0977..cd9e58550 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java @@ -1,5 +1,7 @@ package com.github.scribejava.core.oauth; +import java.io.OutputStream; + import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; @@ -20,9 +22,10 @@ protected String getAuthorizationBaseUrl() { @Override public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return new OAuth20ServiceUnit(this, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, - httpClientConfig, httpClient); + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return new OAuth20ServiceUnit(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, + userAgent, httpClientConfig, httpClient); } @Override diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index 46cf9ee28..2766b7f2b 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -11,6 +11,7 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Parameter; +import java.io.OutputStream; import java.util.HashMap; import java.util.Map; import java.util.concurrent.Future; @@ -23,8 +24,10 @@ class OAuth20ServiceUnit extends OAuth20Service { private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, httpClient); + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, + httpClient); } @Override From f9efe2b05f24e456048f310f927cd2eba20916d8 Mon Sep 17 00:00:00 2001 From: Robert Barbey Date: Thu, 1 Aug 2019 09:53:18 +0200 Subject: [PATCH 335/481] Added log messages for creating requests --- .../scribejava/core/oauth/OAuth20Service.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index ada132d43..57e7143c2 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -40,7 +40,15 @@ public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String //protected to facilitate mocking protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) throws IOException, InterruptedException, ExecutionException { - return api.getAccessTokenExtractor().extract(execute(request)); + log("send request for access token synchronously to %s", request.getCompleteUrl()); + + final Response response = execute(request); + final String body = response.getBody(); + + log("response status code: %s", response.getCode()); + log("response body: %s", body); + + return api.getAccessTokenExtractor().extract(response); } //protected to facilitate mocking @@ -51,10 +59,16 @@ protected Future sendAccessTokenRequestAsync(OAuthRequest req //protected to facilitate mocking protected Future sendAccessTokenRequestAsync(OAuthRequest request, OAuthAsyncRequestCallback callback) { + log("send request for access token asynchronously to %s", request.getCompleteUrl()); return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override public OAuth2AccessToken convert(Response response) throws IOException { + log("received response for access token"); + final String body = response.getBody(); + + log("response status code: %s", response.getCode()); + log("response body: %s", body); return getApi().getAccessTokenExtractor().extract(response); } }); @@ -117,6 +131,9 @@ protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) if (pkceCodeVerifier != null) { request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); } + + log("created access token request with body params [%s], query string params [%s]", request.getBodyParams(), + request.getQueryStringParams()); return request; } @@ -172,6 +189,10 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken, String sco request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); + + log("created refresh token request with body params [%s], query string params [%s]", request.getBodyParams(), + request.getQueryStringParams()); + return request; } @@ -235,6 +256,9 @@ protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, St api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); + log("created access token password grant request with body params [%s], query string params [%s]", + request.getBodyParams(), request.getQueryStringParams()); + return request; } @@ -292,6 +316,10 @@ protected OAuthRequest createAccessTokenClientCredentialsGrantRequest(String sco request.addParameter(OAuthConstants.SCOPE, defaultScope); } request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.CLIENT_CREDENTIALS); + + log("created access token client credentials grant request with body params [%s], query string params [%s]", + request.getBodyParams(), request.getQueryStringParams()); + return request; } @@ -361,6 +389,10 @@ protected OAuthRequest createRevokeTokenRequest(String tokenToRevoke, TokenTypeH if (tokenTypeHint != null) { request.addParameter("token_type_hint", tokenTypeHint.getValue()); } + + log("created revoke token request with body params [%s], query string params [%s]", request.getBodyParams(), + request.getQueryStringParams()); + return request; } From f04ffc7d8322377e976f21c7d1f7b41bae4d821f Mon Sep 17 00:00:00 2001 From: Robert Barbey Date: Thu, 1 Aug 2019 10:38:37 +0200 Subject: [PATCH 336/481] Print params as URL-encoded string --- .../scribejava/core/oauth/OAuth20Service.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 57e7143c2..15cdbf19e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -132,8 +132,9 @@ protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); } - log("created access token request with body params [%s], query string params [%s]", request.getBodyParams(), - request.getQueryStringParams()); + log("created access token request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); return request; } @@ -190,8 +191,9 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken, String sco request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); - log("created refresh token request with body params [%s], query string params [%s]", request.getBodyParams(), - request.getQueryStringParams()); + log("created refresh token request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); return request; } @@ -257,7 +259,8 @@ protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, St api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); log("created access token password grant request with body params [%s], query string params [%s]", - request.getBodyParams(), request.getQueryStringParams()); + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); return request; } @@ -318,7 +321,8 @@ protected OAuthRequest createAccessTokenClientCredentialsGrantRequest(String sco request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.CLIENT_CREDENTIALS); log("created access token client credentials grant request with body params [%s], query string params [%s]", - request.getBodyParams(), request.getQueryStringParams()); + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); return request; } @@ -390,8 +394,9 @@ protected OAuthRequest createRevokeTokenRequest(String tokenToRevoke, TokenTypeH request.addParameter("token_type_hint", tokenTypeHint.getValue()); } - log("created revoke token request with body params [%s], query string params [%s]", request.getBodyParams(), - request.getQueryStringParams()); + log("created revoke token request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); return request; } From cafa5429cffd604894d1e031c1f79fb6cf1cabc9 Mon Sep 17 00:00:00 2001 From: Petr Kopotev Date: Thu, 1 Aug 2019 12:48:29 +0300 Subject: [PATCH 337/481] Add OAuth2.0 for Dropbox APIs with example. --- .../github/scribejava/apis/DropboxApi.java | 30 ++++++++ .../apis/examples/DropboxExample.java | 70 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/DropboxApi.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DropboxApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DropboxApi.java new file mode 100644 index 000000000..19988fe86 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DropboxApi.java @@ -0,0 +1,30 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; + +/** + * Dropbox.com Api + */ +public class DropboxApi extends DefaultApi20 { + + protected DropboxApi() { + } + + private static class InstanceHolder { + private static final DropboxApi INSTANCE = new DropboxApi(); + } + + public static DropboxApi instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://api.dropbox.com/oauth2/token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://www.dropbox.com/oauth2/authorize"; + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java new file mode 100644 index 000000000..7aba52e1f --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java @@ -0,0 +1,70 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.DropboxApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.IOException; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public class DropboxExample { + + private static final String NETWORK_NAME = "Dropbox.com"; + private static final String PROTECTED_RESOURCE_URL + = "https://api.dropboxapi.com/2/users/get_space_usage"; + private static final String PAYLOAD = "null"; + private static final String CONTENT_TYPE_NAME = "Content-Type"; + private static final String CONTENT_TYPE_VALUE = "application/json"; + + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "client id"; + final String clientSecret = "client secret"; + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .callback("https://www.example.com/oauth_callback/") + .build(DropboxApi.instance()); + + final Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("Trading the Authorization Code for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL); + request.addHeader(CONTENT_TYPE_NAME, CONTENT_TYPE_VALUE); + request.setPayload(PAYLOAD); + service.signRequest(accessToken, request); + + final Response response = service.execute(request); + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} From 32273dbcabe7a84c2324e4d5fbae1120e99579a0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 13 Aug 2019 11:07:16 +0300 Subject: [PATCH 338/481] Add debug output to OAuth2Service (thanks to https://github.com/rbarbey) --- changelog | 3 + .../github/scribejava/apis/FacebookApi.java | 22 +++++ .../com/github/scribejava/apis/ImgurApi.java | 23 +++++ .../com/github/scribejava/apis/MailruApi.java | 23 +++++ .../scribejava/apis/OdnoklassnikiApi.java | 24 +++++ .../github/scribejava/apis/WunderlistAPI.java | 25 ++++- .../apis/facebook/FacebookService.java | 25 ++++- .../apis/imgur/ImgurOAuthService.java | 23 ++++- .../apis/mailru/MailruOAuthService.java | 25 ++++- .../OdnoklassnikiOAuthService.java | 26 +++++- .../wunderlist/WunderlistOAuthService.java | 22 +++++ .../core/builder/api/DefaultApi20.java | 22 +++++ .../core/oauth/OAuth10aService.java | 51 +++++++--- .../scribejava/core/oauth/OAuth20Service.java | 93 ++++++++++++------- .../scribejava/core/oauth/OAuthService.java | 51 ++++++++-- .../scribejava/core/oauth/OAuth20ApiUnit.java | 22 +++++ .../core/oauth/OAuth20ServiceUnit.java | 22 +++++ 17 files changed, 440 insertions(+), 62 deletions(-) diff --git a/changelog b/changelog index 17adb113e..79c99a206 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * Add debug output to OAuth2Service (thanks to https://github.com/rbarbey) + [6.7.0] * Add OAuth2 support for Meetup.com (thanks to https://github.com/stevedes77) * upgrade okhttp to 4.0.1 and security fix for jackson-databind 2.9.9.1 diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index 9c3ee7a46..9572b0b8d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -71,6 +71,28 @@ public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return FacebookService + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated + @Override + public FacebookService createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + @Override public FacebookService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index 6c45b1d79..b9c67cac3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -16,6 +16,7 @@ protected ImgurApi() { } private static class InstanceHolder { + private static final ImgurApi INSTANCE = new ImgurApi(); } @@ -55,6 +56,28 @@ protected String getAuthorizationBaseUrl() { throw new UnsupportedOperationException("use getAuthorizationUrl instead"); } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return ImgurOAuthService + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated + @Override + public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + @Override public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index dc1519f50..a9d29c9b7 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -13,6 +13,7 @@ protected MailruApi() { } private static class InstanceHolder { + private static final MailruApi INSTANCE = new MailruApi(); } @@ -30,6 +31,28 @@ protected String getAuthorizationBaseUrl() { return "https://connect.mail.ru/oauth/authorize"; } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return MailruOAuthService + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated + @Override + public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + @Override public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index d6bfe7690..f258344a9 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -17,6 +17,7 @@ protected OdnoklassnikiApi() { } private static class InstanceHolder { + private static final OdnoklassnikiApi INSTANCE = new OdnoklassnikiApi(); } @@ -34,6 +35,29 @@ protected String getAuthorizationBaseUrl() { return "https://connect.ok.ru/oauth/authorize"; } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return OdnoklassnikiOAuthService + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated + @Override + public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, + String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + @Override public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java index 7283c3ecf..97b28d279 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java @@ -6,7 +6,6 @@ import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.oauth2.bearersignature.BearerSignature; import com.github.scribejava.core.oauth2.bearersignature.BearerSignatureURIQueryParameter; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; @@ -49,8 +48,30 @@ public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return WunderlistOAuthService + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated @Override - public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, + public WunderlistOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + + @Override + public WunderlistOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { return new WunderlistOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java index f1f79ad88..f54dedc01 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java @@ -1,6 +1,6 @@ package com.github.scribejava.apis.facebook; -import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.apis.FacebookApi; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthRequest; @@ -15,7 +15,28 @@ public class FacebookService extends OAuth20Service { - public FacebookService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use {@link #FacebookService(com.github.scribejava.apis.FacebookApi, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient) } + */ + @Deprecated + public FacebookService(FacebookApi api, String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + + public FacebookService(FacebookApi api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java index 589354891..e590cee42 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java @@ -14,7 +14,28 @@ public class ImgurOAuthService extends OAuth20Service { - public ImgurOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use {@link #ImgurOAuthService(com.github.scribejava.apis.ImgurApi, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient) } + */ + @Deprecated + public ImgurOAuthService(ImgurApi api, String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + + public ImgurOAuthService(ImgurApi api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java index ab8294139..9a6228177 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java @@ -1,9 +1,9 @@ package com.github.scribejava.apis.mailru; +import com.github.scribejava.apis.MailruApi; import java.net.URLDecoder; import java.util.Map; import java.util.TreeMap; -import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthRequest; @@ -18,7 +18,28 @@ public class MailruOAuthService extends OAuth20Service { - public MailruOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use {@link #MailruOAuthService(com.github.scribejava.apis.MailruApi, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient) } + */ + @Deprecated + public MailruOAuthService(MailruApi api, String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + + public MailruOAuthService(MailruApi api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java index a06b3f0c2..0e012b1a4 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java @@ -1,6 +1,6 @@ package com.github.scribejava.apis.odnoklassniki; -import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.apis.OdnoklassnikiApi; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthRequest; @@ -21,7 +21,29 @@ public class OdnoklassnikiOAuthService extends OAuth20Service { - public OdnoklassnikiOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use {@link #OdnoklassnikiOAuthService(com.github.scribejava.apis.OdnoklassnikiApi, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient) } + */ + @Deprecated + public OdnoklassnikiOAuthService(OdnoklassnikiApi api, String apiKey, String apiSecret, String callback, + String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + + public OdnoklassnikiOAuthService(OdnoklassnikiApi api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java index 06a248d9c..e28c910e6 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java @@ -10,6 +10,28 @@ public class WunderlistOAuthService extends OAuth20Service { + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use {@link #WunderlistOAuthService(com.github.scribejava.apis.WunderlistAPI, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient) } + */ + @Deprecated + public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, + String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 64ad82f00..8a4d6115a 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -107,6 +107,28 @@ public String getAuthorizationUrl(String responseType, String apiKey, String cal return parameters.appendTo(getAuthorizationBaseUrl()); } + /** + * + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return OAuth20Service + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated + public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, + httpClient); + } + public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index 401cba8c9..230a9dbd4 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -33,15 +33,18 @@ public OAuth10aService(DefaultApi10a api, String apiKey, String apiSecret, Strin } public OAuth1RequestToken getRequestToken() throws IOException, InterruptedException, ExecutionException { - log("obtaining request token from %s", api.getRequestTokenEndpoint()); + if (isDebug()) { + log("obtaining request token from %s", api.getRequestTokenEndpoint()); + } final OAuthRequest request = prepareRequestTokenRequest(); log("sending request..."); final Response response = execute(request); - final String body = response.getBody(); - - log("response status code: %s", response.getCode()); - log("response body: %s", body); + if (isDebug()) { + final String body = response.getBody(); + log("response status code: %s", response.getCode()); + log("response body: %s", body); + } return api.getRequestTokenExtractor().extract(response); } @@ -50,7 +53,9 @@ public Future getRequestTokenAsync() { } public Future getRequestTokenAsync(OAuthAsyncRequestCallback callback) { - log("async obtaining request token from %s", api.getRequestTokenEndpoint()); + if (isDebug()) { + log("async obtaining request token from %s", api.getRequestTokenEndpoint()); + } final OAuthRequest request = prepareRequestTokenRequest(); return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override @@ -66,7 +71,9 @@ protected OAuthRequest prepareRequestTokenRequest() { if (callback == null) { callback = OAuthConstants.OOB; } - log("setting oauth_callback to %s", callback); + if (isDebug()) { + log("setting oauth_callback to %s", callback); + } request.addOAuthParameter(OAuthConstants.CALLBACK, callback); addOAuthParams(request, ""); appendSignature(request); @@ -84,12 +91,16 @@ protected void addOAuthParams(OAuthRequest request, String tokenSecret) { } request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, tokenSecret)); - log("appended additional OAuth parameters: %s", request.getOauthParameters()); + if (isDebug()) { + log("appended additional OAuth parameters: %s", request.getOauthParameters()); + } } public OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, String oauthVerifier) throws IOException, InterruptedException, ExecutionException { - log("obtaining access token from %s", api.getAccessTokenEndpoint()); + if (isDebug()) { + log("obtaining access token from %s", api.getAccessTokenEndpoint()); + } final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier); final Response response = execute(request); return api.getAccessTokenExtractor().extract(response); @@ -110,7 +121,9 @@ public Future getAccessTokenAsync(OAuth1RequestToken requestT */ public Future getAccessTokenAsync(OAuth1RequestToken requestToken, String oauthVerifier, OAuthAsyncRequestCallback callback) { - log("async obtaining access token from %s", api.getAccessTokenEndpoint()); + if (isDebug()) { + log("async obtaining access token from %s", api.getAccessTokenEndpoint()); + } final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier); return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override @@ -124,19 +137,25 @@ protected OAuthRequest prepareAccessTokenRequest(OAuth1RequestToken requestToken final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); request.addOAuthParameter(OAuthConstants.TOKEN, requestToken.getToken()); request.addOAuthParameter(OAuthConstants.VERIFIER, oauthVerifier); - log("setting token to: %s and verifier to: %s", requestToken, oauthVerifier); + if (isDebug()) { + log("setting token to: %s and verifier to: %s", requestToken, oauthVerifier); + } addOAuthParams(request, requestToken.getTokenSecret()); appendSignature(request); return request; } public void signRequest(OAuth1AccessToken token, OAuthRequest request) { - log("signing request: %s", request.getCompleteUrl()); + if (isDebug()) { + log("signing request: %s", request.getCompleteUrl()); + } if (!token.isEmpty() || api.isEmptyOAuthTokenParamIsRequired()) { request.addOAuthParameter(OAuthConstants.TOKEN, token.getToken()); } - log("setting token to: %s", token); + if (isDebug()) { + log("setting token to: %s", token); + } addOAuthParams(request, token.getTokenSecret()); appendSignature(request); } @@ -161,8 +180,10 @@ private String getSignature(OAuthRequest request, String tokenSecret) { final String baseString = api.getBaseStringExtractor().extract(request); final String signature = api.getSignatureService().getSignature(baseString, getApiSecret(), tokenSecret); - log("base string is: %s", baseString); - log("signature is: %s", signature); + if (isDebug()) { + log("base string is: %s", baseString); + log("signature is: %s", signature); + } return signature; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 15cdbf19e..74997626c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -28,6 +28,27 @@ public class OAuth20Service extends OAuthService { private final String responseType; private final String defaultScope; + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use {@link #OAuth20Service(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated + public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { @@ -40,13 +61,15 @@ public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String //protected to facilitate mocking protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) throws IOException, InterruptedException, ExecutionException { - log("send request for access token synchronously to %s", request.getCompleteUrl()); - + if (isDebug()) { + log("send request for access token synchronously to %s", request.getCompleteUrl()); + } final Response response = execute(request); - final String body = response.getBody(); - - log("response status code: %s", response.getCode()); - log("response body: %s", body); + if (isDebug()) { + log("response status code: %s", response.getCode()); + final String body = response.getBody(); + log("response body: %s", body); + } return api.getAccessTokenExtractor().extract(response); } @@ -59,16 +82,19 @@ protected Future sendAccessTokenRequestAsync(OAuthRequest req //protected to facilitate mocking protected Future sendAccessTokenRequestAsync(OAuthRequest request, OAuthAsyncRequestCallback callback) { - log("send request for access token asynchronously to %s", request.getCompleteUrl()); + if (isDebug()) { + log("send request for access token asynchronously to %s", request.getCompleteUrl()); + } return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override public OAuth2AccessToken convert(Response response) throws IOException { log("received response for access token"); - final String body = response.getBody(); - - log("response status code: %s", response.getCode()); - log("response body: %s", body); + if (isDebug()) { + log("response status code: %s", response.getCode()); + final String body = response.getBody(); + log("response body: %s", body); + } return getApi().getAccessTokenExtractor().extract(response); } }); @@ -131,10 +157,11 @@ protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) if (pkceCodeVerifier != null) { request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); } - - log("created access token request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); + if (isDebug()) { + log("created access token request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); + } return request; } @@ -190,11 +217,11 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken, String sco request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); - - log("created refresh token request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); - + if (isDebug()) { + log("created refresh token request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); + } return request; } @@ -258,10 +285,11 @@ protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, St api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); - log("created access token password grant request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); - + if (isDebug()) { + log("created access token password grant request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); + } return request; } @@ -320,10 +348,11 @@ protected OAuthRequest createAccessTokenClientCredentialsGrantRequest(String sco } request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.CLIENT_CREDENTIALS); - log("created access token client credentials grant request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); - + if (isDebug()) { + log("created access token client credentials grant request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); + } return request; } @@ -394,9 +423,11 @@ protected OAuthRequest createRevokeTokenRequest(String tokenToRevoke, TokenTypeH request.addParameter("token_type_hint", tokenTypeHint.getValue()); } - log("created revoke token request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); + if (isDebug()) { + log("created revoke token request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); + } return request; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index cb8680b1f..c8101d504 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -26,6 +26,24 @@ public abstract class OAuthService implements Closeable { private final HttpClient httpClient; private final OutputStream debugStream; + /** + * + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use {@link #OAuthService(java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, + * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated + public OAuthService(String apiKey, String apiSecret, String callback, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + this(apiKey, apiSecret, callback, null, userAgent, httpClientConfig, httpClient); + } + public OAuthService(String apiKey, String apiSecret, String callback, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { this.apiKey = apiKey; @@ -116,14 +134,33 @@ public Response execute(OAuthRequest request) throws InterruptedException, Execu } } - public void log(String messagePattern, Object... params) { + /** + * No need to wrap usages in {@link #isDebug()}. + * + * @param message message to log + */ + public void log(String message) { if (debugStream != null) { - final String message = String.format(messagePattern, params) + '\n'; - try { - debugStream.write(message.getBytes("UTF8")); - } catch (IOException | RuntimeException e) { - throw new RuntimeException("there were problems while writting to the debug stream", e); - } + log(message, (Object[]) null); } } + + /** + * Wrap usages in {@link #isDebug()}. It was made for optimization - to not calculate "params" in production mode. + * + * @param messagePattern messagePattern + * @param params params + */ + public void log(String messagePattern, Object... params) { + final String message = String.format(messagePattern, params) + '\n'; + try { + debugStream.write(message.getBytes("UTF8")); + } catch (IOException | RuntimeException e) { + throw new RuntimeException("there were problems while writting to the debug stream", e); + } + } + + protected boolean isDebug() { + return debugStream != null; + } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java index cd9e58550..6ba3e3e20 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java @@ -20,6 +20,28 @@ protected String getAuthorizationBaseUrl() { return "http://localhost:8080/authorize"; } + /** + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @return OAuth20ServiceUnit + * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, + * com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated + @Override + public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + @Override public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index 2766b7f2b..12654051d 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -23,6 +23,28 @@ class OAuth20ServiceUnit extends OAuth20Service { static final int EXPIRES = 3600; private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + /** + * @param api api + * @param apiKey apiKey + * @param apiSecret apiSecret + * @param callback callback + * @param defaultScope defaultScope + * @param responseType responseType + * @param userAgent userAgent + * @param httpClientConfig httpClientConfig + * @param httpClient httpClient + * @deprecated use {@link #OAuth20ServiceUnit(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, + * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} + */ + @Deprecated + OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, + httpClient); + } + OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { From c38249d415974a6040326241ce1c94eef6bf55cc Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 14 Aug 2019 12:51:10 +0300 Subject: [PATCH 339/481] upgrade dependencies --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 2e3434293..e46cd9bfc 100644 --- a/pom.xml +++ b/pom.xml @@ -56,7 +56,7 @@ com.fasterxml.jackson.core jackson-databind - 2.9.9.1 + 2.9.9.3 junit @@ -106,7 +106,7 @@ com.puppycrawl.tools checkstyle - 8.22 + 8.23 @@ -273,7 +273,7 @@ 7 - 6.16.0 + 6.17.0 From 75afd4a28bc48ddfcecc4a2a10b1b3d951d24d05 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 15 Aug 2019 14:33:43 +0300 Subject: [PATCH 340/481] Add Dropbox API (https://www.dropbox.com/) (thanks to https://github.com/petrkopotev) --- README.md | 1 + changelog | 1 + .../main/java/com/github/scribejava/apis/DropboxApi.java | 1 + .../github/scribejava/apis/examples/DropboxExample.java | 7 +++++-- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b1ef40366..6872d69ff 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ ScribeJava support out-of-box several HTTP clients: * Digg (http://digg.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java) * Discord (https://discordapp.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java) * Доктор на работе (https://www.doktornarabote.ru/) +* Dropbox (https://www.dropbox.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java) * Etsy (https://www.etsy.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java) * Facebook (https://www.facebook.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java), [example with Async Apache HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java), [example with Async Ning HTTP client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java) * Fitbit (https://www.fitbit.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java) diff --git a/changelog b/changelog index 79c99a206..02f856b96 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * Add debug output to OAuth2Service (thanks to https://github.com/rbarbey) + * Add Dropbox API (https://www.dropbox.com/) (thanks to https://github.com/petrkopotev) [6.7.0] * Add OAuth2 support for Meetup.com (thanks to https://github.com/stevedes77) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/DropboxApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/DropboxApi.java index 19988fe86..8bbd646f5 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/DropboxApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/DropboxApi.java @@ -11,6 +11,7 @@ protected DropboxApi() { } private static class InstanceHolder { + private static final DropboxApi INSTANCE = new DropboxApi(); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java index 7aba52e1f..4ed799283 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java @@ -15,12 +15,15 @@ public class DropboxExample { private static final String NETWORK_NAME = "Dropbox.com"; - private static final String PROTECTED_RESOURCE_URL - = "https://api.dropboxapi.com/2/users/get_space_usage"; + private static final String PROTECTED_RESOURCE_URL = "https://api.dropboxapi.com/2/users/get_space_usage"; private static final String PAYLOAD = "null"; private static final String CONTENT_TYPE_NAME = "Content-Type"; private static final String CONTENT_TYPE_VALUE = "application/json"; + private DropboxExample() { + } + + @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret final String clientId = "client id"; From e61590899577224e5a5d52b1435d710f6034edaf Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 15 Aug 2019 15:29:33 +0300 Subject: [PATCH 341/481] small typo fix --- .../com/github/scribejava/core/builder/api/DefaultApi20.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 8a4d6115a..8c69ce2f5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -125,7 +125,7 @@ public String getAuthorizationUrl(String responseType, String apiKey, String cal @Deprecated public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, userAgent, httpClientConfig, + return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, httpClient); } From cb9f56d433f389ad86c01670311d2b8d606088eb Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 15 Aug 2019 15:30:15 +0300 Subject: [PATCH 342/481] prepare v6.8.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6872d69ff..16cf3d3ce 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.7.0 + 6.8.0 ``` @@ -139,7 +139,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.7.0 + 6.8.0 ``` diff --git a/changelog b/changelog index 02f856b96..013f62039 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.8.0] * Add debug output to OAuth2Service (thanks to https://github.com/rbarbey) * Add Dropbox API (https://www.dropbox.com/) (thanks to https://github.com/petrkopotev) From 9e33c17c0222d051f293f7d58f45b077296edf6d Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 15 Aug 2019 15:31:50 +0300 Subject: [PATCH 343/481] [maven-release-plugin] prepare release scribejava-6.8.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index e46cd9bfc..ccf904e3d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.7.1-SNAPSHOT + 6.8.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.8.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 2fe76f005..b6c5c4d7a 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.1-SNAPSHOT + 6.8.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 3b8cfb6d0..ea27f8131 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.1-SNAPSHOT + 6.8.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 3eb2f9511..b41ee17dd 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.1-SNAPSHOT + 6.8.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 38e123910..0142231eb 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.1-SNAPSHOT + 6.8.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index b99eb1bca..636ce905d 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.1-SNAPSHOT + 6.8.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 838b87ac5..4b988ec51 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.7.1-SNAPSHOT + 6.8.0 ../pom.xml From 4c516ad78f8dd2ce3de5a08f389d57da106094a0 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 15 Aug 2019 15:31:58 +0300 Subject: [PATCH 344/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index ccf904e3d..d70a2626c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.8.0 + 6.8.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.8.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index b6c5c4d7a..c95ef2b51 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.0 + 6.8.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index ea27f8131..995ea03b5 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.0 + 6.8.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index b41ee17dd..97657ec57 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.0 + 6.8.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 0142231eb..14fcba8b5 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.0 + 6.8.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 636ce905d..1f6453d20 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.0 + 6.8.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 4b988ec51..3006a5d67 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.0 + 6.8.1-SNAPSHOT ../pom.xml From 03321f02e1cc91b5d07e13c0c098640912a1f53b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 15 Aug 2019 16:37:29 +0300 Subject: [PATCH 345/481] drop deprecated --- .../github/scribejava/apis/FacebookApi.java | 22 ------------------ .../com/github/scribejava/apis/ImgurApi.java | 22 ------------------ .../com/github/scribejava/apis/MailruApi.java | 22 ------------------ .../scribejava/apis/OdnoklassnikiApi.java | 23 ------------------- .../github/scribejava/apis/WunderlistAPI.java | 22 ------------------ .../apis/facebook/FacebookService.java | 21 ----------------- .../apis/imgur/ImgurOAuthService.java | 21 ----------------- .../apis/mailru/MailruOAuthService.java | 21 ----------------- .../OdnoklassnikiOAuthService.java | 22 ------------------ .../wunderlist/WunderlistOAuthService.java | 22 ------------------ .../core/builder/api/DefaultApi20.java | 22 ------------------ .../scribejava/core/oauth/OAuth20Service.java | 21 ----------------- .../scribejava/core/oauth/OAuthService.java | 18 --------------- .../scribejava/core/oauth/OAuth20ApiUnit.java | 22 ------------------ .../core/oauth/OAuth20ServiceUnit.java | 22 ------------------ 15 files changed, 323 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index 9572b0b8d..9c3ee7a46 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -71,28 +71,6 @@ public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return FacebookService - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public FacebookService createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - @Override public FacebookService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java index b9c67cac3..845fd95cb 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/ImgurApi.java @@ -56,28 +56,6 @@ protected String getAuthorizationBaseUrl() { throw new UnsupportedOperationException("use getAuthorizationUrl instead"); } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return ImgurOAuthService - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - @Override public ImgurOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java index a9d29c9b7..b48091594 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MailruApi.java @@ -31,28 +31,6 @@ protected String getAuthorizationBaseUrl() { return "https://connect.mail.ru/oauth/authorize"; } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return MailruOAuthService - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - @Override public MailruOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java index f258344a9..b87eaa072 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/OdnoklassnikiApi.java @@ -35,29 +35,6 @@ protected String getAuthorizationBaseUrl() { return "https://connect.ok.ru/oauth/authorize"; } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return OdnoklassnikiOAuthService - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, - String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - @Override public OdnoklassnikiOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java index 97b28d279..abf19db92 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/WunderlistAPI.java @@ -48,28 +48,6 @@ public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return WunderlistOAuthService - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public WunderlistOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - @Override public WunderlistOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java index f54dedc01..efb53a4f3 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookService.java @@ -15,27 +15,6 @@ public class FacebookService extends OAuth20Service { - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use {@link #FacebookService(com.github.scribejava.apis.FacebookApi, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient) } - */ - @Deprecated - public FacebookService(FacebookApi api, String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - public FacebookService(FacebookApi api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java index e590cee42..317934e35 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/imgur/ImgurOAuthService.java @@ -14,27 +14,6 @@ public class ImgurOAuthService extends OAuth20Service { - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use {@link #ImgurOAuthService(com.github.scribejava.apis.ImgurApi, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient) } - */ - @Deprecated - public ImgurOAuthService(ImgurApi api, String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - public ImgurOAuthService(ImgurApi api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java index 9a6228177..a9ff7d77b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/mailru/MailruOAuthService.java @@ -18,27 +18,6 @@ public class MailruOAuthService extends OAuth20Service { - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use {@link #MailruOAuthService(com.github.scribejava.apis.MailruApi, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient) } - */ - @Deprecated - public MailruOAuthService(MailruApi api, String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - public MailruOAuthService(MailruApi api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java index 0e012b1a4..fd1327a6d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/odnoklassniki/OdnoklassnikiOAuthService.java @@ -21,28 +21,6 @@ public class OdnoklassnikiOAuthService extends OAuth20Service { - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use {@link #OdnoklassnikiOAuthService(com.github.scribejava.apis.OdnoklassnikiApi, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient) } - */ - @Deprecated - public OdnoklassnikiOAuthService(OdnoklassnikiApi api, String apiKey, String apiSecret, String callback, - String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - public OdnoklassnikiOAuthService(OdnoklassnikiApi api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java index e28c910e6..06a248d9c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/wunderlist/WunderlistOAuthService.java @@ -10,28 +10,6 @@ public class WunderlistOAuthService extends OAuth20Service { - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use {@link #WunderlistOAuthService(com.github.scribejava.apis.WunderlistAPI, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient) } - */ - @Deprecated - public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, - String defaultScope, String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - public WunderlistOAuthService(WunderlistAPI api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 8c69ce2f5..64ad82f00 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -107,28 +107,6 @@ public String getAuthorizationUrl(String responseType, String apiKey, String cal return parameters.appendTo(getAuthorizationBaseUrl()); } - /** - * - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return OAuth20Service - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 74997626c..45b95d0a8 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -28,27 +28,6 @@ public class OAuth20Service extends OAuthService { private final String responseType; private final String defaultScope; - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use {@link #OAuth20Service(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java index c8101d504..996abee6f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java @@ -26,24 +26,6 @@ public abstract class OAuthService implements Closeable { private final HttpClient httpClient; private final OutputStream debugStream; - /** - * - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use {@link #OAuthService(java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, - * java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - public OAuthService(String apiKey, String apiSecret, String callback, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - this(apiKey, apiSecret, callback, null, userAgent, httpClientConfig, httpClient); - } - public OAuthService(String apiKey, String apiSecret, String callback, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { this.apiKey = apiKey; diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java index 6ba3e3e20..cd9e58550 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ApiUnit.java @@ -20,28 +20,6 @@ protected String getAuthorizationBaseUrl() { return "http://localhost:8080/authorize"; } - /** - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @return OAuth20ServiceUnit - * @deprecated use {@link #createService(java.lang.String, java.lang.String, java.lang.String, java.lang.String, - * java.lang.String, java.io.OutputStream, java.lang.String, com.github.scribejava.core.httpclient.HttpClientConfig, - * com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - @Override - public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - return createService(apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - @Override public OAuth20ServiceUnit createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java index 12654051d..2766b7f2b 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceUnit.java @@ -23,28 +23,6 @@ class OAuth20ServiceUnit extends OAuth20Service { static final int EXPIRES = 3600; private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - /** - * @param api api - * @param apiKey apiKey - * @param apiSecret apiSecret - * @param callback callback - * @param defaultScope defaultScope - * @param responseType responseType - * @param userAgent userAgent - * @param httpClientConfig httpClientConfig - * @param httpClient httpClient - * @deprecated use {@link #OAuth20ServiceUnit(com.github.scribejava.core.builder.api.DefaultApi20, java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.io.OutputStream, java.lang.String, - * com.github.scribejava.core.httpclient.HttpClientConfig, com.github.scribejava.core.httpclient.HttpClient)} - */ - @Deprecated - OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - this(api, apiKey, apiSecret, callback, defaultScope, responseType, null, userAgent, httpClientConfig, - httpClient); - } - OAuth20ServiceUnit(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { From 3ec1be264e5aea1cbacd462c4a29ec1f6376d69d Mon Sep 17 00:00:00 2001 From: Omari Christian Date: Fri, 16 Aug 2019 15:29:56 -0700 Subject: [PATCH 346/481] Add Javadoc regarding closing body stream --- .../java/com/github/scribejava/core/model/Response.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java index 4a84c76ef..a1781cacb 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java @@ -5,6 +5,12 @@ import java.util.Map; import com.github.scribejava.core.utils.StreamUtils; +/** + * An HTTP response. + * + *

    This response may contain a non-null body stream of the HttpUrlConnection. If so, this body must be closed to + * avoid leaking resources. Use either {@code getBody()} or {@code getStream().close()} to close the body. + */ public class Response { private final int code; @@ -45,6 +51,9 @@ public boolean isSuccessful() { return code >= 200 && code < 400; } + /** + * Returns the response body as a string, closing the stream that backs it. Idempotent. + */ public String getBody() throws IOException { return body == null ? parseBodyContents() : body; } From ccf4d52121dc00bb05d6283e2f7c266b01ecf44a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 19 Aug 2019 13:38:47 +0300 Subject: [PATCH 347/481] make Response implements Closeable (thanks to https://github.com/omaric) --- changelog | 3 + .../apis/examples/AWeberExample.java | 9 +- .../apis/examples/AsanaExample.java | 11 +-- .../apis/examples/AutomaticExample.java | 12 +-- .../apis/examples/Box20Example.java | 12 +-- .../apis/examples/DataportenExample.java | 12 +-- .../scribejava/apis/examples/DiggExample.java | 12 +-- .../apis/examples/DiscordExample.java | 12 +-- .../apis/examples/DropboxExample.java | 11 +-- .../scribejava/apis/examples/EtsyExample.java | 10 +-- .../examples/FacebookAsyncApacheExample.java | 12 +-- .../examples/FacebookAsyncNingExample.java | 12 +-- .../apis/examples/FacebookExample.java | 12 +-- .../apis/examples/FitbitApi20Example.java | 8 +- .../apis/examples/FlickrExample.java | 10 +-- .../apis/examples/Foursquare2Example.java | 12 +-- .../apis/examples/FoursquareExample.java | 10 +-- .../apis/examples/FrappeExample.java | 12 +-- .../apis/examples/FreelancerExample.java | 12 +-- .../apis/examples/GeniusExample.java | 12 +-- .../examples/GitHubAsyncOkHttpExample.java | 12 +-- .../apis/examples/GitHubExample.java | 12 +-- .../examples/Google20AsyncAHCExample.java | 8 +- .../apis/examples/Google20Example.java | 8 +- .../apis/examples/Google20RevokeExample.java | 21 +++-- .../examples/Google20WithPKCEExample.java | 8 +- .../scribejava/apis/examples/HHExample.java | 12 +-- .../apis/examples/HiOrgServerExample.java | 12 +-- .../apis/examples/ImgurExample.java | 12 +-- .../apis/examples/Kaixin20Example.java | 12 +-- .../apis/examples/KeycloakExample.java | 12 +-- .../apis/examples/LinkedIn20Example.java | 15 ++-- .../apis/examples/LinkedInExample.java | 9 +- .../examples/LinkedInExampleWithScopes.java | 9 +- .../scribejava/apis/examples/LiveExample.java | 11 +-- .../apis/examples/MailruAsyncExample.java | 11 +-- .../apis/examples/MailruExample.java | 11 +-- .../apis/examples/MediaWikiExample.java | 9 +- .../apis/examples/Meetup20Example.java | 7 +- .../apis/examples/MeetupExample.java | 9 +- ...icrosoftAzureActiveDirectory20Example.java | 11 +-- .../MicrosoftAzureActiveDirectoryExample.java | 11 +-- .../apis/examples/MisfitExample.java | 11 +-- .../apis/examples/NaverExample.java | 11 +-- .../apis/examples/OdnoklassnikiExample.java | 13 +-- .../apis/examples/PinterestExample.java | 11 +-- .../apis/examples/Px500Example.java | 9 +- .../apis/examples/RenrenExample.java | 11 +-- .../apis/examples/SalesforceExample.java | 8 +- .../examples/SalesforceNingAsyncExample.java | 7 +- .../apis/examples/SinaWeibo2Example.java | 11 +-- .../apis/examples/SinaWeiboExample.java | 11 +-- .../apis/examples/SkyrockExample.java | 11 +-- .../apis/examples/StackExchangeExample.java | 11 +-- .../TheThingsNetworkV1StagingExample.java | 25 +++--- .../TheThingsNetworkV2PreviewExample.java | 27 +++--- .../apis/examples/TrelloExample.java | 10 +-- .../apis/examples/TumblrExample.java | 10 +-- .../apis/examples/TutByExample.java | 12 +-- .../apis/examples/TwitterExample.java | 10 +-- .../scribejava/apis/examples/UcozExample.java | 12 +-- .../apis/examples/ViadeoExample.java | 12 +-- .../apis/examples/VkontakteExample.java | 12 +-- .../VkontakteExternalHttpExample.java | 12 +-- .../apis/examples/WunderlistExample.java | 12 +-- .../scribejava/apis/examples/XingExample.java | 10 +-- .../apis/examples/Yahoo20Example.java | 12 +-- .../apis/examples/YahooExample.java | 12 +-- .../FacebookAccessTokenJsonExtractorTest.java | 4 +- .../scribejava/core/model/Response.java | 27 ++++-- .../core/oauth/OAuth10aService.java | 18 ++-- .../scribejava/core/oauth/OAuth20Service.java | 19 +++-- .../scribejava/core/AbstractClientTest.java | 30 +++---- .../OAuth1AccessTokenExtractorTest.java | 50 +++++++---- .../OAuth2AccessTokenExtractorTest.java | 50 +++++++---- .../OAuth2AccessTokenJsonExtractorTest.java | 83 ++++++++++++------- 76 files changed, 581 insertions(+), 471 deletions(-) diff --git a/changelog b/changelog index 013f62039..77161cd52 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * make Response implements Closeable (thanks to https://github.com/omaric) + [6.8.0] * Add debug output to OAuth2Service (thanks to https://github.com/rbarbey) * Add Dropbox API (https://www.dropbox.com/) (thanks to https://github.com/petrkopotev) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index e77555d7c..635017b52 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -58,10 +58,11 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, ACCOUNT_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with AWeber and ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java index 4320fbe6e..1ab4d3d3c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java @@ -69,11 +69,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java index 7174b0eb3..ae0c299f2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java @@ -71,12 +71,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java index 4dd9fad9f..11673af20 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Box20Example.java @@ -79,12 +79,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java index 72dbba843..fe8fada2a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DataportenExample.java @@ -68,12 +68,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index 3b1d0ad61..1f84a45ed 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -62,12 +62,12 @@ public static void main(String... args) throws IOException, InterruptedException final OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL); request.addBodyParameter("comment_id", "20100729223726:4fef610331ee46a3b5cbd740bf71313e"); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java index facca275b..f42bde9ec 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiscordExample.java @@ -78,12 +78,12 @@ public static void main(String... args) throws IOException, ExecutionException, System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java index 4ed799283..bcf02624a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DropboxExample.java @@ -61,11 +61,12 @@ public static void main(String... args) throws IOException, InterruptedException request.setPayload(PAYLOAD); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java index e39877ef6..ad55cb07c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/EtsyExample.java @@ -55,11 +55,11 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("That's it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java index 337a11e40..29d8dba96 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java @@ -73,12 +73,12 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java index 073df9ebe..29c52cbad 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java @@ -81,12 +81,12 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java index cd9a7db9b..db8f6bdea 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java @@ -69,12 +69,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java index 20ca7372b..e5818a92a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FitbitApi20Example.java @@ -71,11 +71,11 @@ public static void main(String... args) throws Exception { service.signRequest(accessToken, request); - final Response response = service.execute(request); System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index 5c37b1248..5da371ca6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -60,11 +60,11 @@ public static void main(String... args) throws IOException, InterruptedException final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); request.addQuerystringParameter("method", "flickr.test.login"); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java index 69d9277f0..cdd29180a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Foursquare2Example.java @@ -54,12 +54,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + accessToken.getAccessToken()); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index 236d9b686..c7b09ca2e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -53,11 +53,11 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java index 64751a92d..827f8aacd 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FrappeExample.java @@ -57,12 +57,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, clientDomain + PROTECTED_RESOURCE_PATH); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index 84cc45c2f..019f7efa0 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -60,12 +60,12 @@ public static void main(String... args) throws IOException, InterruptedException final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); request.addHeader("GData-Version", "3.0"); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java index 71ebfc1f9..9749a168e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GeniusExample.java @@ -77,12 +77,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Accessing a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Viewing contents..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Viewing contents..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java index abecfd03b..a0c94792c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java @@ -73,12 +73,12 @@ public static void main(String... args) throws IOException, ExecutionException, System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java index 59302a752..bfd3f2512 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubExample.java @@ -68,12 +68,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java index f9214f05f..a894db2bf 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java @@ -114,11 +114,11 @@ public static void main(String... args) throws InterruptedException, ExecutionEx final OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl); service.signRequest(accessToken, request); - final Response response = service.execute(request); System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 4c23c3287..6631849bf 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -100,11 +100,11 @@ public static void main(String... args) throws IOException, InterruptedException final OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl); service.signRequest(accessToken, request); - final Response response = service.execute(request); System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java index 384183553..ba513ca52 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java @@ -79,12 +79,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - Response response = service.execute(request); System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); - System.out.println("Revoking token..."); service.revokeToken(accessToken.getAccessToken()); System.out.println("done."); @@ -92,15 +92,18 @@ public static void main(String... args) throws IOException, InterruptedException in.nextLine(); //Google Note: Following a successful revocation response, //it might take some time before the revocation has full effect. - while (response.getCode() == 200) { + int responseCode; + do { Thread.sleep(1000); request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - response = service.execute(request); System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + responseCode = response.getCode(); + System.out.println(responseCode); + System.out.println(response.getBody()); + } System.out.println(); - } + } while (responseCode == 200); } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java index 5f9bb3e15..8c840b8d5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java @@ -106,11 +106,11 @@ public static void main(String... args) throws IOException, InterruptedException final OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl); service.signRequest(accessToken, request); - final Response response = service.execute(request); System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java index 3e9f7b892..c013b7d2b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java @@ -55,12 +55,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java index b2a764883..2602d1257 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java @@ -79,12 +79,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java index d804ed5d4..229e3a7ee 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java @@ -55,12 +55,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java index e354722a6..482453cb4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java @@ -55,12 +55,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java index 242ba46c6..2d78ffb97 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java @@ -59,12 +59,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, protectedResourceUrl); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java index b77a08c61..9c5083386 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java @@ -60,11 +60,11 @@ public static void main(String... args) throws IOException, InterruptedException emailRequest.addHeader("x-li-format", "json"); emailRequest.addHeader("Accept-Language", "ru-RU"); service.signRequest(accessToken, emailRequest); - final Response emailResponse = service.execute(emailRequest); System.out.println(); - System.out.println(emailResponse.getCode()); - System.out.println(emailResponse.getBody()); - + try (Response emailResponse = service.execute(emailRequest)) { + System.out.println(emailResponse.getCode()); + System.out.println(emailResponse.getBody()); + } System.out.println(); System.out.println("Now we're going to access a protected profile resource..."); @@ -73,10 +73,11 @@ public static void main(String... args) throws IOException, InterruptedException request.addHeader("x-li-format", "json"); request.addHeader("Accept-Language", "ru-RU"); service.signRequest(accessToken, request); - final Response response = service.execute(request); System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index ce7849b1d..abb53baf4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -54,10 +54,11 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index 537c06104..fe2b395ac 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -58,10 +58,11 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java index 2e2109e28..2c8635a1a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LiveExample.java @@ -54,11 +54,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java index 0dffbd4d3..1ad9f56cc 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java @@ -67,12 +67,13 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java index fe5df3e51..4eb4c7aff 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java @@ -55,11 +55,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java index e3a998ec8..8aaef6673 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java @@ -59,10 +59,11 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, API_USERINFO_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with MediaWiki and ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java index 1c83722a0..f64ec246b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Meetup20Example.java @@ -59,10 +59,11 @@ public static void main(String... args) throws IOException, InterruptedException final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index 62b01866a..ad6a9bc25 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -53,10 +53,11 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java index 9f9e0afce..71f346bc6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectory20Example.java @@ -51,11 +51,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java index 4d7e6c40e..6c9610f06 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MicrosoftAzureActiveDirectoryExample.java @@ -57,11 +57,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java index 309e34237..65e048499 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java @@ -58,11 +58,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java index 260dbec4f..7918ebd02 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java @@ -70,11 +70,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java index e97540a19..ff2c05863 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java @@ -23,7 +23,7 @@ private OdnoklassnikiExample() { @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret - final String clientId = "your api client id"; + final String clientId = "your api client id"; final String publicKey = "your api public key"; final String secretKey = "your api secret key"; @@ -64,11 +64,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, publicKey)); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java index e6d8922fa..73ad113d5 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java @@ -55,11 +55,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index d9b6622f6..c9b06f540 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -53,10 +53,11 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java index 1131b87fb..701be48b4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java @@ -86,11 +86,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Sig string: " + sig); request.addQuerystringParameter("sig", md5(sig)); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java index 43d3d91b0..6e8ce342a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java @@ -39,7 +39,6 @@ public static void main(String... args) throws IOException, NoSuchAlgorithmExcep // // When you plan to connect to a Sandbox environment you've to use SalesforceApi.sandbox() API instance // new ServiceBuilder.....build(SalesforceApi.sandbox()); - final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .callback("https://www.example.com/callback") @@ -96,9 +95,10 @@ public static void main(String... args) throws IOException, NoSuchAlgorithmExcep final OAuthRequest request = new OAuthRequest(Verb.GET, url); service.signRequest(salesforceAccessToken, request); - final Response response = service.execute(request); System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java index 10505a804..6c3987046 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java @@ -91,10 +91,11 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println(); System.out.println("Full URL: " + url); final OAuthRequest request = new OAuthRequest(Verb.GET, url); - final Response response = service.execute(request); System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } } } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java index a6565e7d6..3ac982efb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java @@ -55,11 +55,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index 6a95f9472..d787aa45e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -61,11 +61,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index dab1f94f8..84bc61381 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -53,11 +53,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java index a35cda537..5b4d52bcb 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java @@ -74,11 +74,12 @@ public static void main(String... args) throws IOException, InterruptedException final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL + "?site=" + site + "&key=" + key); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java index d1b8dcd09..63139e589 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java @@ -50,7 +50,7 @@ public static void main(String... args) throws IOException, InterruptedException // TTN v1staging does not have URL safe keys, so we have to decode it final String code = URLDecoder.decode(in.nextLine(), "UTF-8"); - System.out.println("Using code: "+code); + System.out.println("Using code: " + code); System.out.println(); System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); @@ -78,19 +78,20 @@ public static void main(String... args) throws IOException, InterruptedException service.signRequest(accessToken, request); request.addHeader("Accept", "application/json"); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); - if (response.getCode() == 401) { - System.out.println("Not authorised: "+response.getBody()); - } else { - System.out.println("You should see a JSON array of your registered applications:"); - System.out.println(response.getBody()); + if (response.getCode() == 401) { + System.out.println("Not authorised: " + response.getBody()); + } else { + System.out.println("You should see a JSON array of your registered applications:"); + System.out.println(response.getBody()); - System.out.println(); - System.out.println("That's it man! Go and build something awesome with ScribeJava! :)"); + System.out.println(); + System.out.println("That's it man! Go and build something awesome with ScribeJava! :)"); + } } } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java index 3c35b8be8..25316d6ea 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java @@ -16,8 +16,8 @@ public class TheThingsNetworkV2PreviewExample { private static final String NETWORK_NAME = "TTNv2preview"; - private static final String PROTECTED_RESOURCE_URL = - "https://preview.account.thethingsnetwork.org/api/v2/applications"; + private static final String PROTECTED_RESOURCE_URL + = "https://preview.account.thethingsnetwork.org/api/v2/applications"; private TheThingsNetworkV2PreviewExample() { } @@ -75,19 +75,20 @@ public static void main(String... args) throws IOException, InterruptedException service.signRequest(accessToken, request); request.addHeader("Accept", "application/json"); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); - if (response.getCode() == 401) { - System.out.println("Not authorised: "+response.getBody()); - } else { - System.out.println("You should see a JSON array of your registered applications:"); - System.out.println(response.getBody()); + if (response.getCode() == 401) { + System.out.println("Not authorised: " + response.getBody()); + } else { + System.out.println("You should see a JSON array of your registered applications:"); + System.out.println(response.getBody()); - System.out.println(); - System.out.println("That's it man! Go and build something awesome with ScribeJava! :)"); + System.out.println(); + System.out.println("That's it man! Go and build something awesome with ScribeJava! :)"); + } } } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index 0909e9115..65f64592e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -55,11 +55,11 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index 5ca71b373..3cd648aee 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -55,11 +55,11 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with Scribe! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java index 475c7df58..c6aaf7eab 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TutByExample.java @@ -55,12 +55,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index 04d23911c..13a86535b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -53,11 +53,11 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("That's it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java index 899e2ed57..ae3270020 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java @@ -48,12 +48,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java index 0efdcd448..39dbcff78 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java @@ -54,12 +54,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java index 26f7cde06..baa4dae91 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java @@ -66,12 +66,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java index 3171c8d8c..7f9e0c969 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java @@ -74,12 +74,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java index 5e9e9b52d..5d3ffd562 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java @@ -61,12 +61,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index c66ebb984..6850fadab 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -53,11 +53,11 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java index 1a5186286..49b655462 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java @@ -66,12 +66,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index 455624cfd..ccaedba11 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -54,12 +54,12 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - final Response response = service.execute(request); - System.out.println("Got it! Lets see what we found..."); - System.out.println(); - System.out.println(response.getCode()); - System.out.println(response.getBody()); - + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java index 3fa402247..cb9620e68 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java @@ -18,8 +18,8 @@ public void shouldThrowExceptionIfResponseIsError() throws IOException { + "\"type\":\"OAuthException\"," + "\"code\":100," + "\"fbtrace_id\":\"DtxvtGRaxbB\"}}"; - try { - extractor.extract(error(body)); + try (Response response = error(body)) { + extractor.extract(response); fail(); } catch (FacebookAccessTokenErrorResponse fateR) { assertEquals("This authorization code has been used.", fateR.getMessage()); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java index a1781cacb..613158fc2 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java @@ -4,14 +4,16 @@ import java.io.InputStream; import java.util.Map; import com.github.scribejava.core.utils.StreamUtils; +import java.io.Closeable; /** * An HTTP response. * - *

    This response may contain a non-null body stream of the HttpUrlConnection. If so, this body must be closed to - * avoid leaking resources. Use either {@code getBody()} or {@code getStream().close()} to close the body. + *

    + * This response may contain a non-null body stream of the HttpUrlConnection. If so, this body must be closed to avoid + * leaking resources. Use either {@link #getBody()} or {@link #close()} to close the body. */ -public class Response { +public class Response implements Closeable { private final int code; private final String message; @@ -109,11 +111,18 @@ public String getHeader(String name) { @Override public String toString() { - return "Response{" + - "code=" + code + - ", message='" + message + '\'' + - ", body='" + body + '\'' + - ", headers=" + headers + - '}'; + return "Response{" + + "code=" + code + + ", message='" + message + '\'' + + ", body='" + body + '\'' + + ", headers=" + headers + + '}'; + } + + @Override + public void close() throws IOException { + if (stream != null) { + stream.close(); + } } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index 230a9dbd4..08295d8c0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -39,13 +39,14 @@ public OAuth1RequestToken getRequestToken() throws IOException, InterruptedExcep final OAuthRequest request = prepareRequestTokenRequest(); log("sending request..."); - final Response response = execute(request); - if (isDebug()) { - final String body = response.getBody(); - log("response status code: %s", response.getCode()); - log("response body: %s", body); + try (Response response = execute(request)) { + if (isDebug()) { + final String body = response.getBody(); + log("response status code: %s", response.getCode()); + log("response body: %s", body); + } + return api.getRequestTokenExtractor().extract(response); } - return api.getRequestTokenExtractor().extract(response); } public Future getRequestTokenAsync() { @@ -102,8 +103,9 @@ public OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, String log("obtaining access token from %s", api.getAccessTokenEndpoint()); } final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier); - final Response response = execute(request); - return api.getAccessTokenExtractor().extract(response); + try (Response response = execute(request)) { + return api.getAccessTokenExtractor().extract(response); + } } public Future getAccessTokenAsync(OAuth1RequestToken requestToken, String oauthVerifier) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 45b95d0a8..43a5d1a9f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -43,14 +43,15 @@ protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) if (isDebug()) { log("send request for access token synchronously to %s", request.getCompleteUrl()); } - final Response response = execute(request); - if (isDebug()) { - log("response status code: %s", response.getCode()); - final String body = response.getBody(); - log("response body: %s", body); - } + try (Response response = execute(request)) { + if (isDebug()) { + log("response status code: %s", response.getCode()); + final String body = response.getBody(); + log("response body: %s", body); + } - return api.getAccessTokenExtractor().extract(response); + return api.getAccessTokenExtractor().extract(response); + } } //protected to facilitate mocking @@ -427,7 +428,9 @@ public void revokeToken(String tokenToRevoke, TokenTypeHint tokenTypeHint) throws IOException, InterruptedException, ExecutionException { final OAuthRequest request = createRevokeTokenRequest(tokenToRevoke, tokenTypeHint); - checkForErrorRevokeToken(execute(request)); + try (Response response = execute(request)) { + checkForErrorRevokeToken(response); + } } public Future revokeToken(String tokenToRevoke, OAuthAsyncRequestCallback callback) { diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java index dd94008f6..8fe6bb20e 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java @@ -66,9 +66,10 @@ public void shouldSendGetRequest() throws Exception { final HttpUrl baseUrl = server.url("/testUrl"); final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString()); - final Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); - assertEquals(expectedResponseBody, response.getBody()); + try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { + assertEquals(expectedResponseBody, response.getBody()); + } final RecordedRequest recordedRequest = server.takeRequest(); assertEquals("GET", recordedRequest.getMethod()); @@ -91,9 +92,9 @@ public void shouldSendPostRequest() throws Exception { // request with body OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); request.setPayload(expectedRequestBody); - Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); - - assertEquals(expectedResponseBody, response.getBody()); + try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { + assertEquals(expectedResponseBody, response.getBody()); + } RecordedRequest recordedRequest = server.takeRequest(); assertEquals("POST", recordedRequest.getMethod()); @@ -101,9 +102,9 @@ public void shouldSendPostRequest() throws Exception { // request with empty body request = new OAuthRequest(Verb.POST, baseUrl.toString()); - response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); - - assertEquals(expectedResponseBody, response.getBody()); + try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { + assertEquals(expectedResponseBody, response.getBody()); + } recordedRequest = server.takeRequest(); assertEquals("POST", recordedRequest.getMethod()); @@ -123,9 +124,9 @@ public void shouldReadResponseStream() throws Exception { final HttpUrl baseUrl = server.url("/testUrl"); final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString()); - final Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS); - - assertEquals(expectedResponseBody, StreamUtils.getStreamContents(response.getStream())); + try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { + assertEquals(expectedResponseBody, StreamUtils.getStreamContents(response.getStream())); + } final RecordedRequest recordedRequest = server.takeRequest(); assertEquals("GET", recordedRequest.getMethod()); @@ -165,10 +166,11 @@ public void shouldPassErrors() throws Exception { final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString()); final TestCallback callback = new TestCallback(); - final Response response = oAuthService.execute(request, callback).get(); + try (Response response = oAuthService.execute(request, callback).get()) { - assertEquals(500, response.getCode()); - assertEquals(500, callback.getResponse().getCode()); + assertEquals(500, response.getCode()); + assertEquals(500, callback.getResponse().getCode()); + } server.shutdown(); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth1AccessTokenExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth1AccessTokenExtractorTest.java index 36ac4cd2e..58ed0e93d 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth1AccessTokenExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth1AccessTokenExtractorTest.java @@ -22,58 +22,78 @@ public void setUp() { @Test public void shouldExtractTokenFromOAuthStandardResponse() throws IOException { - final String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03"; - final OAuth1Token extracted = extractor.extract(ok(response)); + final String responseBody = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03"; + final OAuth1Token extracted; + try (Response response = ok(responseBody)) { + extracted = extractor.extract(response); + } assertEquals("hh5s93j4hdidpola", extracted.getToken()); assertEquals("hdhd0244k9j7ao03", extracted.getTokenSecret()); } @Test public void shouldExtractTokenFromInvertedOAuthStandardResponse() throws IOException { - final String response = "oauth_token_secret=hh5s93j4hdidpola&oauth_token=hdhd0244k9j7ao03"; - final OAuth1Token extracted = extractor.extract(ok(response)); + final String responseBody = "oauth_token_secret=hh5s93j4hdidpola&oauth_token=hdhd0244k9j7ao03"; + final OAuth1Token extracted; + try (Response response = ok(responseBody)) { + extracted = extractor.extract(response); + } assertEquals("hh5s93j4hdidpola", extracted.getTokenSecret()); assertEquals("hdhd0244k9j7ao03", extracted.getToken()); } @Test public void shouldExtractTokenFromResponseWithCallbackConfirmed() throws IOException { - final String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03" + final String responseBody = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03" + "&callback_confirmed=true"; - final OAuth1Token extracted = extractor.extract(ok(response)); + final OAuth1Token extracted; + try (Response response = ok(responseBody)) { + extracted = extractor.extract(response); + } assertEquals("hh5s93j4hdidpola", extracted.getToken()); assertEquals("hdhd0244k9j7ao03", extracted.getTokenSecret()); } @Test public void shouldExtractTokenWithEmptySecret() throws IOException { - final String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret="; - final OAuth1Token extracted = extractor.extract(ok(response)); + final String responseBody = "oauth_token=hh5s93j4hdidpola&oauth_token_secret="; + final OAuth1Token extracted; + try (Response response = ok(responseBody)) { + extracted = extractor.extract(response); + } assertEquals("hh5s93j4hdidpola", extracted.getToken()); assertEquals("", extracted.getTokenSecret()); } @Test(expected = OAuthException.class) public void shouldThrowExceptionIfTokenIsAbsent() throws IOException { - final String response = "oauth_secret=hh5s93j4hdidpola&callback_confirmed=true"; - extractor.extract(ok(response)); + final String responseBody = "oauth_secret=hh5s93j4hdidpola&callback_confirmed=true"; + try (Response response = ok(responseBody)) { + extractor.extract(response); + } } @Test(expected = OAuthException.class) public void shouldThrowExceptionIfSecretIsAbsent() throws IOException { - final String response = "oauth_token=hh5s93j4hdidpola&callback_confirmed=true"; - extractor.extract(ok(response)); + final String responseBody = "oauth_token=hh5s93j4hdidpola&callback_confirmed=true"; + try (Response response = ok(responseBody)) { + extractor.extract(response); + } } @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfResponseIsNull() throws IOException { - extractor.extract(ok(null)); + try (Response response = ok(null)) { + extractor.extract(response); + } } @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfResponseIsEmptyString() throws IOException { - final String response = ""; - extractor.extract(ok(response)); + final String responseBody = ""; + try (Response response = ok(responseBody)) { + extractor.extract(response); + } } private static Response ok(String body) { diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java index a79a87615..28d9a569b 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java @@ -22,18 +22,24 @@ public void setUp() { @Test public void shouldExtractTokenFromOAuthStandardResponse() throws IOException { - final String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159" + final String responseBody = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159" + "|RsXNdKrpxg8L6QNLWcs2TVTmcaE"; - final OAuth2AccessToken extracted = extractor.extract(ok(response)); + final OAuth2AccessToken extracted; + try (Response response = ok(responseBody)) { + extracted = extractor.extract(response); + } assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", extracted.getAccessToken()); } @Test public void shouldExtractTokenFromResponseWithExpiresParam() throws IOException { - final String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159" + final String responseBody = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159" + "|RsXNdKrpxg8L6QNLWcs2TVTmcaE&expires_in=5108"; - final OAuth2AccessToken extracted = extractor.extract(ok(response)); + final OAuth2AccessToken extracted; + try (Response response = ok(responseBody)) { + extracted = extractor.extract(response); + } assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", extracted.getAccessToken()); assertEquals(Integer.valueOf(5108), extracted.getExpiresIn()); @@ -41,9 +47,12 @@ public void shouldExtractTokenFromResponseWithExpiresParam() throws IOException @Test public void shouldExtractTokenFromResponseWithExpiresAndRefreshParam() throws IOException { - final String response = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159" + final String responseBody = "access_token=166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159" + "|RsXNdKrpxg8L6QNLWcs2TVTmcaE&expires_in=5108&token_type=bearer&refresh_token=166942940015970"; - final OAuth2AccessToken extracted = extractor.extract(ok(response)); + final OAuth2AccessToken extracted; + try (Response response = ok(responseBody)) { + extracted = extractor.extract(response); + } assertEquals("166942940015970|2.2ltzWXYNDjCtg5ZDVVJJeg__.3600.1295816400-548517159|RsXNdKrpxg8L6QNLWcs2TVTmcaE", extracted.getAccessToken()); assertEquals(Integer.valueOf(5108), extracted.getExpiresIn()); @@ -53,32 +62,43 @@ public void shouldExtractTokenFromResponseWithExpiresAndRefreshParam() throws IO @Test public void shouldExtractTokenFromResponseWithManyParameters() throws IOException { - final String response = "access_token=foo1234&other_stuff=yeah_we_have_this_too&number=42"; - final OAuth2AccessToken extracted = extractor.extract(ok(response)); + final String responseBody = "access_token=foo1234&other_stuff=yeah_we_have_this_too&number=42"; + final OAuth2AccessToken extracted; + try (Response response = ok(responseBody)) { + extracted = extractor.extract(response); + } assertEquals("foo1234", extracted.getAccessToken()); } @Test(expected = OAuthException.class) public void shouldThrowExceptionIfErrorResponse() throws IOException { - final String response = ""; - extractor.extract(error(response)); + final String responseBody = ""; + try (Response response = error(responseBody)) { + extractor.extract(response); + } } @Test(expected = OAuthException.class) public void shouldThrowExceptionIfTokenIsAbsent() throws IOException { - final String response = "&expires=5108"; - extractor.extract(ok(response)); + final String responseBody = "&expires=5108"; + try (Response response = ok(responseBody)) { + extractor.extract(response); + } } @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfResponseIsNull() throws IOException { - extractor.extract(ok(null)); + try (Response response = ok(null)) { + extractor.extract(response); + } } @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfResponseIsEmptyString() throws IOException { - final String response = ""; - extractor.extract(ok(response)); + final String responseBody = ""; + try (Response response = ok(responseBody)) { + extractor.extract(response); + } } private static Response ok(String body) { diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java index dcc81929c..c39b265a8 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java @@ -18,56 +18,73 @@ public class OAuth2AccessTokenJsonExtractorTest { @Test public void shouldParseResponse() throws IOException { - final OAuth2AccessToken token = extractor.extract( - ok("{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X\", " - + "\"token_type\":\"example\"}")); + final String responseBody = "{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X\", " + + "\"token_type\":\"example\"}"; + final OAuth2AccessToken token; + try (Response response = ok(responseBody)) { + token = extractor.extract(response); + } assertEquals("I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X", token.getAccessToken()); } @Test public void shouldParseScopeFromResponse() throws IOException { - OAuth2AccessToken token = extractor.extract( - ok("{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T4X\", " - + "\"token_type\":\"example\"," - + "\"scope\":\"s1\"}")); + final String responseBody = "{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T4X\", " + + "\"token_type\":\"example\"," + + "\"scope\":\"s1\"}"; + final OAuth2AccessToken token; + try (Response response = ok(responseBody)) { + token = extractor.extract(response); + } assertEquals("I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T4X", token.getAccessToken()); assertEquals("s1", token.getScope()); - token = extractor.extract( - ok("{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T5X\", " - + "\"token_type\":\"example\"," - + "\"scope\":\"s1 s2\"}")); - assertEquals("I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T5X", token.getAccessToken()); - assertEquals("s1 s2", token.getScope()); + final String responseBody2 = "{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T5X\", " + + "\"token_type\":\"example\"," + + "\"scope\":\"s1 s2\"}"; + final OAuth2AccessToken token2; + try (Response response = ok(responseBody2)) { + token2 = extractor.extract(response); + } + assertEquals("I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T5X", token2.getAccessToken()); + assertEquals("s1 s2", token2.getScope()); - token = extractor.extract( - ok("{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T6X\", " - + "\"token_type\":\"example\"," - + "\"scope\":\"s3 s4\", " - + "\"refresh_token\":\"refresh_token1\"}")); - assertEquals("I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T6X", token.getAccessToken()); - assertEquals("s3 s4", token.getScope()); - assertEquals("refresh_token1", token.getRefreshToken()); + final String responseBody3 = "{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T6X\", " + + "\"token_type\":\"example\"," + + "\"scope\":\"s3 s4\", " + + "\"refresh_token\":\"refresh_token1\"}"; + final OAuth2AccessToken token3; + try (Response response = ok(responseBody3)) { + token3 = extractor.extract(response); + } + assertEquals("I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T6X", token3.getAccessToken()); + assertEquals("s3 s4", token3.getScope()); + assertEquals("refresh_token1", token3.getRefreshToken()); } @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfForNullParameters() throws IOException { - extractor.extract(ok(null)); + try (Response response = ok(null)) { + extractor.extract(response); + } } @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfForEmptyStrings() throws IOException { - extractor.extract(ok("")); + final String responseBody = ""; + try (Response response = ok(responseBody)) { + extractor.extract(response); + } } @Test public void shouldThrowExceptionIfResponseIsError() throws IOException { - final String body = "{" + - "\"error_description\":\"unknown, invalid, or expired refresh token\"," + - "\"error\":\"invalid_grant\"" + - "}"; - try { - extractor.extract(error(body)); + final String responseBody = "{" + + "\"error_description\":\"unknown, invalid, or expired refresh token\"," + + "\"error\":\"invalid_grant\"" + + "}"; + try (Response response = error(responseBody)) { + extractor.extract(response); fail(); } catch (OAuth2AccessTokenErrorResponse oaer) { assertEquals(OAuth2Error.INVALID_GRANT, oaer.getError()); @@ -77,8 +94,12 @@ public void shouldThrowExceptionIfResponseIsError() throws IOException { @Test public void testEscapedJsonInResponse() throws IOException { - final OAuth2AccessToken token = extractor.extract(ok("{ \"access_token\":\"I0122HKLEM2\\/MV3ABKFTDT3T5X\"," - + "\"token_type\":\"example\"}")); + final String responseBody = "{ \"access_token\":\"I0122HKLEM2\\/MV3ABKFTDT3T5X\"," + + "\"token_type\":\"example\"}"; + final OAuth2AccessToken token; + try (Response response = ok(responseBody)) { + token = extractor.extract(response); + } assertEquals("I0122HKLEM2/MV3ABKFTDT3T5X", token.getAccessToken()); } From f0da25669ed6a1556f1b7d5f40799de86299f188 Mon Sep 17 00:00:00 2001 From: Miles Yucht Date: Mon, 19 Aug 2019 17:14:21 +0200 Subject: [PATCH 348/481] Build OAuth10a service from ServiceBuilderOAuth10a --- .../core/builder/ServiceBuilderOAuth10a.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java index 14323b809..233790386 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java @@ -9,22 +9,22 @@ public interface ServiceBuilderOAuth10a extends ServiceBuilderCommon { @Override - ServiceBuilderOAuth20 callback(String callback); + ServiceBuilderOAuth10a callback(String callback); @Override - ServiceBuilderOAuth20 apiKey(String apiKey); + ServiceBuilderOAuth10a apiKey(String apiKey); @Override - ServiceBuilderOAuth20 apiSecret(String apiSecret); + ServiceBuilderOAuth10a apiSecret(String apiSecret); @Override - ServiceBuilderOAuth20 httpClientConfig(HttpClientConfig httpClientConfig); + ServiceBuilderOAuth10a httpClientConfig(HttpClientConfig httpClientConfig); @Override - ServiceBuilderOAuth20 httpClient(HttpClient httpClient); + ServiceBuilderOAuth10a httpClient(HttpClient httpClient); @Override - ServiceBuilderOAuth20 userAgent(String userAgent); + ServiceBuilderOAuth10a userAgent(String userAgent); ServiceBuilderOAuth10a debugStream(OutputStream debugStream); From c9dfa62d82099291fe8247db3a7fb50d4f33a083 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 20 Aug 2019 15:48:50 +0300 Subject: [PATCH 349/481] fix Type resolution for builder pattern in ServiceBuilderOAuth10a (thanks to https://github.com/mgyucht) --- changelog | 1 + .../scribejava/core/builder/ServiceBuilderCommon.java | 5 +++++ .../scribejava/core/builder/ServiceBuilderOAuth10a.java | 2 ++ .../scribejava/core/builder/ServiceBuilderOAuth20.java | 7 +++++++ 4 files changed, 15 insertions(+) diff --git a/changelog b/changelog index 77161cd52..55f45077c 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * make Response implements Closeable (thanks to https://github.com/omaric) + * fix Type resolution for builder pattern in ServiceBuilderOAuth10a (thanks to https://github.com/mgyucht) [6.8.0] * Add debug output to OAuth2Service (thanks to https://github.com/rbarbey) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderCommon.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderCommon.java index 9cddb2947..ba36cdef0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderCommon.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderCommon.java @@ -3,6 +3,7 @@ import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.oauth.OAuthService; +import java.io.OutputStream; /** * Implementation of the Builder pattern, with a fluent interface that creates a {@link OAuthService} @@ -45,4 +46,8 @@ public interface ServiceBuilderCommon { ServiceBuilderCommon httpClient(HttpClient httpClient); ServiceBuilderCommon userAgent(String userAgent); + + ServiceBuilderCommon debugStream(OutputStream debugStream); + + ServiceBuilderCommon debug(); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java index 233790386..d51f81f4b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java @@ -26,8 +26,10 @@ public interface ServiceBuilderOAuth10a extends ServiceBuilderCommon { @Override ServiceBuilderOAuth10a userAgent(String userAgent); + @Override ServiceBuilderOAuth10a debugStream(OutputStream debugStream); + @Override ServiceBuilderOAuth10a debug(); /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java index 97347959b..47a9cf3f6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java @@ -4,6 +4,7 @@ import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.OutputStream; public interface ServiceBuilderOAuth20 extends ServiceBuilderCommon { @@ -25,6 +26,12 @@ public interface ServiceBuilderOAuth20 extends ServiceBuilderCommon { @Override ServiceBuilderOAuth20 userAgent(String userAgent); + @Override + ServiceBuilderOAuth20 debugStream(OutputStream debugStream); + + @Override + ServiceBuilderOAuth20 debug(); + ServiceBuilderOAuth20 responseType(String responseType); /** From 8caa3ae90dc4d28e07021f446751fed15cf07c62 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 22 Aug 2019 13:49:08 +0300 Subject: [PATCH 350/481] fix no Content-length errors (thanks to https://github.com/mikita-herasiutsin and https://github.com/iankurverma) --- changelog | 1 + .../scribejava/core/httpclient/jdk/JDKHttpClient.java | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/changelog b/changelog index 55f45077c..fb35b1be0 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * make Response implements Closeable (thanks to https://github.com/omaric) * fix Type resolution for builder pattern in ServiceBuilderOAuth10a (thanks to https://github.com/mgyucht) + * fix no Content-length errors (thanks to https://github.com/mikita-herasiutsin and https://github.com/iankurverma) [6.8.0] * Add debug output to OAuth2Service (thanks to https://github.com/rbarbey) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 9a9dbef4b..3f4648a77 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -265,11 +265,7 @@ private static OutputStream prepareConnectionForBodyAndGetOutputStream(HttpURLCo if (connection.getRequestProperty(CONTENT_TYPE) == null) { connection.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } - if (contentLength > 0) { - connection.setDoOutput(true); - return connection.getOutputStream(); - } else { - return null; - } + connection.setDoOutput(true); + return connection.getOutputStream(); } } From 99e95bc43cff40795d14128ef310d9e3cd8a0fcc Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 22 Aug 2019 14:04:08 +0300 Subject: [PATCH 351/481] update okhttp 4.0.1 to 4.1.0 --- pom.xml | 2 +- .../main/java/com/github/scribejava/core/model/Response.java | 3 +++ scribejava-httpclient-okhttp/pom.xml | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d70a2626c..4f1c1ea79 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,7 @@ com.squareup.okhttp3 mockwebserver - 4.0.1 + 4.1.0 test diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java index 613158fc2..7cff61694 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java @@ -55,6 +55,9 @@ public boolean isSuccessful() { /** * Returns the response body as a string, closing the stream that backs it. Idempotent. + * + * @return body as string + * @throws IOException IO Exception */ public String getBody() throws IOException { return body == null ? parseBodyContents() : body; diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 3006a5d67..e47d86846 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 4.0.1 + 4.1.0 com.github.scribejava From 515821e7fa9859d61cf0529fe326dfd4a2307675 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 22 Aug 2019 14:16:59 +0300 Subject: [PATCH 352/481] prepare v6.8.1 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 16cf3d3ce..e675b741d 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.8.0 + 6.8.1 ``` @@ -139,7 +139,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.8.0 + 6.8.1 ``` diff --git a/changelog b/changelog index fb35b1be0..c1bb50e52 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.8.1] * make Response implements Closeable (thanks to https://github.com/omaric) * fix Type resolution for builder pattern in ServiceBuilderOAuth10a (thanks to https://github.com/mgyucht) * fix no Content-length errors (thanks to https://github.com/mikita-herasiutsin and https://github.com/iankurverma) From a11d2b6b299bf21850137d2adaa388c65029285b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 22 Aug 2019 14:18:25 +0300 Subject: [PATCH 353/481] [maven-release-plugin] prepare release scribejava-6.8.1 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 4f1c1ea79..c897ea534 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.8.1-SNAPSHOT + 6.8.1 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.8.1 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index c95ef2b51..52b38a2c3 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.1-SNAPSHOT + 6.8.1 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 995ea03b5..337c271f2 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.1-SNAPSHOT + 6.8.1 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 97657ec57..b3f47ff80 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.1-SNAPSHOT + 6.8.1 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 14fcba8b5..e75ff8ce4 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.1-SNAPSHOT + 6.8.1 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 1f6453d20..79d3983f2 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.1-SNAPSHOT + 6.8.1 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index e47d86846..31f6e6559 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.1-SNAPSHOT + 6.8.1 ../pom.xml From 1700e3315ee8fd2e7cdde5166d6e134abe7a5850 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 22 Aug 2019 14:18:32 +0300 Subject: [PATCH 354/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index c897ea534..109d238b7 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.8.1 + 6.8.2-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.8.1 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 52b38a2c3..69eb60aa8 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.1 + 6.8.2-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 337c271f2..1abb65221 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.1 + 6.8.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index b3f47ff80..36fe35a07 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.1 + 6.8.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index e75ff8ce4..8a327ffc5 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.1 + 6.8.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 79d3983f2..f2ed3cf2d 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.1 + 6.8.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 31f6e6559..a02806a75 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.1 + 6.8.2-SNAPSHOT ../pom.xml From bc85f4a8fdb4a0361c1f3465d1ddc03f12e00cf7 Mon Sep 17 00:00:00 2001 From: Richard Rowley Date: Wed, 9 Jan 2013 18:37:01 +1300 Subject: [PATCH 355/481] Add XeroApi20 derivation --- .../org/scribe/builder/api/XeroApi20.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/org/scribe/builder/api/XeroApi20.java diff --git a/src/main/java/org/scribe/builder/api/XeroApi20.java b/src/main/java/org/scribe/builder/api/XeroApi20.java new file mode 100644 index 000000000..d11abc4b6 --- /dev/null +++ b/src/main/java/org/scribe/builder/api/XeroApi20.java @@ -0,0 +1,23 @@ +package org.scribe.builder.api; + +import org.scribe.model.*; + +public class XeroApi20 extends DefaultApi10a{ + + private static final String BASE_URL = "https://api.xero.com/oauth/"; + + @Override + public String getAccessTokenEndpoint() { + return BASE_URL + "AccessToken"; + } + + @Override + public String getRequestTokenEndpoint() { + return BASE_URL + "RequestToken"; + } + + @Override + public String getAuthorizationUrl(Token token) { + return BASE_URL + "Authorize?oauth_token=" + token.getToken(); + } +} From 35cdf78b3474b88c1c4c44f34b7e4d1f004455ae Mon Sep 17 00:00:00 2001 From: SidneyAllen Date: Mon, 12 Aug 2019 10:28:17 -0700 Subject: [PATCH 356/481] Xero API for oAuth2 and example code --- .../com/github/scribejava/apis/XeroApi20.java | 37 +++++ .../scribejava/apis/examples/XeroExample.java | 130 ++++++++++++++++++ .../org/scribe/builder/api/XeroApi20.java | 23 ---- 3 files changed, 167 insertions(+), 23 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/XeroApi20.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XeroExample.java delete mode 100644 src/main/java/org/scribe/builder/api/XeroApi20.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/XeroApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/XeroApi20.java new file mode 100644 index 000000000..e20b99daf --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/XeroApi20.java @@ -0,0 +1,37 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; + +/** + * Xero.com Api + */ +public class XeroApi20 extends DefaultApi20 { + + protected XeroApi20() { + } + + private static class InstanceHolder { + private static final XeroApi20 INSTANCE = new XeroApi20(); + } + + public static XeroApi20 instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://identity.xero.com/connect/token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://login.xero.com/identity/connect/authorize"; + } + + @Override + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XeroExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XeroExample.java new file mode 100644 index 000000000..6cae34c5d --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XeroExample.java @@ -0,0 +1,130 @@ +package com.github.scribejava.apis.examples; + +import java.util.Random; +import java.util.Scanner; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +/* + * This full example needs a library to parse + * the JSON response and obtain a Xero Tenant Id + * in order to access protected resources. + * + * If you add the following dependency, you can then + * uncomment the rest of the example code to access + * the Xero Organisation and other protected resources + * + * + com.googlecode.json-simple + json-simple + 1.1.1 + + * + */ + +/* +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; +*/ + +public class XeroExample { + + private static final String NETWORK_NAME = "Xero"; + private static final String PROTECTED_RESOURCE_URL = "https://api.xero.com/connections"; + private static final String PROTECTED_ORGANISATION_URL = "https://api.xero.com/api.xro/2.0/Organisation"; + + private XeroExample() { + } + + @SuppressWarnings("PMD.SystemPrintln") + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id, secret and redirect uri + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String callback = "your redirect uri"; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .defaultScope("openid email profile offline_access accounting.settings accounting.transactions") // replace with desired scope + .callback(callback) + .build(Xero20Api.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(secretState); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + System.out.println("Trading the Authorization Code for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + // GET the Xero Tenant ID + System.out.println("Getting Xero tenant id..."); + final OAuthRequest requestConn = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + requestConn.addHeader("Accept", "application/json"); + service.signRequest(accessToken.getAccessToken(), requestConn); + final Response responseConn = service.execute(requestConn); + System.out.println(); + System.out.println(responseConn.getCode()); + System.out.println(responseConn.getBody()); + /* + JSONParser parser = new JSONParser(); + JSONArray jsonArray = null; + try { + jsonArray = (JSONArray) parser.parse(responseConn.getBody()); + } catch (ParseException e) { + e.printStackTrace(); + } + + JSONObject jsonObject = (JSONObject) jsonArray.get(0); + System.out.println("Your Xero tenant id is ...." + jsonObject.get("tenantId")); + + // GET protected Resource + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_ORGANISATION_URL); + request.addHeader("xero-tenant-id",jsonObject.get("tenantId").toString()); + service.signRequest(accessToken.getAccessToken(), request); + final Response response = service.execute(request); + + // Now let's go and ask for a protected resource! + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + */ + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} \ No newline at end of file diff --git a/src/main/java/org/scribe/builder/api/XeroApi20.java b/src/main/java/org/scribe/builder/api/XeroApi20.java deleted file mode 100644 index d11abc4b6..000000000 --- a/src/main/java/org/scribe/builder/api/XeroApi20.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.scribe.builder.api; - -import org.scribe.model.*; - -public class XeroApi20 extends DefaultApi10a{ - - private static final String BASE_URL = "https://api.xero.com/oauth/"; - - @Override - public String getAccessTokenEndpoint() { - return BASE_URL + "AccessToken"; - } - - @Override - public String getRequestTokenEndpoint() { - return BASE_URL + "RequestToken"; - } - - @Override - public String getAuthorizationUrl(Token token) { - return BASE_URL + "Authorize?oauth_token=" + token.getToken(); - } -} From cc8841299f6437124156648aa804c0e1070768af Mon Sep 17 00:00:00 2001 From: SidneyAllen Date: Mon, 19 Aug 2019 09:31:12 -0700 Subject: [PATCH 357/481] Updated example to use Jackson to parse JSON --- .../scribejava/apis/examples/XeroExample.java | 65 +++++++------------ 1 file changed, 22 insertions(+), 43 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XeroExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XeroExample.java index 6cae34c5d..b8cfc1977 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XeroExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XeroExample.java @@ -1,7 +1,12 @@ package com.github.scribejava.apis.examples; +import java.util.List; +import java.util.Map; import java.util.Random; import java.util.Scanner; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.TypeFactory; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; @@ -11,30 +16,6 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -/* - * This full example needs a library to parse - * the JSON response and obtain a Xero Tenant Id - * in order to access protected resources. - * - * If you add the following dependency, you can then - * uncomment the rest of the example code to access - * the Xero Organisation and other protected resources - * - * - com.googlecode.json-simple - json-simple - 1.1.1 - - * - */ - -/* -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; -import org.json.simple.parser.ParseException; -*/ - public class XeroExample { private static final String NETWORK_NAME = "Xero"; @@ -46,10 +27,11 @@ private XeroExample() { @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - // Replace these with your client id, secret and redirect uri + // Replace these with your client id and secret final String clientId = "your client id"; final String clientSecret = "your client secret"; - final String callback = "your redirect uri"; + final String callback = "your callback url"; + final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) @@ -90,31 +72,28 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); - // GET the Xero Tenant ID + //First GET the Xero Tenant ID System.out.println("Getting Xero tenant id..."); final OAuthRequest requestConn = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); requestConn.addHeader("Accept", "application/json"); service.signRequest(accessToken.getAccessToken(), requestConn); - final Response responseConn = service.execute(requestConn); - System.out.println(); - System.out.println(responseConn.getCode()); - System.out.println(responseConn.getBody()); - /* - JSONParser parser = new JSONParser(); - JSONArray jsonArray = null; - try { - jsonArray = (JSONArray) parser.parse(responseConn.getBody()); - } catch (ParseException e) { - e.printStackTrace(); - } + final Response connResp = service.execute(requestConn); - JSONObject jsonObject = (JSONObject) jsonArray.get(0); - System.out.println("Your Xero tenant id is ...." + jsonObject.get("tenantId")); + ObjectMapper objectMapper = new ObjectMapper(); + TypeFactory typeFactory = objectMapper.getTypeFactory(); + @SuppressWarnings("rawtypes") + List tenantList = objectMapper.readValue(connResp.getBody(), typeFactory.constructCollectionType(List.class, Map.class)); + + System.out.println(); + System.out.println(connResp.getCode()); + System.out.println(connResp.getBody()); + System.out.println(); + System.out.println("Your Xero tenant id is ...." + tenantList.get(0).get("tenantId")); // GET protected Resource System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_ORGANISATION_URL); - request.addHeader("xero-tenant-id",jsonObject.get("tenantId").toString()); + request.addHeader("xero-tenant-id",tenantList.get(0).get("tenantId").toString()); service.signRequest(accessToken.getAccessToken(), request); final Response response = service.execute(request); @@ -123,7 +102,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); System.out.println(response.getCode()); System.out.println(response.getBody()); - */ + System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } From ee703cbc0d9afd68f545343787a3fbaea3dbe974 Mon Sep 17 00:00:00 2001 From: SidneyAllen Date: Mon, 19 Aug 2019 09:33:38 -0700 Subject: [PATCH 358/481] newline added --- .../java/com/github/scribejava/apis/examples/XeroExample.java | 1 + 1 file changed, 1 insertion(+) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XeroExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XeroExample.java index b8cfc1977..e0da463ed 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XeroExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XeroExample.java @@ -89,6 +89,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(connResp.getBody()); System.out.println(); System.out.println("Your Xero tenant id is ...." + tenantList.get(0).get("tenantId")); + System.out.println(); // GET protected Resource System.out.println("Now we're going to access a protected resource..."); From 177a977fa6e85757b1a5b4c243c17f532d661965 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 22 Aug 2019 13:42:20 +0300 Subject: [PATCH 359/481] Add Xero API (https://www.xero.com/) (thanks to https://github.com/SidneyAllen) --- README.md | 3 +- changelog | 3 ++ .../com/github/scribejava/apis/XeroApi20.java | 8 +---- .../scribejava/apis/examples/XeroExample.java | 30 +++++++++---------- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index e675b741d..adabdd45a 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ ScribeJava support out-of-box several HTTP clients: * [RFC 7009](https://tools.ietf.org/html/rfc7009) OAuth 2.0 Token Revocation, [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java) * [RFC 5849](https://tools.ietf.org/html/rfc5849) The OAuth 1.0 Protocol, [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java) -### Supports all major 1.0a and 2.0 OAuth APIs out-of-the-box +### Supports all (50+) major 1.0a and 2.0 OAuth APIs out-of-the-box * Asana (https://asana.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java) * Automatic (https://www.automatic.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java) @@ -103,6 +103,7 @@ ScribeJava support out-of-box several HTTP clients: * Viadeo (http://viadeo.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ViadeoExample.java) * VK ВКонтакте (http://vk.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java), [example Client Credentials Grant](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java), [example with External HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java) * Wunderlist (https://www.wunderlist.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/WunderlistExample.java) +* Xero (https://www.xero.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XeroExample.java) * XING (https://www.xing.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java) * Yahoo (https://www.yahoo.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java) * check the [examples folder](https://github.com/scribejava/scribejava/tree/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples) diff --git a/changelog b/changelog index c1bb50e52..9d727dde3 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * Add Xero API (https://www.xero.com/) (thanks to https://github.com/SidneyAllen) + [6.8.1] * make Response implements Closeable (thanks to https://github.com/omaric) * fix Type resolution for builder pattern in ServiceBuilderOAuth10a (thanks to https://github.com/mgyucht) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/XeroApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/XeroApi20.java index e20b99daf..2141ed007 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/XeroApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/XeroApi20.java @@ -1,8 +1,6 @@ package com.github.scribejava.apis; import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; -import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; /** * Xero.com Api @@ -13,6 +11,7 @@ protected XeroApi20() { } private static class InstanceHolder { + private static final XeroApi20 INSTANCE = new XeroApi20(); } @@ -29,9 +28,4 @@ public String getAccessTokenEndpoint() { protected String getAuthorizationBaseUrl() { return "https://login.xero.com/identity/connect/authorize"; } - - @Override - public ClientAuthentication getClientAuthentication() { - return RequestBodyAuthenticationScheme.instance(); - } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XeroExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XeroExample.java index e0da463ed..d66334e40 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XeroExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XeroExample.java @@ -6,7 +6,7 @@ import java.util.Scanner; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.type.TypeFactory; +import com.github.scribejava.apis.XeroApi20; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; @@ -31,13 +31,14 @@ public static void main(String... args) throws IOException, InterruptedException final String clientId = "your client id"; final String clientSecret = "your client secret"; final String callback = "your callback url"; - + final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .defaultScope("openid email profile offline_access accounting.settings accounting.transactions") // replace with desired scope + // replace with desired scope + .defaultScope("openid email profile offline_access accounting.settings accounting.transactions") .callback(callback) - .build(Xero20Api.instance()); + .build(XeroApi20.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); @@ -71,33 +72,32 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Got the Access Token!"); System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); System.out.println(); - + //First GET the Xero Tenant ID System.out.println("Getting Xero tenant id..."); final OAuthRequest requestConn = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); requestConn.addHeader("Accept", "application/json"); service.signRequest(accessToken.getAccessToken(), requestConn); final Response connResp = service.execute(requestConn); - - ObjectMapper objectMapper = new ObjectMapper(); - TypeFactory typeFactory = objectMapper.getTypeFactory(); - @SuppressWarnings("rawtypes") - List tenantList = objectMapper.readValue(connResp.getBody(), typeFactory.constructCollectionType(List.class, Map.class)); - + + final ObjectMapper objectMapper = new ObjectMapper(); + final List> tenantList = objectMapper.readValue(connResp.getBody(), + objectMapper.getTypeFactory().constructCollectionType(List.class, Map.class)); + System.out.println(); System.out.println(connResp.getCode()); System.out.println(connResp.getBody()); System.out.println(); System.out.println("Your Xero tenant id is ...." + tenantList.get(0).get("tenantId")); System.out.println(); - + // GET protected Resource System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_ORGANISATION_URL); - request.addHeader("xero-tenant-id",tenantList.get(0).get("tenantId").toString()); + request.addHeader("xero-tenant-id", tenantList.get(0).get("tenantId")); service.signRequest(accessToken.getAccessToken(), request); final Response response = service.execute(request); - + // Now let's go and ask for a protected resource! System.out.println("Got it! Lets see what we found..."); System.out.println(); @@ -107,4 +107,4 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } -} \ No newline at end of file +} From ed86d41401044b5d7d35f7a6c4447f29a444de15 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 4 Oct 2019 14:28:10 +0300 Subject: [PATCH 360/481] upgrade dependencies --- checkstyle.xml | 8 ++++---- pom.xml | 8 ++++---- .../github/scribejava/core/model/OAuth2AccessToken.java | 3 ++- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/checkstyle.xml b/checkstyle.xml index f3befc8a5..c9b0fac9b 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -93,10 +93,6 @@ - - - - @@ -107,6 +103,10 @@ + + + + diff --git a/pom.xml b/pom.xml index 109d238b7..2bd9bdd0e 100644 --- a/pom.xml +++ b/pom.xml @@ -56,7 +56,7 @@ com.fasterxml.jackson.core jackson-databind - 2.9.9.3 + 2.10.0 junit @@ -67,7 +67,7 @@ com.squareup.okhttp3 mockwebserver - 4.1.0 + 4.2.0 test @@ -77,7 +77,7 @@ org.apache.felix maven-bundle-plugin - 4.2.0 + 4.2.1 bundle-manifest @@ -106,7 +106,7 @@ com.puppycrawl.tools checkstyle - 8.23 + 8.25 diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java index 37b951f13..00d5b1636 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java @@ -8,7 +8,8 @@ *

    * http://tools.ietf.org/html/rfc6749#section-5.1 * - * @see OAuth 2 Access Token Specification

    + * @see OAuth 2 Access Token Specification + *

    */ public class OAuth2AccessToken extends Token { diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 36fe35a07..642286105 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.10.1 + 2.10.3 com.github.scribejava diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 8a327ffc5..efcced401 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -23,7 +23,7 @@ org.apache.httpcomponents httpclient - 4.5.9 + 4.5.10 org.apache.httpcomponents diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index a02806a75..c7935567c 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 4.1.0 + 4.2.0 com.github.scribejava From b33bd573196c6b0119e0fa539d7a70a0c4c21ada Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 4 Oct 2019 14:42:53 +0300 Subject: [PATCH 361/481] prepare v6.9.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index adabdd45a..1b1f0665c 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.8.1 + 6.9.0 ``` @@ -140,7 +140,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.8.1 + 6.9.0 ``` diff --git a/changelog b/changelog index 9d727dde3..2075c1bc7 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[6.9.0] * Add Xero API (https://www.xero.com/) (thanks to https://github.com/SidneyAllen) [6.8.1] From 16c9cca7b3d3aeb1db60ae7cb3429e7b45d97abf Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 4 Oct 2019 14:44:14 +0300 Subject: [PATCH 362/481] [maven-release-plugin] prepare release scribejava-6.9.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 2bd9bdd0e..9b835f686 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.8.2-SNAPSHOT + 6.9.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-6.9.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 69eb60aa8..f8a0c8447 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.2-SNAPSHOT + 6.9.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 1abb65221..01166a22e 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.2-SNAPSHOT + 6.9.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 642286105..9288ea67b 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.2-SNAPSHOT + 6.9.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index efcced401..8b8c380d8 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.2-SNAPSHOT + 6.9.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index f2ed3cf2d..2d2e7fad0 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.2-SNAPSHOT + 6.9.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index c7935567c..bbd6ca92e 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.8.2-SNAPSHOT + 6.9.0 ../pom.xml From b19ba640cd9c37761ff86039519806d94a12660a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Fri, 4 Oct 2019 14:44:43 +0300 Subject: [PATCH 363/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 9b835f686..72ffeb5e1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.9.0 + 6.9.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -34,7 +34,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-6.9.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index f8a0c8447..fe2dd76c0 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.0 + 6.9.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 01166a22e..0fc1965c9 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.0 + 6.9.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 9288ea67b..7ac157bd8 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.0 + 6.9.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 8b8c380d8..ecb3a4390 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.0 + 6.9.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 2d2e7fad0..1bf4a7f51 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.0 + 6.9.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index bbd6ca92e..e468d46fe 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.0 + 6.9.1-SNAPSHOT ../pom.xml From ea42bc94876e58d0730e3b871b095878f3f6fc49 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 14 Oct 2019 14:20:14 +0300 Subject: [PATCH 364/481] upgrade okhttp 4.2.0 -> 4.2.2 --- pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 72ffeb5e1..88210b98e 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,7 @@ com.squareup.okhttp3 mockwebserver - 4.2.0 + 4.2.2 test diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index e468d46fe..7ac66ff5c 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 4.2.0 + 4.2.2 com.github.scribejava From 3a095e2471b6a24bb2e74a6b7bf95a63d98ce387 Mon Sep 17 00:00:00 2001 From: Alex Vidrean Date: Tue, 15 Oct 2019 19:23:46 +0300 Subject: [PATCH 365/481] feat: added polar oauth2 api and example --- .../github/scribejava/apis/PolarAPI20.java | 54 ++++++++++++ .../apis/polar/PolarJsonTokenExtractor.java | 49 +++++++++++ .../apis/polar/PolarOAuth20Service.java | 45 ++++++++++ .../apis/polar/PolarOauth2AccessToken.java | 45 ++++++++++ .../apis/examples/PolarAPI20Example.java | 83 +++++++++++++++++++ 5 files changed, 276 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI20.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOauth2AccessToken.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI20.java new file mode 100644 index 000000000..ba3026953 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI20.java @@ -0,0 +1,54 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.polar.PolarJsonTokenExtractor; +import com.github.scribejava.apis.polar.PolarOAuth20Service; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.OutputStream; + +/** + * Polar's OAuth2 client's implementation + * source: https://www.polar.com/accesslink-api/#authentication + */ +public class PolarAPI20 extends DefaultApi20 { + + protected PolarAPI20() { + } + + private static class InstanceHolder { + + private static final PolarAPI20 INSTANCE = new PolarAPI20(); + } + + public static PolarAPI20 instance() { + return PolarAPI20.InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://polarremote.com/v2/oauth2/token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://flow.polar.com/oauth2/authorization"; + } + + @Override + public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, + OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + + return new PolarOAuth20Service(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, + httpClientConfig, httpClient); + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return PolarJsonTokenExtractor.instance(); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java new file mode 100644 index 000000000..dbfee8be2 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java @@ -0,0 +1,49 @@ +package com.github.scribejava.apis.polar; + +import com.fasterxml.jackson.databind.JsonNode; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; +import com.github.scribejava.core.oauth2.OAuth2Error; + +import java.io.IOException; + +/** + * Token related documentation: https://www.polar.com/accesslink-api/#token-endpoint + */ +public class PolarJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { + + protected PolarJsonTokenExtractor() { + } + + private static class InstanceHolder { + + private static final PolarJsonTokenExtractor INSTANCE = new PolarJsonTokenExtractor(); + } + + public static PolarJsonTokenExtractor instance() { + return InstanceHolder.INSTANCE; + } + + @Override + protected PolarOauth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, + String refreshToken, String scope, JsonNode response, String rawResponse) { + return new PolarOauth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, + response.get("x_user_id").asText(), rawResponse); + } + + @Override + public void generateError(String rawResponse) throws IOException { + final JsonNode errorNode = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER.readTree(rawResponse) + .get("errors").get(0); + + OAuth2Error errorCode; + try { + errorCode = OAuth2Error.parseFrom(extractRequiredParameter(errorNode, "errorType", rawResponse).asText()); + } catch (IllegalArgumentException iaE) { + //non oauth standard error code + errorCode = null; + } + + throw new OAuth2AccessTokenErrorResponse(errorCode, errorNode.get("message").asText(), null, rawResponse); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java new file mode 100644 index 000000000..238b31084 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java @@ -0,0 +1,45 @@ +package com.github.scribejava.apis.polar; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.AccessTokenRequestParams; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.core.pkce.PKCE; + +import java.io.OutputStream; + +public class PolarOAuth20Service extends OAuth20Service { + + public PolarOAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, + OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, httpClient); + } + + @Override + protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) { + final OAuthRequest request = new OAuthRequest(getApi().getAccessTokenVerb(), getApi().getAccessTokenEndpoint()); + + getApi().getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); + + request.addBodyParameter(OAuthConstants.CODE, params.getCode()); + final String callback = getCallback(); + if (callback != null) { + request.addBodyParameter(OAuthConstants.REDIRECT_URI, callback); + } + request.addBodyParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); + + final String pkceCodeVerifier = params.getPkceCodeVerifier(); + if (pkceCodeVerifier != null) { + request.addBodyParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); + } + if (isDebug()) { + log("created access token request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); + } + return request; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOauth2AccessToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOauth2AccessToken.java new file mode 100644 index 000000000..ca1d84b1f --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOauth2AccessToken.java @@ -0,0 +1,45 @@ +package com.github.scribejava.apis.polar; + +import com.github.scribejava.core.model.OAuth2AccessToken; + +import java.util.Objects; + +public class PolarOauth2AccessToken extends OAuth2AccessToken { + + private String userId; + + public PolarOauth2AccessToken( + String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, String userId, String rawResponse) { + super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); + this.userId = userId; + } + + public String getUserId() { + return userId; + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 37 * hash + Objects.hashCode(userId); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + if (!super.equals(obj)) { + return false; + } + + return Objects.equals(userId, ((PolarOauth2AccessToken) obj).getUserId()); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java new file mode 100644 index 000000000..376ab6e85 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java @@ -0,0 +1,83 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.PolarAPI20; +import com.github.scribejava.apis.polar.PolarOauth2AccessToken; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.util.Scanner; + +/** + * @author Alex Vidrean + * @since 13-Oct-19 + */ +public class PolarAPI20Example { + + private static final String NETWORK_NAME = "Polar"; + + private static final String PROTECTED_RESOURCE_URL = "https://www.polaraccesslink.com/v3/users/%s"; + + private PolarAPI20Example() { + } + + @SuppressWarnings("PMD.SystemPrintln") + public static void main(String... args) throws Exception { + + // Replace these with your client id and secret fron your app + final String clientId = "1a86ac29-7ea3-473a-81d9-8ea582214558"; + final String clientSecret = "0dc23e1d-b677-4da0-bb14-311949898a95"; + final String scope = "accesslink.read_all"; + final String callback = "http://localhost"; + final OAuth20Service service = new ServiceBuilder(clientId).apiSecret(clientSecret).defaultScope(scope) + //your callback URL to store and handle the authorization code sent by Polar + .callback(callback).build(PolarAPI20.instance()); + final Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl("some_params"); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("Trading the Authorization Code for an Access Token..."); + System.out.println("Got the Access Token!"); + final OAuth2AccessToken oauth2AccessToken = service.getAccessToken(code); + System.out.println("(if your curious it looks like this: " + oauth2AccessToken + ", 'rawResponse'='" + oauth2AccessToken.getRawResponse() + "')"); + System.out.println(); + + if (!(oauth2AccessToken instanceof PolarOauth2AccessToken)) { + System.out.println("oauth2AccessToken is not instance of PolarOAuth2AccessToken. Strange enough. exit."); + return; + } + + final PolarOauth2AccessToken accessToken = (PolarOauth2AccessToken) oauth2AccessToken; + + // Now let's go and ask for a protected resource! + // This will get the profile for this user + System.out.println("Now we're going to access a protected resource..."); + + final OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, accessToken.getUserId())); + request.addHeader("Accept", "application/json"); + + service.signRequest(accessToken, request); + + System.out.println(); + try (Response response = service.execute(request)) { + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } + System.out.println(); + } +} From 443c243589dbe8fdb6ca450aa3cefa5b7689cd86 Mon Sep 17 00:00:00 2001 From: Alex Vidrean Date: Sun, 20 Oct 2019 11:19:57 +0300 Subject: [PATCH 366/481] refactor: revert adding polar parameters for access token call to BodyParameter fix: removed actual client id and secret from polar example --- .../github/scribejava/apis/polar/PolarOAuth20Service.java | 8 ++++---- .../scribejava/apis/examples/PolarAPI20Example.java | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java index 238b31084..3b1bbca0c 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java @@ -24,16 +24,16 @@ protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) getApi().getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); - request.addBodyParameter(OAuthConstants.CODE, params.getCode()); + request.addParameter(OAuthConstants.CODE, params.getCode()); final String callback = getCallback(); if (callback != null) { - request.addBodyParameter(OAuthConstants.REDIRECT_URI, callback); + request.addParameter(OAuthConstants.REDIRECT_URI, callback); } - request.addBodyParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); final String pkceCodeVerifier = params.getPkceCodeVerifier(); if (pkceCodeVerifier != null) { - request.addBodyParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); + request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); } if (isDebug()) { log("created access token request with body params [%s], query string params [%s]", diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java index 376ab6e85..3b670de1d 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java @@ -28,10 +28,10 @@ private PolarAPI20Example() { public static void main(String... args) throws Exception { // Replace these with your client id and secret fron your app - final String clientId = "1a86ac29-7ea3-473a-81d9-8ea582214558"; - final String clientSecret = "0dc23e1d-b677-4da0-bb14-311949898a95"; + final String clientId = "your api client"; + final String clientSecret = "your api secret"; final String scope = "accesslink.read_all"; - final String callback = "http://localhost"; + final String callback = "your api callback"; final OAuth20Service service = new ServiceBuilder(clientId).apiSecret(clientSecret).defaultScope(scope) //your callback URL to store and handle the authorization code sent by Polar .callback(callback).build(PolarAPI20.instance()); From cca662cb770b8920e52e2a2a6dcf822db8d5e0e2 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 21 Oct 2019 15:52:24 +0300 Subject: [PATCH 367/481] Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) --- README.md | 1 + changelog | 3 + .../com/github/scribejava/apis/PolarAPI.java | 53 ++++++++++++ .../github/scribejava/apis/PolarAPI20.java | 54 ------------ .../apis/polar/PolarJsonTokenExtractor.java | 4 +- .../apis/polar/PolarOAuth20Service.java | 45 ---------- .../apis/polar/PolarOAuth2AccessToken.java | 45 ++++++++++ .../apis/polar/PolarOAuthService.java | 47 +++++++++++ .../apis/polar/PolarOauth2AccessToken.java | 45 ---------- .../apis/examples/PolarAPI20Example.java | 83 ------------------- .../apis/examples/PolarAPIExample.java | 82 ++++++++++++++++++ 11 files changed, 233 insertions(+), 229 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI20.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth2AccessToken.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuthService.java delete mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOauth2AccessToken.java delete mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPIExample.java diff --git a/README.md b/README.md index 1b1f0665c..199e1c7a5 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ ScribeJava support out-of-box several HTTP clients: * Misfit (http://misfit.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MisfitExample.java) * NAVER (http://www.naver.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/NaverExample.java) * Odnoklassniki Одноклассники (http://ok.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/OdnoklassnikiExample.java) +* Polar (https://www.polar.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPIExample.java) * Pinterest (https://www.pinterest.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PinterestExample.java) * 500px (https://500px.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java) * Renren (http://renren.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/RenrenExample.java) diff --git a/changelog b/changelog index 2075c1bc7..a8de5b3b2 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) + [6.9.0] * Add Xero API (https://www.xero.com/) (thanks to https://github.com/SidneyAllen) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI.java new file mode 100644 index 000000000..01e1651c6 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI.java @@ -0,0 +1,53 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.polar.PolarJsonTokenExtractor; +import com.github.scribejava.apis.polar.PolarOAuthService; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuth2AccessToken; + +import java.io.OutputStream; + +/** + * Polar's OAuth2 client's implementation source: https://www.polar.com/accesslink-api/#authentication + */ +public class PolarAPI extends DefaultApi20 { + + protected PolarAPI() { + } + + private static class InstanceHolder { + + private static final PolarAPI INSTANCE = new PolarAPI(); + } + + public static PolarAPI instance() { + return PolarAPI.InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://polarremote.com/v2/oauth2/token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://flow.polar.com/oauth2/authorization"; + } + + @Override + public PolarOAuthService createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + + return new PolarOAuthService(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, + userAgent, httpClientConfig, httpClient); + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return PolarJsonTokenExtractor.instance(); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI20.java deleted file mode 100644 index ba3026953..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/PolarAPI20.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.github.scribejava.apis; - -import com.github.scribejava.apis.polar.PolarJsonTokenExtractor; -import com.github.scribejava.apis.polar.PolarOAuth20Service; -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.extractors.TokenExtractor; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.oauth.OAuth20Service; - -import java.io.OutputStream; - -/** - * Polar's OAuth2 client's implementation - * source: https://www.polar.com/accesslink-api/#authentication - */ -public class PolarAPI20 extends DefaultApi20 { - - protected PolarAPI20() { - } - - private static class InstanceHolder { - - private static final PolarAPI20 INSTANCE = new PolarAPI20(); - } - - public static PolarAPI20 instance() { - return PolarAPI20.InstanceHolder.INSTANCE; - } - - @Override - public String getAccessTokenEndpoint() { - return "https://polarremote.com/v2/oauth2/token"; - } - - @Override - protected String getAuthorizationBaseUrl() { - return "https://flow.polar.com/oauth2/authorization"; - } - - @Override - public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, String responseType, - OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - - return new PolarOAuth20Service(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, - httpClientConfig, httpClient); - } - - @Override - public TokenExtractor getAccessTokenExtractor() { - return PolarJsonTokenExtractor.instance(); - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java index dbfee8be2..efca61631 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java @@ -25,9 +25,9 @@ public static PolarJsonTokenExtractor instance() { } @Override - protected PolarOauth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, + protected PolarOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, JsonNode response, String rawResponse) { - return new PolarOauth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, + return new PolarOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, response.get("x_user_id").asText(), rawResponse); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java deleted file mode 100644 index 3b1bbca0c..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth20Service.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.github.scribejava.apis.polar; - -import com.github.scribejava.core.builder.api.DefaultApi20; -import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.OAuthConstants; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.oauth.AccessTokenRequestParams; -import com.github.scribejava.core.oauth.OAuth20Service; -import com.github.scribejava.core.pkce.PKCE; - -import java.io.OutputStream; - -public class PolarOAuth20Service extends OAuth20Service { - - public PolarOAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, - OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, httpClient); - } - - @Override - protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) { - final OAuthRequest request = new OAuthRequest(getApi().getAccessTokenVerb(), getApi().getAccessTokenEndpoint()); - - getApi().getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); - - request.addParameter(OAuthConstants.CODE, params.getCode()); - final String callback = getCallback(); - if (callback != null) { - request.addParameter(OAuthConstants.REDIRECT_URI, callback); - } - request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); - - final String pkceCodeVerifier = params.getPkceCodeVerifier(); - if (pkceCodeVerifier != null) { - request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); - } - if (isDebug()) { - log("created access token request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); - } - return request; - } -} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth2AccessToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth2AccessToken.java new file mode 100644 index 000000000..d9ea04035 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth2AccessToken.java @@ -0,0 +1,45 @@ +package com.github.scribejava.apis.polar; + +import com.github.scribejava.core.model.OAuth2AccessToken; + +import java.util.Objects; + +public class PolarOAuth2AccessToken extends OAuth2AccessToken { + + private final String userId; + + public PolarOAuth2AccessToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, + String scope, String userId, String rawResponse) { + super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); + this.userId = userId; + } + + public String getUserId() { + return userId; + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 37 * hash + Objects.hashCode(userId); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + if (!super.equals(obj)) { + return false; + } + + return Objects.equals(userId, ((PolarOAuth2AccessToken) obj).getUserId()); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuthService.java new file mode 100644 index 000000000..e0b0af6f1 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuthService.java @@ -0,0 +1,47 @@ +package com.github.scribejava.apis.polar; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.oauth.AccessTokenRequestParams; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.core.pkce.PKCE; + +import java.io.OutputStream; + +public class PolarOAuthService extends OAuth20Service { + + public PolarOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, + httpClient); + } + + @Override + protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) { + final OAuthRequest request = new OAuthRequest(getApi().getAccessTokenVerb(), getApi().getAccessTokenEndpoint()); + + getApi().getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); + + request.addParameter(OAuthConstants.CODE, params.getCode()); + final String callback = getCallback(); + if (callback != null) { + request.addParameter(OAuthConstants.REDIRECT_URI, callback); + } + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); + + final String pkceCodeVerifier = params.getPkceCodeVerifier(); + if (pkceCodeVerifier != null) { + request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); + } + if (isDebug()) { + log("created access token request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); + } + return request; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOauth2AccessToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOauth2AccessToken.java deleted file mode 100644 index ca1d84b1f..000000000 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOauth2AccessToken.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.github.scribejava.apis.polar; - -import com.github.scribejava.core.model.OAuth2AccessToken; - -import java.util.Objects; - -public class PolarOauth2AccessToken extends OAuth2AccessToken { - - private String userId; - - public PolarOauth2AccessToken( - String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, String userId, String rawResponse) { - super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); - this.userId = userId; - } - - public String getUserId() { - return userId; - } - - @Override - public int hashCode() { - int hash = super.hashCode(); - hash = 37 * hash + Objects.hashCode(userId); - return hash; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - if (!super.equals(obj)) { - return false; - } - - return Objects.equals(userId, ((PolarOauth2AccessToken) obj).getUserId()); - } -} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java deleted file mode 100644 index 3b670de1d..000000000 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPI20Example.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.github.scribejava.apis.examples; - -import com.github.scribejava.apis.PolarAPI20; -import com.github.scribejava.apis.polar.PolarOauth2AccessToken; -import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuth20Service; - -import java.util.Scanner; - -/** - * @author Alex Vidrean - * @since 13-Oct-19 - */ -public class PolarAPI20Example { - - private static final String NETWORK_NAME = "Polar"; - - private static final String PROTECTED_RESOURCE_URL = "https://www.polaraccesslink.com/v3/users/%s"; - - private PolarAPI20Example() { - } - - @SuppressWarnings("PMD.SystemPrintln") - public static void main(String... args) throws Exception { - - // Replace these with your client id and secret fron your app - final String clientId = "your api client"; - final String clientSecret = "your api secret"; - final String scope = "accesslink.read_all"; - final String callback = "your api callback"; - final OAuth20Service service = new ServiceBuilder(clientId).apiSecret(clientSecret).defaultScope(scope) - //your callback URL to store and handle the authorization code sent by Polar - .callback(callback).build(PolarAPI20.instance()); - final Scanner in = new Scanner(System.in); - - System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); - System.out.println(); - - // Obtain the Authorization URL - System.out.println("Fetching the Authorization URL..."); - final String authorizationUrl = service.getAuthorizationUrl("some_params"); - System.out.println("Got the Authorization URL!"); - System.out.println("Now go and authorize ScribeJava here:"); - System.out.println(authorizationUrl); - System.out.println("And paste the authorization code here"); - System.out.print(">>"); - final String code = in.nextLine(); - System.out.println(); - - System.out.println("Trading the Authorization Code for an Access Token..."); - System.out.println("Got the Access Token!"); - final OAuth2AccessToken oauth2AccessToken = service.getAccessToken(code); - System.out.println("(if your curious it looks like this: " + oauth2AccessToken + ", 'rawResponse'='" + oauth2AccessToken.getRawResponse() + "')"); - System.out.println(); - - if (!(oauth2AccessToken instanceof PolarOauth2AccessToken)) { - System.out.println("oauth2AccessToken is not instance of PolarOAuth2AccessToken. Strange enough. exit."); - return; - } - - final PolarOauth2AccessToken accessToken = (PolarOauth2AccessToken) oauth2AccessToken; - - // Now let's go and ask for a protected resource! - // This will get the profile for this user - System.out.println("Now we're going to access a protected resource..."); - - final OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, accessToken.getUserId())); - request.addHeader("Accept", "application/json"); - - service.signRequest(accessToken, request); - - System.out.println(); - try (Response response = service.execute(request)) { - System.out.println(response.getCode()); - System.out.println(response.getBody()); - } - System.out.println(); - } -} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPIExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPIExample.java new file mode 100644 index 000000000..501a8e470 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/PolarAPIExample.java @@ -0,0 +1,82 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.PolarAPI; +import com.github.scribejava.apis.polar.PolarOAuth2AccessToken; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.util.Scanner; + +public class PolarAPIExample { + + private static final String NETWORK_NAME = "Polar"; + + private static final String PROTECTED_RESOURCE_URL = "https://www.polaraccesslink.com/v3/users/%s"; + + private PolarAPIExample() { + } + + @SuppressWarnings("PMD.SystemPrintln") + public static void main(String... args) throws Exception { + final String clientId = "your_api_client"; + final String clientSecret = "your_api_secret"; + final String scope = "accesslink.read_all"; + final String callback = "your_api_callback"; + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .defaultScope(scope) + //your callback URL to store and handle the authorization code sent by Polar + .callback(callback) + .build(PolarAPI.instance()); + final Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl("some_params"); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("Trading the Authorization Code for an Access Token..."); + System.out.println("Got the Access Token!"); + final OAuth2AccessToken oauth2AccessToken = service.getAccessToken(code); + System.out.println("(if your curious it looks like this: " + oauth2AccessToken + + ", 'rawResponse'='" + oauth2AccessToken.getRawResponse() + "')"); + System.out.println(); + + if (!(oauth2AccessToken instanceof PolarOAuth2AccessToken)) { + System.out.println("oauth2AccessToken is not instance of PolarOAuth2AccessToken. Strange enough. exit."); + return; + } + + final PolarOAuth2AccessToken accessToken = (PolarOAuth2AccessToken) oauth2AccessToken; + + // Now let's go and ask for a protected resource! + // This will get the profile for this user + System.out.println("Now we're going to access a protected resource..."); + + final OAuthRequest request = new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, + accessToken.getUserId())); + request.addHeader("Accept", "application/json"); + + service.signRequest(accessToken, request); + + System.out.println(); + try (Response response = service.execute(request)) { + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } + System.out.println(); + } +} From 3f1cd63ae5c41dacffced9fc0d73446af9f1ca89 Mon Sep 17 00:00:00 2001 From: bjournaud Date: Thu, 23 Jan 2020 18:15:46 +0100 Subject: [PATCH 368/481] Add proxy option to JDKHttpClient --- .../scribejava/core/httpclient/jdk/JDKHttpClient.java | 7 ++++++- .../core/httpclient/jdk/JDKHttpClientConfig.java | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 3f4648a77..25212977c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -115,7 +115,12 @@ public Response execute(String userAgent, Map headers, Verb http private Response doExecute(String userAgent, Map headers, Verb httpVerb, String completeUrl, BodyType bodyType, Object bodyContents) throws IOException { - final HttpURLConnection connection = (HttpURLConnection) new URL(completeUrl).openConnection(); + final HttpURLConnection connection; + if (config.getProxy() == null) { + connection = (HttpURLConnection) new URL(completeUrl).openConnection(); + }else { + connection = (HttpURLConnection) new URL(completeUrl).openConnection(config.getProxy()); + } connection.setInstanceFollowRedirects(config.isFollowRedirects()); connection.setRequestMethod(httpVerb.name()); if (config.getConnectTimeout() != null) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java index cfb97b359..baa431b83 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java @@ -1,5 +1,7 @@ package com.github.scribejava.core.httpclient.jdk; +import java.net.Proxy; + import com.github.scribejava.core.httpclient.HttpClientConfig; public class JDKHttpClientConfig implements HttpClientConfig { @@ -7,6 +9,7 @@ public class JDKHttpClientConfig implements HttpClientConfig { private Integer connectTimeout; private Integer readTimeout; private boolean followRedirects = true; + private Proxy proxy; @Override public JDKHttpClientConfig createDefaultConfig() { @@ -37,6 +40,14 @@ public boolean isFollowRedirects() { return followRedirects; } + public void setProxy(Proxy proxy) { + this.proxy = proxy; + } + + public Proxy getProxy() { + return proxy; + } + /** * Sets whether the underlying Http Connection follows redirects or not. * From 241969cbee80d2bdefe9fcedd97c52dbe5d6899d Mon Sep 17 00:00:00 2001 From: afkbrb <2w6f8c@gmail.com> Date: Sat, 14 Mar 2020 14:09:47 +0800 Subject: [PATCH 369/481] change "Verfier" to "Verifier" --- .../java/com/github/scribejava/apis/examples/AWeberExample.java | 2 +- .../java/com/github/scribejava/apis/examples/DiggExample.java | 2 +- .../java/com/github/scribejava/apis/examples/FlickrExample.java | 2 +- .../com/github/scribejava/apis/examples/FoursquareExample.java | 2 +- .../com/github/scribejava/apis/examples/FreelancerExample.java | 2 +- .../com/github/scribejava/apis/examples/LinkedInExample.java | 2 +- .../scribejava/apis/examples/LinkedInExampleWithScopes.java | 2 +- .../com/github/scribejava/apis/examples/MediaWikiExample.java | 2 +- .../java/com/github/scribejava/apis/examples/MeetupExample.java | 2 +- .../java/com/github/scribejava/apis/examples/Px500Example.java | 2 +- .../com/github/scribejava/apis/examples/SinaWeiboExample.java | 2 +- .../com/github/scribejava/apis/examples/SkyrockExample.java | 2 +- .../java/com/github/scribejava/apis/examples/TrelloExample.java | 2 +- .../java/com/github/scribejava/apis/examples/TumblrExample.java | 2 +- .../com/github/scribejava/apis/examples/TwitterExample.java | 2 +- .../java/com/github/scribejava/apis/examples/UcozExample.java | 2 +- .../java/com/github/scribejava/apis/examples/XingExample.java | 2 +- .../java/com/github/scribejava/apis/examples/YahooExample.java | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java index 635017b52..e61110716 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java @@ -47,7 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java index 1f84a45ed..eb2820683 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/DiggExample.java @@ -50,7 +50,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java index 5da371ca6..8cdf8a209 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FlickrExample.java @@ -48,7 +48,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java index c7b09ca2e..6aa3c9435 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FoursquareExample.java @@ -42,7 +42,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java index 019f7efa0..023d789c4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FreelancerExample.java @@ -48,7 +48,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java index abb53baf4..ec1051134 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java @@ -43,7 +43,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java index fe2b395ac..3b795de1f 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java @@ -47,7 +47,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java index 8aaef6673..621480013 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MediaWikiExample.java @@ -48,7 +48,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java index ad6a9bc25..e3c7c8e8c 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MeetupExample.java @@ -42,7 +42,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java index c9b06f540..e441cebdd 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Px500Example.java @@ -42,7 +42,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java index d787aa45e..767ccdbab 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java @@ -50,7 +50,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java index 84bc61381..f2c0cf007 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java @@ -42,7 +42,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java index 65f64592e..737bd768e 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java @@ -44,7 +44,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java index 3cd648aee..063b8b9b2 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TumblrExample.java @@ -44,7 +44,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java index 13a86535b..748fa9034 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java @@ -42,7 +42,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java index ae3270020..5760bb36a 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/UcozExample.java @@ -37,7 +37,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.print(">>"); final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java index 6850fadab..ebf946db5 100755 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java @@ -42,7 +42,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java index ccaedba11..acaa42aea 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java @@ -43,7 +43,7 @@ public static void main(String... args) throws IOException, InterruptedException final String oauthVerifier = in.nextLine(); System.out.println(); - // Trade the Request Token and Verfier for the Access Token + // Trade the Request Token and Verifier for the Access Token System.out.println("Trading the Request Token for an Access Token..."); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier); System.out.println("Got the Access Token!"); From a7b01f632ac4283db7b7833d64b17a717de4bee7 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Thu, 19 Mar 2020 18:39:32 +0300 Subject: [PATCH 370/481] update deps --- pmd.xml | 2 +- pom.xml | 18 +++--- .../fitbit/FitBitJsonTokenExtractorTest.java | 62 ++++++------------- .../multipart/MultipartPayload.java | 2 +- .../multipart/MultipartPayloadTest.java | 49 ++++++--------- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 51 insertions(+), 88 deletions(-) diff --git a/pmd.xml b/pmd.xml index 6c204f770..7b5314710 100644 --- a/pmd.xml +++ b/pmd.xml @@ -93,7 +93,7 @@ - + diff --git a/pom.xml b/pom.xml index 88210b98e..a7a764942 100644 --- a/pom.xml +++ b/pom.xml @@ -56,18 +56,18 @@ com.fasterxml.jackson.core jackson-databind - 2.10.0 + 2.10.3 junit junit - 4.12 + 4.13 test com.squareup.okhttp3 mockwebserver - 4.2.2 + 4.4.1 test @@ -91,7 +91,7 @@ org.apache.maven.plugins maven-jar-plugin - 3.1.2 + 3.2.0 ${project.build.outputDirectory}/META-INF/MANIFEST.MF @@ -101,12 +101,12 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.1.0 + 3.1.1 com.puppycrawl.tools checkstyle - 8.25 + 8.30 @@ -174,7 +174,7 @@ org.apache.maven.plugins maven-source-plugin - 3.1.0 + 3.2.1 attach-sources @@ -227,7 +227,7 @@ org.apache.maven.plugins maven-pmd-plugin - 3.12.0 + 3.13.0 net.sourceforge.pmd @@ -273,7 +273,7 @@ 7 - 6.17.0 + 6.22.0 diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java index e717dbd7b..396377294 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java @@ -4,58 +4,34 @@ import com.github.scribejava.core.oauth2.OAuth2Error; import java.io.IOException; -import org.hamcrest.FeatureMatcher; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; -import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertEquals; +import org.junit.function.ThrowingRunnable; public class FitBitJsonTokenExtractorTest { - private static final String ERROR_DESCRIPTION = "Authorization code invalid: " + - "cbb1c11b23209011e89be71201fa6381464dc0af " + - "Visit https://dev.fitbit.com/docs/oauth2 for more information " + - "on the Fitbit Web API authorization process."; - private static final String ERROR_JSON = "{\"errors\":[{\"errorType\":\"invalid_grant\",\"message\":\"" + - ERROR_DESCRIPTION + "\"}],\"success\":false}"; - - @Rule - public ExpectedException thrown = ExpectedException.none(); + private static final String ERROR_DESCRIPTION = "Authorization code invalid: " + + "cbb1c11b23209011e89be71201fa6381464dc0af " + + "Visit https://dev.fitbit.com/docs/oauth2 for more information " + + "on the Fitbit Web API authorization process."; + private static final String ERROR_JSON = "{\"errors\":[{\"errorType\":\"invalid_grant\",\"message\":\"" + + ERROR_DESCRIPTION + "\"}],\"success\":false}"; @Test public void testErrorExtraction() throws IOException { final FitBitJsonTokenExtractor extractor = new FitBitJsonTokenExtractor(); - - thrown.expect(OAuth2AccessTokenErrorResponse.class); - thrown.expect(new ErrorCodeFeatureMatcher(OAuth2Error.INVALID_GRANT)); - thrown.expect(new ErrorDescriptionFeatureMatcher(ERROR_DESCRIPTION)); - - extractor.generateError(ERROR_JSON); - } - - private static class ErrorCodeFeatureMatcher extends FeatureMatcher { - - private ErrorCodeFeatureMatcher(OAuth2Error expected) { - super(equalTo(expected), "a response with errorCode", "errorCode"); - } - - @Override - protected OAuth2Error featureValueOf(OAuth2AccessTokenErrorResponse actual) { - return actual.getError(); - } - } - - private static class ErrorDescriptionFeatureMatcher extends FeatureMatcher { - - private ErrorDescriptionFeatureMatcher(String expected) { - super(equalTo(expected), "a response with errorDescription", "errorDescription"); - } - - @Override - protected String featureValueOf(OAuth2AccessTokenErrorResponse actual) { - return actual.getErrorDescription(); - } + final OAuth2AccessTokenErrorResponse thrown = assertThrows(OAuth2AccessTokenErrorResponse.class, + new ThrowingRunnable() { + @Override + public void run() throws Throwable { + extractor.generateError(ERROR_JSON); + } + }); + assertSame(OAuth2Error.INVALID_GRANT, thrown.getError()); + assertEquals(ERROR_DESCRIPTION, thrown.getErrorDescription()); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java index 5c9282272..7e3f8cfde 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java @@ -77,7 +77,7 @@ private static Map composeHeaders(String subtype, String boundar static void checkBoundarySyntax(String boundary) { if (boundary == null || !BOUNDARY_REGEXP.matcher(boundary).matches()) { - throw new IllegalArgumentException("{'boundary'='" + boundary + "'} has invaid syntax. Should be '" + throw new IllegalArgumentException("{'boundary'='" + boundary + "'} has invalid syntax. Should be '" + BOUNDARY_PATTERN + "'."); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java index a7989a01e..4abc36ee5 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java @@ -1,17 +1,14 @@ package com.github.scribejava.core.httpclient.multipart; -import org.hamcrest.core.StringStartsWith; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import org.junit.Rule; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.function.ThrowingRunnable; public class MultipartPayloadTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Test public void testValidCheckBoundarySyntax() { MultipartPayload.checkBoundarySyntax("0aA'()+_,-./:=?"); @@ -22,47 +19,27 @@ public void testValidCheckBoundarySyntax() { @Test public void testNonValidLastWhiteSpaceCheckBoundarySyntax() { - final String boundary = "0aA'()+_,-./:=? "; - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage( - StringStartsWith.startsWith("{'boundary'='" + boundary + "'} has invaid syntax. Should be '")); - MultipartPayload.checkBoundarySyntax(boundary); + testBoundary("0aA'()+_,-./:=? "); } @Test public void testNonValidEmptyCheckBoundarySyntax() { - final String boundary = ""; - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage( - StringStartsWith.startsWith("{'boundary'='" + boundary + "'} has invaid syntax. Should be '")); - MultipartPayload.checkBoundarySyntax(boundary); + testBoundary(""); } @Test public void testNonValidIllegalSymbolCheckBoundarySyntax() { - final String boundary = "0aA'()+_;,-./:=? "; - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage( - StringStartsWith.startsWith("{'boundary'='" + boundary + "'} has invaid syntax. Should be '")); - MultipartPayload.checkBoundarySyntax(boundary); + testBoundary("0aA'()+_;,-./:=? "); } @Test public void testNonValidTooLongCheckBoundarySyntax() { - final String boundary = "12345678901234567890123456789012345678901234567890123456789012345678901"; - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage( - StringStartsWith.startsWith("{'boundary'='" + boundary + "'} has invaid syntax. Should be '")); - MultipartPayload.checkBoundarySyntax(boundary); + testBoundary("12345678901234567890123456789012345678901234567890123456789012345678901"); } @Test public void testNonValidNullCheckBoundarySyntax() { - final String boundary = null; - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage( - StringStartsWith.startsWith("{'boundary'='" + boundary + "'} has invaid syntax. Should be '")); - MultipartPayload.checkBoundarySyntax(boundary); + testBoundary(null); } @Test @@ -118,4 +95,14 @@ public void testParseBoundaryFromHeader() { assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=;123")); assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"\"123")); } + + private static void testBoundary(final String boundary) { + final IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + MultipartPayload.checkBoundarySyntax(boundary); + } + }); + assertTrue(thrown.getMessage().startsWith("{'boundary'='" + boundary + "'} has invalid syntax. Should be '")); + } } diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 7ac157bd8..51553b620 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.10.3 + 2.11.0 com.github.scribejava diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index ecb3a4390..7a0933f34 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -23,7 +23,7 @@ org.apache.httpcomponents httpclient - 4.5.10 + 4.5.12 org.apache.httpcomponents diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 7ac66ff5c..33b6da071 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 4.2.2 + 4.4.1 com.github.scribejava From 7bb59c36799a635f526206af010136669f23c33f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20Schejbal?= Date: Mon, 6 Apr 2020 16:00:25 +0200 Subject: [PATCH 371/481] initial support for device flow --- .../BaseMicrosoftAzureActiveDirectoryApi.java | 5 + .../core/builder/api/DefaultApi20.java | 4 + .../OAuth2AccessTokenJsonExtractor.java | 2 +- .../scribejava/core/model/DeviceCode.java | 38 +++++++ .../scribejava/core/oauth/OAuth20Service.java | 100 +++++++++++++++++- .../scribejava/core/oauth2/OAuth2Error.java | 31 +++++- 6 files changed, 172 insertions(+), 8 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceCode.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java index 5e4891164..8dc5d5616 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java @@ -30,6 +30,11 @@ protected String getAuthorizationBaseUrl() { return MSFT_LOGIN_URL + tenant + OAUTH_2 + getEndpointVersionPath() + "/authorize"; } + @Override + public String getDeviceAuthorizationUrl() { + return MSFT_LOGIN_URL + tenant + OAUTH_2 + getEndpointVersionPath() + "/devicecode"; + } + @Override public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index 64ad82f00..ad1afcc65 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -121,4 +121,8 @@ public BearerSignature getBearerSignature() { public ClientAuthentication getClientAuthentication() { return HttpBasicAuthenticationScheme.instance(); } + + public String getDeviceAuthorizationUrl() { + return null; + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index b1b8c4536..c2f483e0e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -93,7 +93,7 @@ protected OAuth2AccessToken createToken(String accessToken, String tokenType, In return new OAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); } - protected static JsonNode extractRequiredParameter(JsonNode errorNode, String parameterName, String rawResponse) + public static JsonNode extractRequiredParameter(JsonNode errorNode, String parameterName, String rawResponse) throws OAuthException { final JsonNode value = errorNode.get(parameterName); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceCode.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceCode.java new file mode 100644 index 000000000..8e31fc8aa --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceCode.java @@ -0,0 +1,38 @@ +package com.github.scribejava.core.model; + +public class DeviceCode { + private String deviceCode; + private String userCode; + private String verificationUri; + private int intervalSeconds; + private long expiresAtMillis; + + public DeviceCode(String deviceCode, String userCode, String verificationUri, + int intervalSeconds, int expiresInSeconds) { + this.deviceCode = deviceCode; + this.userCode = userCode; + this.verificationUri = verificationUri; + this.intervalSeconds = intervalSeconds; + expiresAtMillis = System.currentTimeMillis() + (expiresInSeconds * 1000); + } + + public String getDeviceCode() { + return deviceCode; + } + + public String getUserCode() { + return userCode; + } + + public String getVerificationUri() { + return verificationUri; + } + + public int getIntervalSeconds() { + return intervalSeconds; + } + + public long getExpiresAtMillis() { + return expiresAtMillis; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 43a5d1a9f..03a803e04 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -1,27 +1,38 @@ package com.github.scribejava.core.oauth; -import java.io.IOException; -import java.io.OutputStream; -import java.util.concurrent.Future; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.DeviceCode; import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; import com.github.scribejava.core.model.OAuth2Authorization; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth2.OAuth2Error; import com.github.scribejava.core.pkce.PKCE; -import java.util.Map; -import java.util.concurrent.ExecutionException; import com.github.scribejava.core.revoke.TokenTypeHint; +import java.io.IOException; +import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; +import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +import static com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor.extractRequiredParameter; +import static com.github.scribejava.core.oauth2.OAuth2Error.AUTHORIZATION_PENDING; +import static com.github.scribejava.core.oauth2.OAuth2Error.SLOW_DOWN; +import static java.lang.Thread.sleep; public class OAuth20Service extends OAuthService { + protected static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); private static final String VERSION = "2.0"; private final DefaultApi20 api; @@ -490,4 +501,83 @@ public String getResponseType() { public String getDefaultScope() { return defaultScope; } + + /** + * Requests a device code from a server. + * + * @see rfc8628 + * @see + * azure v2-oauth2-device-code + */ + public DeviceCode getDeviceCode() throws InterruptedException, ExecutionException, IOException { + final OAuthRequest request = new OAuthRequest(Verb.POST, api.getDeviceAuthorizationUrl()); + request.addBodyParameter(OAuthConstants.CLIENT_ID, getApiKey()); + request.addBodyParameter(OAuthConstants.SCOPE, getDefaultScope()); + try (Response response = execute(request)) { + final String body = response.getBody(); + if (response.getCode() == 200) { + final JsonNode n = OBJECT_MAPPER.readTree(body); + return new DeviceCode( + extractRequiredParameter(n, "device_code", body).textValue(), + extractRequiredParameter(n, "user_code", body).textValue(), + extractRequiredParameter(n, "verification_uri", body).textValue(), + n.path("interval").asInt(5), + extractRequiredParameter(n, "expires_in", body).intValue()); + } else { + OAuth2AccessTokenJsonExtractor.instance().generateError(body); + throw new IllegalStateException(); // generateError() always throws an exception + } + } + } + + /** + * Attempts to get a token from a server. + * Function {@link #pollDeviceAccessToken(DeviceCode)} is usually used instead of this. + * + * @return token + * @throws OAuth2AccessTokenErrorResponse + * If {@link OAuth2AccessTokenErrorResponse#getError()} is + * {@link OAuth2Error#AUTHORIZATION_PENDING} or {@link OAuth2Error#SLOW_DOWN}, + * another attempt should be made after a while. + * + * @see #getDeviceCode() + */ + public OAuth2AccessToken getAccessTokenDeviceCodeGrant(DeviceCode deviceCode) + throws IOException, InterruptedException, ExecutionException { + final OAuthRequest request = new OAuthRequest(Verb.POST, api.getAccessTokenEndpoint()); + request.addParameter(OAuthConstants.GRANT_TYPE, "urn:ietf:params:oauth:grant-type:device_code"); + request.addBodyParameter(OAuthConstants.CLIENT_ID, getApiKey()); + request.addParameter("device_code", deviceCode.getDeviceCode()); + try (Response response = execute(request)) { + return api.getAccessTokenExtractor().extract(response); + } + } + + /** + * Periodically tries to get a token from a server (waiting for the user to give consent). + * + * @return token + * @throws OAuth2AccessTokenErrorResponse + * Indicates OAuth error. + * + * @see #getDeviceCode() + */ + public OAuth2AccessToken pollDeviceAccessToken(DeviceCode deviceCode) + throws InterruptedException, ExecutionException, IOException { + long intervalMillis = deviceCode.getIntervalSeconds() * 1000; + while (true) { + try { + return getAccessTokenDeviceCodeGrant(deviceCode); + } catch (OAuth2AccessTokenErrorResponse e) { + if (e.getError() != AUTHORIZATION_PENDING) { + if (e.getError() == SLOW_DOWN) { + intervalMillis += 5000; + } else { + throw e; + } + } + } + sleep(intervalMillis); + } + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java index b5a8d89e6..af8f540f8 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java @@ -1,5 +1,10 @@ package com.github.scribejava.core.oauth2; +import java.util.EnumSet; +import java.util.Set; + +import static java.util.Collections.unmodifiableSet; + public enum OAuth2Error { /** * @see RFC 6749, 4.1.2.1 Error Response @@ -67,7 +72,29 @@ public enum OAuth2Error { * @see RFC 7009, 4.1. OAuth Extensions Error * Registration */ - UNSUPPORTED_TOKEN_TYPE("unsupported_token_type"); + UNSUPPORTED_TOKEN_TYPE("unsupported_token_type"), + + /** + * @see rfc8628#section-3.5 + */ + AUTHORIZATION_PENDING("authorization_pending"), + + /** + * @see rfc8628#section-3.5 + */ + SLOW_DOWN("slow_down"), + + /** + * @see rfc8628#section-3.5 + */ + EXPIRED_TOKEN("expired_token"), + ; + + /** + * Unlike {@link #values()} which creates a new array every time, this always + * returns the same immutable object. + */ + public static final Set VALUES = unmodifiableSet(EnumSet.allOf(OAuth2Error.class)); private final String errorString; @@ -76,7 +103,7 @@ public enum OAuth2Error { } public static OAuth2Error parseFrom(String errorString) { - for (OAuth2Error error : OAuth2Error.values()) { + for (OAuth2Error error : VALUES) { if (error.errorString.equals(errorString)) { return error; } From a8578ef2142fa2fca616ade32fff19d9d7423bf3 Mon Sep 17 00:00:00 2001 From: v0o0v Date: Thu, 9 Apr 2020 11:56:47 +0900 Subject: [PATCH 372/481] Add Kakao API --- .../com/github/scribejava/apis/KakaoApi.java | 34 +++++++++ .../apis/examples/KakaoExample.java | 70 +++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/KakaoApi.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KakaoExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KakaoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KakaoApi.java new file mode 100644 index 000000000..948705496 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KakaoApi.java @@ -0,0 +1,34 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; + +public class KakaoApi extends DefaultApi20 { + + protected KakaoApi() { + } + + private static class InstanceHolder { + private static final KakaoApi INSTANCE = new KakaoApi(); + } + + public static KakaoApi instance() { + return KakaoApi.InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://kauth.kakao.com/oauth/token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://kauth.kakao.com/oauth/authorize"; + } + + @Override + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KakaoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KakaoExample.java new file mode 100644 index 000000000..89b7b4f1d --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KakaoExample.java @@ -0,0 +1,70 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.KakaoApi; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.IOException; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public class KakaoExample { + + private static final String NETWORK_NAME = "Kakao"; + private static final String PROTECTED_RESOURCE_URL = "https://kapi.kakao.com/v2/user/me"; + + private KakaoExample() { + } + + @SuppressWarnings("PMD.SystemPrintln") + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "your client id"; + + final OAuth20Service service = new ServiceBuilder(clientId) + .callback("http://www.example.com/oauth_callback/") + .build(KakaoApi.instance()); + + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("Trading the Authorization Code for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + + } +} From b2458a8abe0cf8237c491986ba2832031bdcfd33 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 5 May 2020 18:26:52 +0300 Subject: [PATCH 373/481] make Response accept resources to autoclose and autoclose it (thanks to https://github.com/drei01) --- changelog | 1 + .../core/model/OAuthAsyncRequestCallback.java | 5 ++++ .../scribejava/core/model/OAuthRequest.java | 9 ++++++ .../scribejava/core/model/Response.java | 29 +++++++++++++++++-- .../core/oauth/OAuth10aService.java | 8 +++-- .../scribejava/core/oauth/OAuth20Service.java | 5 +++- .../apache/OAuthAsyncCompletionHandler.java | 4 ++- .../OAuthAsyncCompletionHandlerTest.java | 3 ++ .../ning/OAuthAsyncCompletionHandlerTest.java | 2 ++ .../okhttp/OAuthAsyncCompletionHandler.java | 6 ++-- .../httpclient/okhttp/OkHttpHttpClient.java | 6 ++-- .../OAuthAsyncCompletionHandlerTest.java | 3 ++ 12 files changed, 69 insertions(+), 12 deletions(-) diff --git a/changelog b/changelog index a8de5b3b2..8a117fae5 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) + * make Response accept resources to autoclose and autoclose it (thanks to https://github.com/drei01) [6.9.0] * Add Xero API (https://www.xero.com/) (thanks to https://github.com/SidneyAllen) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthAsyncRequestCallback.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthAsyncRequestCallback.java index 10f398fc4..466dd98ee 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthAsyncRequestCallback.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthAsyncRequestCallback.java @@ -2,6 +2,11 @@ public interface OAuthAsyncRequestCallback { + /** + * Implementations of this method should close provided response in case it implements {@link java.io.Closeable} + * + * @param response + */ void onCompleted(T response); void onThrowable(Throwable t); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index ca6a32bf0..604d770e7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -400,6 +400,15 @@ public void setCharset(String charsetName) { public interface ResponseConverter { + /** + * Implementations of this method should close provided Response in case response is not included in the return + * Object of type <T> Then responsibility to close response is in on the + * {@link com.github.scribejava.core.model.OAuthAsyncRequestCallback#onCompleted(java.lang.Object) } + * + * @param response + * @return T + * @throws IOException + */ T convert(Response response) throws IOException; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java index 7cff61694..553c6cda5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Response.java @@ -20,6 +20,8 @@ public class Response implements Closeable { private final Map headers; private String body; private InputStream stream; + private Closeable[] closeables; + private boolean closed; private Response(int code, String message, Map headers) { this.code = code; @@ -27,9 +29,11 @@ private Response(int code, String message, Map headers) { this.headers = headers; } - public Response(int code, String message, Map headers, InputStream stream) { + public Response(int code, String message, Map headers, InputStream stream, + Closeable... closeables) { this(code, message, headers); this.stream = stream; + this.closeables = closeables; } public Response(int code, String message, Map headers, String body) { @@ -124,8 +128,27 @@ public String toString() { @Override public void close() throws IOException { - if (stream != null) { - stream.close(); + if (closed) { + return; } + IOException ioException = null; + if (closeables != null) { + for (Closeable closeable : closeables) { + if (closeable == null) { + continue; + } + try { + closeable.close(); + } catch (IOException ioE) { + if (ioException != null) { + ioException = ioE; + } + } + } + } + if (ioException != null) { + throw ioException; + } + closed = true; } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index 08295d8c0..89fd279b1 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -61,7 +61,9 @@ public Future getRequestTokenAsync(OAuthAsyncRequestCallback return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override public OAuth1RequestToken convert(Response response) throws IOException { - return getApi().getRequestTokenExtractor().extract(response); + final OAuth1RequestToken token = getApi().getRequestTokenExtractor().extract(response); + response.close(); + return token; } }); } @@ -130,7 +132,9 @@ public Future getAccessTokenAsync(OAuth1RequestToken requestT return execute(request, callback, new OAuthRequest.ResponseConverter() { @Override public OAuth1AccessToken convert(Response response) throws IOException { - return getApi().getAccessTokenExtractor().extract(response); + final OAuth1AccessToken token = getApi().getAccessTokenExtractor().extract(response); + response.close(); + return token; } }); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 43a5d1a9f..b4343d3ad 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -75,7 +75,9 @@ public OAuth2AccessToken convert(Response response) throws IOException { final String body = response.getBody(); log("response body: %s", body); } - return getApi().getAccessTokenExtractor().extract(response); + final OAuth2AccessToken token = getApi().getAccessTokenExtractor().extract(response); + response.close(); + return token; } }); } @@ -445,6 +447,7 @@ public Future revokeToken(String tokenToRevoke, OAuthAsyncRequestCallback< @Override public Void convert(Response response) throws IOException { checkForErrorRevokeToken(response); + response.close(); return null; } }); diff --git a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java index 4494fea2b..7779b83e7 100644 --- a/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-apache/src/main/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandler.java @@ -17,6 +17,7 @@ import com.github.scribejava.core.model.OAuthRequest.ResponseConverter; import com.github.scribejava.core.model.Response; import java.io.IOException; +import java.io.InputStream; import org.apache.http.HttpEntity; public class OAuthAsyncCompletionHandler implements FutureCallback { @@ -44,8 +45,9 @@ public void completed(HttpResponse httpResponse) { final StatusLine statusLine = httpResponse.getStatusLine(); final HttpEntity httpEntity = httpResponse.getEntity(); + final InputStream contentStream = httpEntity == null ? null : httpEntity.getContent(); final Response response = new Response(statusLine.getStatusCode(), statusLine.getReasonPhrase(), headersMap, - httpEntity == null ? null : httpEntity.getContent()); + contentStream, contentStream); @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); diff --git a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandlerTest.java b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandlerTest.java index c43fbed9e..e1a4ddc9c 100644 --- a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandlerTest.java @@ -167,6 +167,7 @@ private static class AllGoodResponseConverter implements OAuthRequest.ResponseCo @Override public String convert(Response response) throws IOException { + response.close(); return "All good"; } } @@ -175,6 +176,7 @@ private static class ExceptionResponseConverter implements OAuthRequest.Response @Override public String convert(Response response) throws IOException { + response.close(); throw new IOException("Failed to convert"); } } @@ -183,6 +185,7 @@ private static class OAuthExceptionResponseConverter implements OAuthRequest.Res @Override public String convert(Response response) throws IOException { + response.close(); throw new OAuthException("bad oauth"); } } diff --git a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandlerTest.java b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandlerTest.java index c235061e9..7bc56e1e1 100644 --- a/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-ning/src/test/java/com/github/scribejava/httpclient/ning/OAuthAsyncCompletionHandlerTest.java @@ -84,6 +84,7 @@ private static class AllGoodResponseConverter implements OAuthRequest.ResponseCo @Override public String convert(Response response) throws IOException { + response.close(); return "All good"; } } @@ -92,6 +93,7 @@ private static class OAuthExceptionResponseConverter implements OAuthRequest.Res @Override public String convert(Response response) throws IOException { + response.close(); throw new OAuthException("bad oauth"); } } diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java index 8345fa9d1..787b70395 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandler.java @@ -38,15 +38,15 @@ public void onResponse(Call call, okhttp3.Response okHttpResponse) { try { final Response response = OkHttpHttpClient.convertResponse(okHttpResponse); - try { + try { @SuppressWarnings("unchecked") final T t = converter == null ? (T) response : converter.convert(response); okHttpFuture.setResult(t); if (callback != null) { callback.onCompleted(t); } - } catch (IOException | RuntimeException e) { - okHttpFuture.setException(e); + } catch (IOException | RuntimeException e) { + okHttpFuture.setException(e); if (callback != null) { callback.onThrowable(e); } diff --git a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java index 67df4b089..f82697db0 100644 --- a/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java +++ b/scribejava-httpclient-okhttp/src/main/java/com/github/scribejava/httpclient/okhttp/OkHttpHttpClient.java @@ -17,6 +17,7 @@ import java.util.concurrent.Future; import com.github.scribejava.core.model.Response; import java.io.File; +import java.io.InputStream; import java.util.HashMap; import java.util.concurrent.ExecutionException; import okhttp3.Cache; @@ -192,8 +193,9 @@ static Response convertResponse(okhttp3.Response okHttpResponse) { } final ResponseBody body = okHttpResponse.body(); - return new Response(okHttpResponse.code(), okHttpResponse.message(), headersMap, - body == null ? null : body.byteStream()); + final InputStream bodyStream = body == null ? null : body.byteStream(); + return new Response(okHttpResponse.code(), okHttpResponse.message(), headersMap, bodyStream, bodyStream, body, + okHttpResponse); } } diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java index 93d3c01f1..6e9f88fe5 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java @@ -179,6 +179,7 @@ private static class AllGoodResponseConverter implements OAuthRequest.ResponseCo @Override public String convert(Response response) throws IOException { + response.close(); return "All good"; } } @@ -187,6 +188,7 @@ private static class ExceptionResponseConverter implements OAuthRequest.Response @Override public String convert(Response response) throws IOException { + response.close(); throw new IOException("Failed to convert"); } } @@ -195,6 +197,7 @@ private static class OAuthExceptionResponseConverter implements OAuthRequest.Res @Override public String convert(Response response) throws IOException { + response.close(); throw new OAuthException("bad oauth"); } } From 43ce7ed67a58882294f78337ce6c267346aa2562 Mon Sep 17 00:00:00 2001 From: Petr Kopotev Date: Thu, 7 May 2020 13:22:17 +0300 Subject: [PATCH 374/481] Add Slack api --- .../com/github/scribejava/apis/SlackApi.java | 39 +++++++ .../apis/slack/SlackJsonTokenExtractor.java | 32 ++++++ .../apis/slack/SlackOAuth2AccessToken.java | 45 ++++++++ .../apis/examples/SlackExample.java | 103 ++++++++++++++++++ 4 files changed, 219 insertions(+) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/SlackApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackJsonTokenExtractor.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackOAuth2AccessToken.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SlackExample.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SlackApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SlackApi.java new file mode 100644 index 000000000..1cfd4436b --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SlackApi.java @@ -0,0 +1,39 @@ +package com.github.scribejava.apis; + +import com.github.scribejava.apis.fitbit.FitBitJsonTokenExtractor; +import com.github.scribejava.apis.slack.SlackJsonTokenExtractor; +import com.github.scribejava.apis.slack.SlackOAuth2AccessToken; +import com.github.scribejava.core.builder.api.DefaultApi20; + +/** + * Slack.com api + */ +public class SlackApi extends DefaultApi20 { + + protected SlackApi() { + } + + private static class InstanceHolder { + + private static final SlackApi INSTANCE = new SlackApi(); + } + + public static SlackApi instance() { + return SlackApi.InstanceHolder.INSTANCE; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://slack.com/api/oauth.v2.access"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://slack.com/oauth/v2/authorize"; + } + + @Override + public SlackJsonTokenExtractor getAccessTokenExtractor() { + return SlackJsonTokenExtractor.instance(); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackJsonTokenExtractor.java new file mode 100644 index 000000000..985cec908 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackJsonTokenExtractor.java @@ -0,0 +1,32 @@ +package com.github.scribejava.apis.slack; + +import com.fasterxml.jackson.databind.JsonNode; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; + +public class SlackJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { + + protected SlackJsonTokenExtractor() { + } + + private static class InstanceHolder { + + private static final SlackJsonTokenExtractor INSTANCE = new SlackJsonTokenExtractor(); + } + + public static SlackJsonTokenExtractor instance() { + return SlackJsonTokenExtractor.InstanceHolder.INSTANCE; + } + + @Override + protected SlackOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, + String refreshToken, String scope, JsonNode response, String rawResponse) { + String userAccessToken = ""; + final JsonNode userAccessTokenNode = response.get("authed_user").get("access_token"); + if (userAccessTokenNode != null) { + userAccessToken = userAccessTokenNode.asText(); + } + + return new SlackOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, + userAccessToken, rawResponse); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackOAuth2AccessToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackOAuth2AccessToken.java new file mode 100644 index 000000000..cc0d7b120 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackOAuth2AccessToken.java @@ -0,0 +1,45 @@ +package com.github.scribejava.apis.slack; + +import com.github.scribejava.core.model.OAuth2AccessToken; + +import java.util.Objects; + +public class SlackOAuth2AccessToken extends OAuth2AccessToken { + + private final String userAccessToken; + + public SlackOAuth2AccessToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, String userAccessToken, String rawResponse) { + super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); + this.userAccessToken = userAccessToken; + } + + public String getUserAccessToken() { + return userAccessToken; + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 37 * hash + Objects.hashCode(userAccessToken); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + if (!super.equals(obj)) { + return false; + } + + return Objects.equals(userAccessToken, ((SlackOAuth2AccessToken) obj).getUserAccessToken()); + } + +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SlackExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SlackExample.java new file mode 100644 index 000000000..eb4be91d9 --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SlackExample.java @@ -0,0 +1,103 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.apis.SlackApi; +import com.github.scribejava.apis.slack.SlackOAuth2AccessToken; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public class SlackExample { + + private static final String NETWORK_NAME = "Slack.com"; + private static final String BOT_RESOURCE_URL = "https://slack.com/api/channels.list"; + private static final String BOT_SCOPE = "channels:read" + private static final String USER_RESOURCE_URL = "https://slack.com/api/users.list"; + private static final String USER_SCOPE = "users:read"; + private static final String PAYLOAD = "null"; + private static final String CONTENT_TYPE_NAME = "Content-Type"; + private static final String CONTENT_TYPE_VALUE = "application/json"; + + private SlackExample() { + } + + @SuppressWarnings("PMD.SystemPrintln") + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "client-id"; + final String clientSecret = "client-secret"; + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .callback("https://www.example.com/oauth_callback/") + .defaultScope(BOT_SCOPE) + .build(SlackApi.instance()); + + final Scanner in = new Scanner(System.in); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + + final Map additionalParams = new HashMap<>(); + // define user scope if any + additionalParams.put("user_scope", USER_SCOPE); + final String authorizationUrl = service.createAuthorizationUrlBuilder() + .additionalParams(additionalParams) + .build(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("Trading the Authorization Code for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + System.out.println("Getting info using BOT token..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, BOT_RESOURCE_URL); + request.addHeader(CONTENT_TYPE_NAME, CONTENT_TYPE_VALUE); + request.setPayload(PAYLOAD); + service.signRequest(accessToken, request); + + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + System.out.println(); + } + + System.out.println("Getting info using USER token..."); + final OAuthRequest userRequest = new OAuthRequest(Verb.GET, USER_RESOURCE_URL); + userRequest.addHeader(CONTENT_TYPE_NAME, CONTENT_TYPE_VALUE); + userRequest.setPayload(PAYLOAD); + SlackOAuth2AccessToken token = (SlackOAuth2AccessToken)accessToken; + service.signRequest(token.getUserAccessToken(), userRequest); + + try (Response response = service.execute(userRequest)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } + + + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + } +} From fdef16c0a278711491fb87d50bae0e66ca61a102 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Mon, 11 May 2020 15:05:49 +0300 Subject: [PATCH 375/481] update deps --- pom.xml | 10 +++++----- .../core/model/OAuthAsyncRequestCallback.java | 2 +- .../com/github/scribejava/core/model/OAuthRequest.java | 4 ++-- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index a7a764942..e62db482f 100644 --- a/pom.xml +++ b/pom.xml @@ -56,7 +56,7 @@ com.fasterxml.jackson.core jackson-databind - 2.10.3 + 2.11.0 junit @@ -67,7 +67,7 @@ com.squareup.okhttp3 mockwebserver - 4.4.1 + 4.6.0 test @@ -106,7 +106,7 @@ com.puppycrawl.tools checkstyle - 8.30 + 8.32 @@ -187,7 +187,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.1.1 + 3.2.0 ${java.home}/bin/javadoc UTF-8 @@ -273,7 +273,7 @@ 7 - 6.22.0 + 6.23.0 diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthAsyncRequestCallback.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthAsyncRequestCallback.java index 466dd98ee..7719314d2 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthAsyncRequestCallback.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthAsyncRequestCallback.java @@ -5,7 +5,7 @@ public interface OAuthAsyncRequestCallback { /** * Implementations of this method should close provided response in case it implements {@link java.io.Closeable} * - * @param response + * @param response response */ void onCompleted(T response); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index 604d770e7..79c66695f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -405,9 +405,9 @@ public interface ResponseConverter { * Object of type <T> Then responsibility to close response is in on the * {@link com.github.scribejava.core.model.OAuthAsyncRequestCallback#onCompleted(java.lang.Object) } * - * @param response + * @param response response * @return T - * @throws IOException + * @throws IOException IOException */ T convert(Response response) throws IOException; } diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 51553b620..fa0ce5dc5 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.11.0 + 2.12.1 com.github.scribejava diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 33b6da071..ea231de3a 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 4.4.1 + 4.6.0 com.github.scribejava From 7f3a902e224a8e02470b7095beebcd46c3a6bf7a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 29 Jul 2020 17:54:48 +0300 Subject: [PATCH 376/481] fix url encoding in POST payload, it wasn't needed (thanks to https://github.com/max904-github) --- changelog | 1 + .../scribejava/core/model/OAuthRequest.java | 2 +- .../scribejava/core/model/Parameter.java | 4 + .../scribejava/core/model/ParameterList.java | 12 ++ .../scribejava/core/AbstractClientTest.java | 151 +++++++++++++++++- .../scribejava/core/model/RequestTest.java | 3 +- 6 files changed, 162 insertions(+), 11 deletions(-) diff --git a/changelog b/changelog index 8a117fae5..a249f11af 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) * make Response accept resources to autoclose and autoclose it (thanks to https://github.com/drei01) + * fix url encoding in POST payload, it wasn't needed (thanks to https://github.com/max904-github) [6.9.0] * Add Xero API (https://www.xero.com/) (thanks to https://github.com/SidneyAllen) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index 79c66695f..d8511296b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -360,7 +360,7 @@ public byte[] getByteArrayPayload() { if (byteArrayPayload != null) { return byteArrayPayload; } - final String body = bodyParams.asFormUrlEncodedString(); + final String body = bodyParams.asString(); try { return body.getBytes(getCharset()); } catch (UnsupportedEncodingException uee) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java index 9397cb773..962992c46 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java @@ -16,6 +16,10 @@ public String asUrlEncodedPair() { return OAuthEncoder.encode(key).concat("=").concat(OAuthEncoder.encode(value)); } + public String asPair() { + return key + '=' + value; + } + @Override public boolean equals(Object other) { if (other == null) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java index 39d806652..c8b2c04a2 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java @@ -65,6 +65,18 @@ public String asFormUrlEncodedString() { return builder.substring(1); } + public String asString() { + if (params.isEmpty()) { + return EMPTY_STRING; + } + + final StringBuilder builder = new StringBuilder(); + for (Parameter p : params) { + builder.append(PARAM_SEPARATOR).append(p.asPair()); + } + return builder.substring(1); + } + public void addAll(ParameterList other) { params.addAll(other.getParams()); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java index 8fe6bb20e..5bd62e9d5 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java @@ -78,37 +78,172 @@ public void shouldSendGetRequest() throws Exception { } @Test - public void shouldSendPostRequest() throws Exception { + public void shouldSendPostRequestWithEmptyBody() throws Exception { + final String expectedResponseBody = "response body for test shouldSendPostRequest"; + final String expectedRequestBody = ""; + + final MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); + try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { + assertEquals(expectedResponseBody, response.getBody()); + } + + final RecordedRequest recordedRequest = server.takeRequest(); + assertEquals("POST", recordedRequest.getMethod()); + assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + + server.shutdown(); + } + + @Test + public void shouldSendPostRequestWithStringBody() throws Exception { final String expectedResponseBody = "response body for test shouldSendPostRequest"; final String expectedRequestBody = "request body"; final MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); + request.setPayload(expectedRequestBody); + try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { + assertEquals(expectedResponseBody, response.getBody()); + } + + final RecordedRequest recordedRequest = server.takeRequest(); + assertEquals("POST", recordedRequest.getMethod()); + assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + + server.shutdown(); + } + + @Test + public void shouldSendPostRequestWithStringBodyWithSpecialChars() throws Exception { + final String expectedResponseBody = "response body for test shouldSendPostRequest"; + final String expectedRequestBody = "~/!@#$%^&*()_+//\r\n%2F&"; + + final MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setBody(expectedResponseBody)); server.start(); final HttpUrl baseUrl = server.url("/testUrl"); - // request with body - OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); + final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); request.setPayload(expectedRequestBody); try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { assertEquals(expectedResponseBody, response.getBody()); } - RecordedRequest recordedRequest = server.takeRequest(); + final RecordedRequest recordedRequest = server.takeRequest(); + assertEquals("POST", recordedRequest.getMethod()); + assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + + server.shutdown(); + } + + @Test + public void shouldSendPostRequestWithByteBodyBody() throws Exception { + final String expectedResponseBody = "response body for test shouldSendPostRequest"; + final String expectedRequestBody = "request body"; + + final MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); + request.setPayload(expectedRequestBody.getBytes()); + try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { + assertEquals(expectedResponseBody, response.getBody()); + } + + final RecordedRequest recordedRequest = server.takeRequest(); + assertEquals("POST", recordedRequest.getMethod()); + assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + + server.shutdown(); + } + + @Test + public void shouldSendPostRequestWithByteBodyWithSpecialChars() throws Exception { + final String expectedResponseBody = "response body for test shouldSendPostRequest"; + final String expectedRequestBody = "~/!@#$%^&*()_+//\r\n%2F&"; + + final MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); + request.setPayload(expectedRequestBody.getBytes()); + try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { + assertEquals(expectedResponseBody, response.getBody()); + } + + final RecordedRequest recordedRequest = server.takeRequest(); + assertEquals("POST", recordedRequest.getMethod()); + assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + + server.shutdown(); + } + + @Test + public void shouldSendPostRequestWithBodyParamsBody() throws Exception { + final String expectedResponseBody = "response body for test shouldSendPostRequest"; + final String expectedRequestBodyParamName = "request body param name"; + final String expectedRequestBodyParamValue = "request body param value"; + final String expectedRequestBody = expectedRequestBodyParamName + '=' + expectedRequestBodyParamValue; + + final MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); + request.addBodyParameter(expectedRequestBodyParamName, expectedRequestBodyParamValue); + try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { + assertEquals(expectedResponseBody, response.getBody()); + } + + final RecordedRequest recordedRequest = server.takeRequest(); assertEquals("POST", recordedRequest.getMethod()); assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); - // request with empty body - request = new OAuthRequest(Verb.POST, baseUrl.toString()); + server.shutdown(); + } + + @Test + public void shouldSendPostRequestWithBodyParamsBodyWithSpecialChars() throws Exception { + final String expectedResponseBody = "response body for test shouldSendPostRequest"; + final String expectedRequestBodyParamName = "~/!@#$%^&*()_+//\r\n%2F&name"; + final String expectedRequestBodyParamValue = "~/!@#$%^&*()_+//\r\n%2F&value"; + final String expectedRequestBody = expectedRequestBodyParamName + '=' + expectedRequestBodyParamValue; + + final MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.start(); + + final HttpUrl baseUrl = server.url("/testUrl"); + + final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); + request.addBodyParameter(expectedRequestBodyParamName, expectedRequestBodyParamValue); try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { assertEquals(expectedResponseBody, response.getBody()); } - recordedRequest = server.takeRequest(); + final RecordedRequest recordedRequest = server.takeRequest(); assertEquals("POST", recordedRequest.getMethod()); - assertEquals("", recordedRequest.getBody().readUtf8()); + assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); server.shutdown(); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java index 274ccca23..d0c870dac 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java @@ -29,8 +29,7 @@ public void shouldGetQueryStringParameters() { @Test public void shouldSetBodyParamsAndAddContentLength() { - assertEquals("param=value¶m%20with%20spaces=value%20with%20spaces", - new String(postRequest.getByteArrayPayload())); + assertEquals("param=value¶m with spaces=value with spaces", new String(postRequest.getByteArrayPayload())); } @Test From 8b8691940822230a57dff13171bc5fe2a7ad41e8 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Wed, 29 Jul 2020 18:05:58 +0300 Subject: [PATCH 377/481] update deps --- pom.xml | 15 ++++++--------- scribejava-httpclient-okhttp/pom.xml | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index e62db482f..2b6955ad0 100644 --- a/pom.xml +++ b/pom.xml @@ -40,15 +40,12 @@ kullfar - Stas Gromov + Stanislav Gromov kullfar@gmail.com all +3 - - +7-909-677-11-16 - @@ -56,7 +53,7 @@ com.fasterxml.jackson.core jackson-databind - 2.11.0 + 2.11.1 junit @@ -67,7 +64,7 @@ com.squareup.okhttp3 mockwebserver - 4.6.0 + 4.8.0 test @@ -77,7 +74,7 @@ org.apache.felix maven-bundle-plugin - 4.2.1 + 5.1.1 bundle-manifest @@ -106,7 +103,7 @@ com.puppycrawl.tools checkstyle - 8.32 + 8.35 @@ -273,7 +270,7 @@ 7 - 6.23.0 + 6.26.0 diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index ea231de3a..cf5ac1998 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 4.6.0 + 4.8.0 com.github.scribejava From 68a73ace2954026d4e0a3789872cdbfd4336da4c Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Sat, 1 Aug 2020 09:53:55 +0300 Subject: [PATCH 378/481] really fix url encoding in POST payload, it was needed for 'application/x-www-form-urlencoded' Content-Type + unit tests (thanks to https://github.com/max904-github) --- changelog | 3 +- .../github/scribejava/apis/SalesforceApi.java | 8 +- .../scribejava/core/model/OAuthRequest.java | 2 +- .../scribejava/core/model/Parameter.java | 4 - .../scribejava/core/model/ParameterList.java | 12 --- .../scribejava/core/AbstractClientTest.java | 84 ++++--------------- .../scribejava/core/model/RequestTest.java | 66 +++++++++++---- 7 files changed, 77 insertions(+), 102 deletions(-) diff --git a/changelog b/changelog index a249f11af..953ac5d16 100644 --- a/changelog +++ b/changelog @@ -1,7 +1,8 @@ [SNAPSHOT] * Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) * make Response accept resources to autoclose and autoclose it (thanks to https://github.com/drei01) - * fix url encoding in POST payload, it wasn't needed (thanks to https://github.com/max904-github) + * fix url encoding in POST payload (it's needed for 'application/x-www-form-urlencoded' Content-Type) + + unit tests (thanks to https://github.com/max904-github) [6.9.0] * Add Xero API (https://www.xero.com/) (thanks to https://github.com/SidneyAllen) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java index 57cdd32ac..8760a7fff 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SalesforceApi.java @@ -17,10 +17,9 @@ /** * This class is an implementation of the Salesforce OAuth2 API. - * The default implementation connects to the Salesforce - * production environment. - * If you want to connect to a Sandbox environment you've to use {@link #sandbox()} method to - * get sandbox instance of this API + * + * The default implementation connects to the Salesforce production environment. If you want to connect to a Sandbox + * environment you've to use {@link #sandbox()} method to get sandbox instance of this API */ public class SalesforceApi extends DefaultApi20 { @@ -52,6 +51,7 @@ protected SalesforceApi(String hostName) { } private static class InstanceHolder { + private static final SalesforceApi INSTANCE = new SalesforceApi(PRODUCTION_HOST); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index d8511296b..79c66695f 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -360,7 +360,7 @@ public byte[] getByteArrayPayload() { if (byteArrayPayload != null) { return byteArrayPayload; } - final String body = bodyParams.asString(); + final String body = bodyParams.asFormUrlEncodedString(); try { return body.getBytes(getCharset()); } catch (UnsupportedEncodingException uee) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java index 962992c46..9397cb773 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java @@ -16,10 +16,6 @@ public String asUrlEncodedPair() { return OAuthEncoder.encode(key).concat("=").concat(OAuthEncoder.encode(value)); } - public String asPair() { - return key + '=' + value; - } - @Override public boolean equals(Object other) { if (other == null) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java index c8b2c04a2..39d806652 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/ParameterList.java @@ -65,18 +65,6 @@ public String asFormUrlEncodedString() { return builder.substring(1); } - public String asString() { - if (params.isEmpty()) { - return EMPTY_STRING; - } - - final StringBuilder builder = new StringBuilder(); - for (Parameter p : params) { - builder.append(PARAM_SEPARATOR).append(p.asPair()); - } - return builder.substring(1); - } - public void addAll(ParameterList other) { params.addAll(other.getParams()); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java index 5bd62e9d5..c1bc1967e 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/AbstractClientTest.java @@ -19,6 +19,8 @@ import java.util.concurrent.TimeUnit; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNotNull; public abstract class AbstractClientTest { @@ -78,32 +80,27 @@ public void shouldSendGetRequest() throws Exception { } @Test - public void shouldSendPostRequestWithEmptyBody() throws Exception { - final String expectedResponseBody = "response body for test shouldSendPostRequest"; - final String expectedRequestBody = ""; - + public void shouldSendPostWithApplicationXWwwFormUrlencodedRequestContentTypeHeader() throws Exception { final MockWebServer server = new MockWebServer(); - server.enqueue(new MockResponse().setBody(expectedResponseBody)); + server.enqueue(new MockResponse()); server.start(); final HttpUrl baseUrl = server.url("/testUrl"); final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); - try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { - assertEquals(expectedResponseBody, response.getBody()); - } + oAuthService.execute(request, null).get(30, TimeUnit.SECONDS).close(); final RecordedRequest recordedRequest = server.takeRequest(); assertEquals("POST", recordedRequest.getMethod()); - assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + assertEquals(HttpClient.DEFAULT_CONTENT_TYPE, recordedRequest.getHeader(HttpClient.CONTENT_TYPE)); server.shutdown(); } @Test - public void shouldSendPostRequestWithStringBody() throws Exception { + public void shouldSendPostRequestWithEmptyBody() throws Exception { final String expectedResponseBody = "response body for test shouldSendPostRequest"; - final String expectedRequestBody = "request body"; + final String expectedRequestBody = ""; final MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setBody(expectedResponseBody)); @@ -112,7 +109,6 @@ public void shouldSendPostRequestWithStringBody() throws Exception { final HttpUrl baseUrl = server.url("/testUrl"); final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); - request.setPayload(expectedRequestBody); try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { assertEquals(expectedResponseBody, response.getBody()); } @@ -120,14 +116,15 @@ public void shouldSendPostRequestWithStringBody() throws Exception { final RecordedRequest recordedRequest = server.takeRequest(); assertEquals("POST", recordedRequest.getMethod()); assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + assertEquals(HttpClient.DEFAULT_CONTENT_TYPE, recordedRequest.getHeader(HttpClient.CONTENT_TYPE)); server.shutdown(); } @Test - public void shouldSendPostRequestWithStringBodyWithSpecialChars() throws Exception { + public void shouldSendPostRequestWithStringBody() throws Exception { final String expectedResponseBody = "response body for test shouldSendPostRequest"; - final String expectedRequestBody = "~/!@#$%^&*()_+//\r\n%2F&"; + final String expectedRequestBody = "request body"; final MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setBody(expectedResponseBody)); @@ -144,6 +141,9 @@ public void shouldSendPostRequestWithStringBodyWithSpecialChars() throws Excepti final RecordedRequest recordedRequest = server.takeRequest(); assertEquals("POST", recordedRequest.getMethod()); assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + final String contentTypeHeader = recordedRequest.getHeader(HttpClient.CONTENT_TYPE); + assertNotNull(contentTypeHeader); + assertTrue(contentTypeHeader.startsWith(HttpClient.DEFAULT_CONTENT_TYPE)); server.shutdown(); } @@ -168,30 +168,7 @@ public void shouldSendPostRequestWithByteBodyBody() throws Exception { final RecordedRequest recordedRequest = server.takeRequest(); assertEquals("POST", recordedRequest.getMethod()); assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); - - server.shutdown(); - } - - @Test - public void shouldSendPostRequestWithByteBodyWithSpecialChars() throws Exception { - final String expectedResponseBody = "response body for test shouldSendPostRequest"; - final String expectedRequestBody = "~/!@#$%^&*()_+//\r\n%2F&"; - - final MockWebServer server = new MockWebServer(); - server.enqueue(new MockResponse().setBody(expectedResponseBody)); - server.start(); - - final HttpUrl baseUrl = server.url("/testUrl"); - - final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); - request.setPayload(expectedRequestBody.getBytes()); - try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { - assertEquals(expectedResponseBody, response.getBody()); - } - - final RecordedRequest recordedRequest = server.takeRequest(); - assertEquals("POST", recordedRequest.getMethod()); - assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + assertEquals(HttpClient.DEFAULT_CONTENT_TYPE, recordedRequest.getHeader(HttpClient.CONTENT_TYPE)); server.shutdown(); } @@ -199,34 +176,8 @@ public void shouldSendPostRequestWithByteBodyWithSpecialChars() throws Exception @Test public void shouldSendPostRequestWithBodyParamsBody() throws Exception { final String expectedResponseBody = "response body for test shouldSendPostRequest"; - final String expectedRequestBodyParamName = "request body param name"; - final String expectedRequestBodyParamValue = "request body param value"; - final String expectedRequestBody = expectedRequestBodyParamName + '=' + expectedRequestBodyParamValue; - - final MockWebServer server = new MockWebServer(); - server.enqueue(new MockResponse().setBody(expectedResponseBody)); - server.start(); - - final HttpUrl baseUrl = server.url("/testUrl"); - - final OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString()); - request.addBodyParameter(expectedRequestBodyParamName, expectedRequestBodyParamValue); - try (Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS)) { - assertEquals(expectedResponseBody, response.getBody()); - } - - final RecordedRequest recordedRequest = server.takeRequest(); - assertEquals("POST", recordedRequest.getMethod()); - assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); - - server.shutdown(); - } - - @Test - public void shouldSendPostRequestWithBodyParamsBodyWithSpecialChars() throws Exception { - final String expectedResponseBody = "response body for test shouldSendPostRequest"; - final String expectedRequestBodyParamName = "~/!@#$%^&*()_+//\r\n%2F&name"; - final String expectedRequestBodyParamValue = "~/!@#$%^&*()_+//\r\n%2F&value"; + final String expectedRequestBodyParamName = "request_body_param_name"; + final String expectedRequestBodyParamValue = "request_body_param_value"; final String expectedRequestBody = expectedRequestBodyParamName + '=' + expectedRequestBodyParamValue; final MockWebServer server = new MockWebServer(); @@ -244,6 +195,7 @@ public void shouldSendPostRequestWithBodyParamsBodyWithSpecialChars() throws Exc final RecordedRequest recordedRequest = server.takeRequest(); assertEquals("POST", recordedRequest.getMethod()); assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8()); + assertEquals(HttpClient.DEFAULT_CONTENT_TYPE, recordedRequest.getHeader(HttpClient.CONTENT_TYPE)); server.shutdown(); } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java index d0c870dac..87189632b 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/RequestTest.java @@ -1,27 +1,21 @@ package com.github.scribejava.core.model; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import org.junit.Before; import org.junit.Test; -import java.net.MalformedURLException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; public class RequestTest { - private OAuthRequest getRequest; - private OAuthRequest postRequest; - - @Before - public void setUp() throws MalformedURLException { - postRequest = new OAuthRequest(Verb.POST, "http://example.com"); + @Test + public void shouldGetQueryStringParameters() { + final OAuthRequest postRequest = new OAuthRequest(Verb.POST, "http://example.com"); postRequest.addBodyParameter("param", "value"); postRequest.addBodyParameter("param with spaces", "value with spaces"); - getRequest = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces"); - } + final OAuthRequest getRequest + = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces"); - @Test - public void shouldGetQueryStringParameters() { assertEquals(2, getRequest.getQueryStringParams().size()); assertEquals(0, postRequest.getQueryStringParams().size()); assertTrue(getRequest.getQueryStringParams().contains(new Parameter("qsparam", "value"))); @@ -29,12 +23,21 @@ public void shouldGetQueryStringParameters() { @Test public void shouldSetBodyParamsAndAddContentLength() { - assertEquals("param=value¶m with spaces=value with spaces", new String(postRequest.getByteArrayPayload())); + final OAuthRequest postRequest = new OAuthRequest(Verb.POST, "http://example.com"); + postRequest.addBodyParameter("param", "value"); + postRequest.addBodyParameter("param with spaces", "value with spaces"); + + assertEquals("param=value¶m%20with%20spaces=value%20with%20spaces", + new String(postRequest.getByteArrayPayload())); } @Test public void shouldSetPayloadAndHeaders() { + final OAuthRequest postRequest = new OAuthRequest(Verb.POST, "http://example.com"); + postRequest.addBodyParameter("param", "value"); + postRequest.addBodyParameter("param with spaces", "value with spaces"); postRequest.setPayload("PAYLOAD"); + assertEquals("PAYLOAD", postRequest.getStringPayload()); } @@ -56,6 +59,41 @@ public void shouldReturnTheCompleteUrl() { @Test public void shouldHandleQueryStringSpaceEncodingProperly() { + final OAuthRequest getRequest + = new OAuthRequest(Verb.GET, "http://example.com?qsparam=value&other+param=value+with+spaces"); + assertTrue(getRequest.getQueryStringParams().contains(new Parameter("other param", "value with spaces"))); } + + @Test + public void shouldNotEncodeInStringPayload() throws Exception { + final String requestBody = "~/!@#$%^&*( )_+//\r\n%2F&"; + + final OAuthRequest postRequest = new OAuthRequest(Verb.POST, "http://example.com"); + postRequest.setPayload(requestBody); + + assertEquals(requestBody, postRequest.getStringPayload()); + } + + @Test + public void shouldNotEncodeInByteBodyPayload() throws Exception { + final byte[] requestBody = "~/!@#$%^&*( )_+//\r\n%2F&".getBytes(); + + final OAuthRequest postRequest = new OAuthRequest(Verb.POST, "http://example.com"); + postRequest.setPayload(requestBody); + + assertArrayEquals(requestBody, postRequest.getByteArrayPayload()); + } + + @Test + public void shouldEncodeInBodyParamsPayload() throws Exception { + final String expectedRequestBodyParamName = "~/!@#$%^&*( )_+//\r\n%2F&name"; + final String expectedRequestBodyParamValue = "~/!@#$%^&*( )_+//\r\n%2F&value"; + final String expectedRequestBody = "~%2F%21%40%23%24%25%5E%26%2A%28%20%29_%2B%2F%2F%0D%0A%252F%26amp%3Bname=" + + "~%2F%21%40%23%24%25%5E%26%2A%28%20%29_%2B%2F%2F%0D%0A%252F%26amp%3Bvalue"; + + final OAuthRequest postRequest = new OAuthRequest(Verb.POST, "http://example.com"); + postRequest.addBodyParameter(expectedRequestBodyParamName, expectedRequestBodyParamValue); + assertArrayEquals(expectedRequestBody.getBytes(), postRequest.getByteArrayPayload()); + } } From dfbf50dd63898c60ac9fa54725cf4408442b3c18 Mon Sep 17 00:00:00 2001 From: max904 Date: Wed, 8 Jan 2020 15:31:57 +0100 Subject: [PATCH 379/481] Implemented Armeria-based http client binding for ScribeJava. Armeria (https://github.com/line/armeria/) is an open-source asynchronous HTTP/2/1 client/server library built on top of Netty and Java 8. Java 8 required to build this http client module. --- pom.xml | 1 + scribejava-httpclient-armeria/pom.xml | 69 +++ .../httpclient/multipart/MultipartUtils.java | 53 +++ .../httpclient/armeria/ArmeriaHttpClient.java | 440 ++++++++++++++++++ .../armeria/ArmeriaHttpClientConfig.java | 104 +++++ .../httpclient/armeria/ArmeriaProvider.java | 16 + ...ibejava.core.httpclient.HttpClientProvider | 1 + .../armeria/ArmeriaHttpClientTest.java | 69 +++ .../test/resources/simplelogger.properties | 29 ++ 9 files changed, 782 insertions(+) create mode 100644 scribejava-httpclient-armeria/pom.xml create mode 100644 scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java create mode 100644 scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java create mode 100644 scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java create mode 100644 scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaProvider.java create mode 100644 scribejava-httpclient-armeria/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider create mode 100644 scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java create mode 100644 scribejava-httpclient-armeria/src/test/resources/simplelogger.properties diff --git a/pom.xml b/pom.xml index 2b6955ad0..a5119ada7 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,7 @@ scribejava-httpclient-ning scribejava-httpclient-okhttp scribejava-httpclient-apache + scribejava-httpclient-armeria diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml new file mode 100644 index 000000000..e11a41915 --- /dev/null +++ b/scribejava-httpclient-armeria/pom.xml @@ -0,0 +1,69 @@ + + + 4.0.0 + + + com.github.scribejava + scribejava + 6.9.1-SNAPSHOT + ../pom.xml + + + scribejava-httpclient-armeria + ScribeJava Async Armeria Client support + jar + + + + com.github.scribejava + scribejava-core + ${project.version} + + + com.linecorp.armeria + armeria + 0.97.0 + + + com.github.scribejava + scribejava-core + ${project.version} + test-jar + test + + + io.netty + netty-all + 4.1.43.Final + test + + + org.slf4j + slf4j-simple + 1.7.30 + test + + + + + + + maven-compiler-plugin + 3.8.1 + + UTF-8 + 8 + true + + + + org.apache.felix + maven-bundle-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + + diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java new file mode 100644 index 000000000..bbbbad078 --- /dev/null +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java @@ -0,0 +1,53 @@ +package com.github.scribejava.core.httpclient.multipart; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.List; +import java.util.Map; + +public abstract class MultipartUtils { + + // copied from com.github.scribejava.core.httpclient.jdk.JDKHttpClient#getPayload + public static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload) throws IOException { + final ByteArrayOutputStream os = new ByteArrayOutputStream(); + + final String preamble = multipartPayload.getPreamble(); + if (preamble != null) { + os.write(preamble.getBytes()); + } + final List bodyParts = multipartPayload.getBodyParts(); + if (!bodyParts.isEmpty()) { + final String boundary = multipartPayload.getBoundary(); + final byte[] startBoundary = ("\r\n--" + boundary + "\r\n").getBytes(); + + for (BodyPartPayload bodyPart : bodyParts) { + os.write(startBoundary); + + final Map bodyPartHeaders = bodyPart.getHeaders(); + if (bodyPartHeaders != null) { + for (Map.Entry header : bodyPartHeaders.entrySet()) { + os.write((header.getKey() + ": " + header.getValue() + "\r\n").getBytes()); + } + } + + if (bodyPart instanceof MultipartPayload) { + getPayload((MultipartPayload) bodyPart).writeTo(os); + } else if (bodyPart instanceof ByteArrayBodyPartPayload) { + os.write("\r\n".getBytes()); + os.write(((ByteArrayBodyPartPayload) bodyPart).getPayload()); + } else { + throw new AssertionError(bodyPart.getClass()); + } + } + + os.write(("\r\n--" + boundary + "--\r\n").getBytes()); + final String epilogue = multipartPayload.getEpilogue(); + if (epilogue != null) { + os.write((epilogue + "\r\n").getBytes()); + } + + } + return os; + } + +} diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java new file mode 100644 index 000000000..d3b8a6359 --- /dev/null +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java @@ -0,0 +1,440 @@ +package com.github.scribejava.httpclient.armeria; + +import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.httpclient.multipart.MultipartPayload; +import com.github.scribejava.core.httpclient.multipart.MultipartUtils; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.linecorp.armeria.client.ClientFactory; +import com.linecorp.armeria.client.ClientFactoryBuilder; +import com.linecorp.armeria.client.ClientFactoryOptionValue; +import com.linecorp.armeria.client.ClientOptions; +import com.linecorp.armeria.client.Endpoint; +import com.linecorp.armeria.client.WebClient; +import com.linecorp.armeria.client.WebClientBuilder; +import com.linecorp.armeria.client.logging.LoggingClient; +import com.linecorp.armeria.common.AggregatedHttpResponse; +import com.linecorp.armeria.common.HttpData; +import com.linecorp.armeria.common.HttpMethod; +import com.linecorp.armeria.common.HttpResponse; +import com.linecorp.armeria.common.RequestHeaders; +import com.linecorp.armeria.common.RequestHeadersBuilder; +import com.linecorp.armeria.common.SessionProtocol; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.nio.file.Files; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Future; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import java.util.function.Supplier; + +public class ArmeriaHttpClient extends AbstractAsyncOnlyHttpClient { + + private final ArmeriaHttpClientConfig config; + private final Map httpClients = new HashMap<>(); + private final ReentrantReadWriteLock httpClientsLock = new ReentrantReadWriteLock(); + + public ArmeriaHttpClient() { + this(ArmeriaHttpClientConfig.defaultConfig()); + } + + public ArmeriaHttpClient(ArmeriaHttpClientConfig config) { + this.config = config; + } + + public HttpClientConfig getConfig() { + return config; + } + + /** + * Cleans up HTTP clients collection. + */ + @Override + public void close() { + final Lock writeLock = httpClientsLock.writeLock(); + writeLock.lock(); + try { + httpClients.clear(); + } finally { + writeLock.unlock(); + } + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + new BytesBody(bodyContents), callback, converter); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + new MultipartBody(bodyContents), callback, converter); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + new StringBody(bodyContents), callback, converter); + } + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, File bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + new FileBody(bodyContents), callback, converter); + } + + private CompletableFuture doExecuteAsync(String userAgent, + Map headers, Verb httpVerb, + String completeUrl, Supplier contentSupplier, + OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + // Get the URI and Path + final URI uri = URI.create(completeUrl); + final String path = getServicePath(uri); + + // Fetch/Create WebClient instance for a given Endpoint + final WebClient client = getHttpClient(uri); + + // Build HTTP request + final RequestHeadersBuilder headersBuilder = + RequestHeaders.of(getHttpMethod(httpVerb), path).toBuilder(); + headersBuilder.add(headers.entrySet()); + if (userAgent != null) { + headersBuilder.add(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); + } + + // Build the request body and execute HTTP request + final HttpResponse response; + if (httpVerb.isPermitBody()) { // POST, PUT, PATCH and DELETE methods + final HttpData contents = contentSupplier.get(); + if (httpVerb.isRequiresBody() && contents == null) { // POST or PUT methods + throw new IllegalArgumentException( + "Contents missing for request method " + httpVerb.name()); + } + if (contents != null) { + response = client.execute(headersBuilder.build(), contents); + } else { + response = client.execute(headersBuilder.build()); + } + } else { + response = client.execute(headersBuilder.build()); + } + + // Aggregate HTTP response (asynchronously) and return the result Future + return response.aggregate() + .thenApply(r -> whenResponseComplete(callback, converter, r)) + .exceptionally(e -> completeExceptionally(callback, e)); + } + + //------------------------------------------------------------------------------------------------ + + /** + * Extracts Protocol + Host + Port part from a given endpoint {@link URI} + * @param uri an endpoint {@link URI} + * @return a portion of {@link URI} including a combination of Protocol + Host + Port + * @see #getHttpClient(URI uri) + */ + private String getHostUri(final URI uri) { + final StringBuilder builder = new StringBuilder(); + builder.append(uri.getScheme()).append("://").append(uri.getHost()); + final int port = uri.getPort(); + if (port > 0) { + builder.append(":").append(port); + } + return builder.toString(); + } + + /** + * Extracts service path from a given endpoint {@link URI} + * @param uri an endpoint {@link URI} + * @return service path portion of the {@link URI} + */ + private static String getServicePath(final URI uri) { + final StringBuilder builder = new StringBuilder(); + final String path = uri.getRawPath(); + if (path != null && path.length() > 0) { + builder.append(path); + } else { + builder.append("/"); + } + final String query = uri.getRawQuery(); + if (query != null && query.length() > 0) { + builder.append("?").append(query); + } + return builder.toString(); + } + + /** + * Provides and instance of {@link WebClient} for a given endpoint {@link URI} based on + * a combination of Protocol + Host + Port. + * @param uri an endpoint {@link URI} + * @return {@link WebClient} instance + */ + private WebClient getHttpClient(final URI uri) { + final String hostUri = getHostUri(uri); + + WebClient client; + final Lock readLock = httpClientsLock.readLock(); + readLock.lock(); + try { + client = httpClients.get(hostUri); + } finally { + readLock.unlock(); + } + + if (client != null) { + return client; + } + + client = buildNewHttpClient(uri); + + final Lock writeLock = httpClientsLock.writeLock(); + writeLock.lock(); + try { + if (!httpClients.containsKey(hostUri)) { + httpClients.put(hostUri, client); + return client; + } else { + return httpClients.get(hostUri); + } + } finally { + writeLock.unlock(); + } + } + + /** + * Builds a brand-new instance of {@link WebClient} for a given endpoint {@link URI}. + * Uses {@link ArmeriaHttpClientConfig} to configure the builder and the client. + * @param uri an endpoint {@link URI} + * @return Brand-new {@link WebClient} instance + */ + private WebClient buildNewHttpClient(final URI uri) { + // Build the client and the headers + WebClientBuilder clientBuilder = + getHttpClientBuilder(uri, config.getSessionProtocolPreference()); + + final ClientOptions clientOptions = config.getClientOptions(); + if (clientOptions != null) { + clientBuilder.options(clientOptions); + } + + final ClientFactoryBuilder clientFactoryBuilder = ClientFactory.builder(); + final Collection> clientFactoryOptions = config.getClientFactoryOptions(); + if (clientFactoryOptions != null && !clientFactoryOptions.isEmpty()) { + clientFactoryOptions.forEach(clientFactoryBuilder::option); + } + clientBuilder.factory(clientFactoryBuilder.build()); + + if (config.isLogging()) { + clientBuilder = clientBuilder.decorator(LoggingClient.newDecorator()); + } + + return clientBuilder.build(); + } + + /** + * Provides an instance of {@link WebClientBuilder} for a given endpoint {@link URI} + * @param uri an endpoint {@link URI} + * @param protocolPreference an HTTP protocol generation preference; acceptable values: "h1" or "h2". + * @return {@link WebClientBuilder} instance to build a new {@link WebClient} + */ + private WebClientBuilder getHttpClientBuilder(final URI uri, final SessionProtocol protocolPreference) { + final SessionProtocol sessionProtocol = SessionProtocol.of(uri.getScheme()); + final String host = uri.getHost(); + final int port = uri.getPort(); + final Endpoint endpoint = (port > 0) ? Endpoint.of(host, port) : Endpoint.of(host); + switch(sessionProtocol) { + case HTTP: + if (protocolPreference == SessionProtocol.H1) { + // enforce HTTP/1 protocol + return WebClient.builder(SessionProtocol.H1C, endpoint); + } + break; + case HTTPS: + if (protocolPreference == SessionProtocol.H1) { + // enforce HTTP/1 protocol + return WebClient.builder(SessionProtocol.H1, endpoint); + } + break; + default: + break; + } + return WebClient.builder(sessionProtocol, endpoint); + } + + /** + * Maps {@link Verb} to {@link HttpMethod} + * @param httpVerb a {@link Verb} to match with {@link HttpMethod} + * @return {@link HttpMethod} corresponding to the parameter + */ + private HttpMethod getHttpMethod(final Verb httpVerb) { + switch (httpVerb) { + case GET: + return HttpMethod.GET; + case POST: + return HttpMethod.POST; + case PUT: + return HttpMethod.PUT; + case DELETE: + return HttpMethod.DELETE; + case HEAD: + return HttpMethod.HEAD; + case OPTIONS: + return HttpMethod.OPTIONS; + case TRACE: + return HttpMethod.TRACE; + case PATCH: + return HttpMethod.PATCH; + default: + throw new IllegalArgumentException( + "message build error: unsupported HTTP method: " + httpVerb.name()); + } + } + + //------------------------------------------------------------------------------------------------ + // Response asynchronous handlers + + /** + * Converts {@link AggregatedHttpResponse} to {@link Response} + * @param aggregatedResponse an instance of {@link AggregatedHttpResponse} to convert to {@link Response} + * @return a {@link Response} converted from {@link AggregatedHttpResponse} + */ + private Response convertResponse(final AggregatedHttpResponse aggregatedResponse) { + final Map headersMap = new HashMap<>(aggregatedResponse.headers().size()); + aggregatedResponse.headers() + .forEach((header, value) -> headersMap.put(header.toString(), value)); + return new Response(aggregatedResponse.status().code(), + aggregatedResponse.status().reasonPhrase(), + headersMap, aggregatedResponse.content().toInputStream()); + } + + /** + * Converts {@link AggregatedHttpResponse} to {@link Response} upon its aggregation completion + * and invokes {@link OAuthAsyncRequestCallback} for it. + * @param callback a {@link OAuthAsyncRequestCallback} callback to invoke upon response completion + * @param converter an optional {@link OAuthRequest.ResponseConverter} result converter for {@link Response} + * @param aggregatedResponse a source {@link AggregatedHttpResponse} to handle + * @param converter {@link OAuthRequest.ResponseConverter} specific type or {@link Response} + * @return either instance of {@link Response} or converted result based on {@link OAuthRequest.ResponseConverter} + */ + private T whenResponseComplete(OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter, AggregatedHttpResponse aggregatedResponse) { + final Response response = convertResponse(aggregatedResponse); + try { + @SuppressWarnings("unchecked") final T t = + converter == null ? (T) response : converter.convert(response); + if (callback != null) { + callback.onCompleted(t); + } + return t; + } catch (IOException | RuntimeException e) { + return completeExceptionally(callback, e); + } + } + + /** + * Invokes {@link OAuthAsyncRequestCallback} upon {@link Throwable} error result + * @param callback a {@link OAuthAsyncRequestCallback} callback to invoke upon response completion + * @param throwable a {@link Throwable} error result + * @param converter {@link OAuthRequest.ResponseConverter} specific type or {@link Response} + * @return null + */ + private T completeExceptionally(OAuthAsyncRequestCallback callback, Throwable throwable) { + if (callback != null) { + callback.onThrowable(throwable); + } + return null; + } + + //------------------------------------------------------------------------------------------------ + // Body type suppliers + + private static class BytesBody implements Supplier { + + private final byte[] bodyContents; + + BytesBody(final byte[] bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public HttpData get() { + return (bodyContents != null) ? HttpData.wrap(bodyContents) : null; + } + } + + private static class StringBody implements Supplier { + + private final String bodyContents; + + StringBody(final String bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public HttpData get() { + return (bodyContents != null) ? HttpData.ofUtf8(bodyContents) : null; + } + } + + private static class FileBody implements Supplier { + + private final File bodyContents; + + FileBody(final File bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public HttpData get() { + try { + return (bodyContents != null) + ? HttpData.wrap(Files.readAllBytes(bodyContents.toPath())) + : null; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + private static class MultipartBody implements Supplier { + + private final MultipartPayload bodyContents; + + MultipartBody(final MultipartPayload bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public HttpData get() { + try { + return (bodyContents != null) + ? HttpData.wrap(MultipartUtils.getPayload(bodyContents).toByteArray()) + : null; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + //------------------------------------------------------------------------------------------------ +} diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java new file mode 100644 index 000000000..0b566de4a --- /dev/null +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java @@ -0,0 +1,104 @@ +package com.github.scribejava.httpclient.armeria; + +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.linecorp.armeria.client.ClientFactoryOption; +import com.linecorp.armeria.client.ClientFactoryOptionValue; +import com.linecorp.armeria.client.ClientOption; +import com.linecorp.armeria.client.ClientOptions; +import com.linecorp.armeria.client.ClientOptionsBuilder; +import com.linecorp.armeria.common.SessionProtocol; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +public class ArmeriaHttpClientConfig implements HttpClientConfig { + + private Map options; + private Map factoryOptions; + private String protocolPreference; + private Boolean logging; + + ClientOptions getClientOptions() { + if (options == null || options.isEmpty()) { + return null; + } + final ClientOptionsBuilder builder = ClientOptions.builder(); + for (Map.Entry optionEntry : options.entrySet()) { + builder.option(ClientOption.valueOf(optionEntry.getKey()), optionEntry.getValue()); + } + return builder.build(); + } + + public Map getOptions() { + return options; + } + + public void setOptions(Map options) { + this.options = options; + } + + Collection> getClientFactoryOptions() { + if (factoryOptions == null || factoryOptions.isEmpty()) { + return Collections.emptyList(); + } + final List> options = new ArrayList<>(); + for (Map.Entry optionEntry : factoryOptions.entrySet()) { + options.add(ClientFactoryOption.valueOf(optionEntry.getKey()).newValue(optionEntry.getValue())); + } + // WARNING: this ClientFactoryOptions.of(options) method will override default channel options of the factory + // and cause NPE + //return ClientFactoryOptions.of(options); + return options; + } + + public Map getFactoryOptions() { + return factoryOptions; + } + + public void setFactoryOptions(Map factoryOptions) { + this.factoryOptions = factoryOptions; + } + + SessionProtocol getSessionProtocolPreference() { + if (protocolPreference == null) { + return SessionProtocol.H1; // default + } + final SessionProtocol protocol = SessionProtocol.of(protocolPreference); + switch(protocol) { + case H1: + case H1C: + return SessionProtocol.H1; + case PROXY: + throw new IllegalArgumentException("protocolPreference - " + SessionProtocol.PROXY.uriText()); + default: + return SessionProtocol.H2; + } + } + + public String getProtocolPreference() { + return protocolPreference; + } + + public void setProtocolPreference(String protocolPreference) { + this.protocolPreference = protocolPreference; + } + + public boolean isLogging() { + return logging != null && logging; + } + + public void setLogging(boolean logging) { + this.logging = logging; + } + + @Override + public HttpClientConfig createDefaultConfig() { + return defaultConfig(); + } + + public static ArmeriaHttpClientConfig defaultConfig() { + return new ArmeriaHttpClientConfig(); + } +} diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaProvider.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaProvider.java new file mode 100644 index 000000000..b352a8b07 --- /dev/null +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaProvider.java @@ -0,0 +1,16 @@ +package com.github.scribejava.httpclient.armeria; + +import com.github.scribejava.core.httpclient.HttpClientProvider; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; + +public class ArmeriaProvider implements HttpClientProvider { + + @Override + public HttpClient createClient(HttpClientConfig config) { + if (config instanceof ArmeriaHttpClientConfig) { + return new ArmeriaHttpClient((ArmeriaHttpClientConfig) config); + } + return null; + } +} diff --git a/scribejava-httpclient-armeria/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider b/scribejava-httpclient-armeria/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider new file mode 100644 index 000000000..bba338db5 --- /dev/null +++ b/scribejava-httpclient-armeria/src/main/resources/META-INF/services/com.github.scribejava.core.httpclient.HttpClientProvider @@ -0,0 +1 @@ +com.github.scribejava.httpclient.armeria.ArmeriaProvider diff --git a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java new file mode 100644 index 000000000..3cdecee1a --- /dev/null +++ b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java @@ -0,0 +1,69 @@ +package com.github.scribejava.httpclient.armeria; + +import com.github.scribejava.core.AbstractClientTest; +import com.github.scribejava.core.httpclient.HttpClient; +import io.netty.channel.EventLoopGroup; +import io.netty.resolver.AbstractAddressResolver; +import io.netty.resolver.AddressResolver; +import io.netty.resolver.AddressResolverGroup; +import io.netty.util.concurrent.EventExecutor; +import io.netty.util.concurrent.Promise; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.util.Collections; +import java.util.List; +import java.util.function.Function; + +public class ArmeriaHttpClientTest extends AbstractClientTest { + + @Override + protected HttpClient createNewClient() { + final ArmeriaHttpClientConfig config = ArmeriaHttpClientConfig.defaultConfig(); + // simulate DNS resolution for a mock address ("kubernetes.docker.internal") + final Function> + addressResolverGroupFactory = eventLoopGroup -> new MockAddressResolverGroup(); + config.setFactoryOptions(// No-Op DNS resolver to avoid resolution issues in the unit test + Collections.singletonMap("ADDRESS_RESOLVER_GROUP_FACTORY", addressResolverGroupFactory)); + // enable client-side HTTP tracing + config.setLogging(true); + return new ArmeriaHttpClient(config); + } + + //------------------------------------------------------------------------------------------------ + // No-Op DNS resolver to avoid resolution issues in the unit test + + static class MockAddressResolverGroup extends AddressResolverGroup { + + private MockAddressResolverGroup() { + } + + protected AddressResolver newResolver(EventExecutor executor) { + return new MockAddressResolver(executor); + } + } + + static class MockAddressResolver extends AbstractAddressResolver { + + private MockAddressResolver(EventExecutor executor) { + super(executor); + } + + protected boolean doIsResolved(InetSocketAddress address) { + return !address.isUnresolved(); + } + + private InetSocketAddress resolveToLoopback(InetSocketAddress unresolvedAddress) { + return new InetSocketAddress(InetAddress.getLoopbackAddress(), unresolvedAddress.getPort()); + } + + protected void doResolve(InetSocketAddress unresolvedAddress, Promise promise) { + promise.setSuccess(resolveToLoopback(unresolvedAddress)); + } + + protected void doResolveAll(InetSocketAddress unresolvedAddress, Promise> promise) { + promise.setSuccess(Collections.singletonList(resolveToLoopback(unresolvedAddress))); + } + } + + //------------------------------------------------------------------------------------------------ +} diff --git a/scribejava-httpclient-armeria/src/test/resources/simplelogger.properties b/scribejava-httpclient-armeria/src/test/resources/simplelogger.properties new file mode 100644 index 000000000..ce703174e --- /dev/null +++ b/scribejava-httpclient-armeria/src/test/resources/simplelogger.properties @@ -0,0 +1,29 @@ +# SLF4J's SimpleLogger configuration file +# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err. + +# Default logging detail level for all instances of SimpleLogger. +# Must be one of ("trace", "debug", "info", "warn", or "error"). +# If not specified, defaults to "info". +org.slf4j.simpleLogger.defaultLogLevel=debug + +# Set to true if you want the current date and time to be included in output messages. +# Default is false, and will output the number of milliseconds elapsed since startup. +org.slf4j.simpleLogger.showDateTime=true + +# The date and time format to be used in the output messages. +# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat. +# If the format is not specified or is invalid, the default format is used. +# The default format is yyyy-MM-dd HH:mm:ss:SSS Z. +org.slf4j.simpleLogger.dateTimeFormat=[HH:mm:ss] + +# Set to true if you want to output the current thread name. +# Defaults to true. +#org.slf4j.simpleLogger.showThreadName=true + +# Set to true if you want the Logger instance name to be included in output messages. +# Defaults to true. +#org.slf4j.simpleLogger.showLogName=true + +# Set to true if you want the last component of the name to be included in output messages. +# Defaults to false. +org.slf4j.simpleLogger.showShortLogName=true From 7c2b4b005fc729ede5fb8e6103f609d53b23d44a Mon Sep 17 00:00:00 2001 From: max904 Date: Mon, 18 May 2020 18:42:16 +0200 Subject: [PATCH 380/481] - upgraded Armeria to the latest version 0.99.5 and removed explicit Netty dependency - reworked ArmeriaHttpClientConfig and added configurations for clientOptions, clientFactory, protocolPreference, retry and logging - added ArmeriaWebClientBuilder to build new WebClient using newWebClient(String scheme, String authority) - adjusted ArmeriaHttpClient and ArmeriaHttpClientTest - added more JavaDoc - removed simplelogger.properties used for tests --- scribejava-httpclient-armeria/pom.xml | 12 +- .../httpclient/armeria/ArmeriaHttpClient.java | 169 ++++--------- .../armeria/ArmeriaHttpClientConfig.java | 237 ++++++++++++------ .../armeria/ArmeriaWebClientBuilder.java | 74 ++++++ .../armeria/ArmeriaHttpClientTest.java | 10 +- .../test/resources/simplelogger.properties | 29 --- 6 files changed, 307 insertions(+), 224 deletions(-) create mode 100644 scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaWebClientBuilder.java delete mode 100644 scribejava-httpclient-armeria/src/test/resources/simplelogger.properties diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index e11a41915..e8ff5b167 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -22,19 +22,19 @@ com.linecorp.armeria armeria - 0.97.0 + 0.99.5 com.github.scribejava - scribejava-core + scribejava-apis ${project.version} - test-jar test - io.netty - netty-all - 4.1.43.Final + com.github.scribejava + scribejava-core + ${project.version} + test-jar test diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java index d3b8a6359..fb372f83c 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java @@ -1,7 +1,8 @@ package com.github.scribejava.httpclient.armeria; +import static java.util.Objects.requireNonNull; + import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; -import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.httpclient.multipart.MultipartPayload; import com.github.scribejava.core.httpclient.multipart.MultipartUtils; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; @@ -9,27 +10,18 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; -import com.linecorp.armeria.client.ClientFactory; -import com.linecorp.armeria.client.ClientFactoryBuilder; -import com.linecorp.armeria.client.ClientFactoryOptionValue; -import com.linecorp.armeria.client.ClientOptions; -import com.linecorp.armeria.client.Endpoint; import com.linecorp.armeria.client.WebClient; -import com.linecorp.armeria.client.WebClientBuilder; -import com.linecorp.armeria.client.logging.LoggingClient; import com.linecorp.armeria.common.AggregatedHttpResponse; import com.linecorp.armeria.common.HttpData; import com.linecorp.armeria.common.HttpMethod; import com.linecorp.armeria.common.HttpResponse; import com.linecorp.armeria.common.RequestHeaders; import com.linecorp.armeria.common.RequestHeadersBuilder; -import com.linecorp.armeria.common.SessionProtocol; import java.io.File; import java.io.IOException; import java.net.URI; import java.nio.file.Files; -import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.concurrent.CompletableFuture; @@ -38,10 +30,23 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.function.Supplier; +/** + * An implementation of {@link AbstractAsyncOnlyHttpClient} based on + * Armeria HTTP client. + */ public class ArmeriaHttpClient extends AbstractAsyncOnlyHttpClient { - private final ArmeriaHttpClientConfig config; + /** + * A builder of new instances of Armeria's {@link WebClient} + */ + private final ArmeriaWebClientBuilder clientBuilder; + /** + * A list of cached Endpoints. It helps avoiding building a new Endpoint per each request. + */ private final Map httpClients = new HashMap<>(); + /** + * A read/write lock to access the list of cached Endpoints concurrently. + */ private final ReentrantReadWriteLock httpClientsLock = new ReentrantReadWriteLock(); public ArmeriaHttpClient() { @@ -49,15 +54,11 @@ public ArmeriaHttpClient() { } public ArmeriaHttpClient(ArmeriaHttpClientConfig config) { - this.config = config; - } - - public HttpClientConfig getConfig() { - return config; + this.clientBuilder = config.builder(); } /** - * Cleans up HTTP clients collection. + * Cleans up the list of cached Endpoints. */ @Override public void close() { @@ -112,7 +113,7 @@ private CompletableFuture doExecuteAsync(String userAgent, final String path = getServicePath(uri); // Fetch/Create WebClient instance for a given Endpoint - final WebClient client = getHttpClient(uri); + final WebClient client = getClient(uri); // Build HTTP request final RequestHeadersBuilder headersBuilder = @@ -148,55 +149,19 @@ private CompletableFuture doExecuteAsync(String userAgent, //------------------------------------------------------------------------------------------------ /** - * Extracts Protocol + Host + Port part from a given endpoint {@link URI} - * @param uri an endpoint {@link URI} - * @return a portion of {@link URI} including a combination of Protocol + Host + Port - * @see #getHttpClient(URI uri) - */ - private String getHostUri(final URI uri) { - final StringBuilder builder = new StringBuilder(); - builder.append(uri.getScheme()).append("://").append(uri.getHost()); - final int port = uri.getPort(); - if (port > 0) { - builder.append(":").append(port); - } - return builder.toString(); - } - - /** - * Extracts service path from a given endpoint {@link URI} - * @param uri an endpoint {@link URI} - * @return service path portion of the {@link URI} - */ - private static String getServicePath(final URI uri) { - final StringBuilder builder = new StringBuilder(); - final String path = uri.getRawPath(); - if (path != null && path.length() > 0) { - builder.append(path); - } else { - builder.append("/"); - } - final String query = uri.getRawQuery(); - if (query != null && query.length() > 0) { - builder.append("?").append(query); - } - return builder.toString(); - } - - /** - * Provides and instance of {@link WebClient} for a given endpoint {@link URI} based on - * a combination of Protocol + Host + Port. + * Provides an instance of {@link WebClient} for a given endpoint {@link URI} based on an endpoint + * as {@code scheme://authority}. * @param uri an endpoint {@link URI} * @return {@link WebClient} instance */ - private WebClient getHttpClient(final URI uri) { - final String hostUri = getHostUri(uri); + private WebClient getClient(final URI uri) { + final String endpoint = getEndPoint(uri); WebClient client; final Lock readLock = httpClientsLock.readLock(); readLock.lock(); try { - client = httpClients.get(hostUri); + client = httpClients.get(endpoint); } finally { readLock.unlock(); } @@ -205,16 +170,18 @@ private WebClient getHttpClient(final URI uri) { return client; } - client = buildNewHttpClient(uri); + client = clientBuilder.newWebClient( + requireNonNull(uri.getScheme(), "scheme"), + requireNonNull(uri.getAuthority(), "authority")); final Lock writeLock = httpClientsLock.writeLock(); writeLock.lock(); try { - if (!httpClients.containsKey(hostUri)) { - httpClients.put(hostUri, client); + if (!httpClients.containsKey(endpoint)) { + httpClients.put(endpoint, client); return client; } else { - return httpClients.get(hostUri); + return httpClients.get(endpoint); } } finally { writeLock.unlock(); @@ -222,63 +189,35 @@ private WebClient getHttpClient(final URI uri) { } /** - * Builds a brand-new instance of {@link WebClient} for a given endpoint {@link URI}. - * Uses {@link ArmeriaHttpClientConfig} to configure the builder and the client. - * @param uri an endpoint {@link URI} - * @return Brand-new {@link WebClient} instance + * Extracts {@code scheme} and {@code authority} portion of the {@link URI}. + * Assuming the {@link URI} as the following: + * {@code URI = scheme:[//authority]path[?query][#fragment]} */ - private WebClient buildNewHttpClient(final URI uri) { - // Build the client and the headers - WebClientBuilder clientBuilder = - getHttpClientBuilder(uri, config.getSessionProtocolPreference()); - - final ClientOptions clientOptions = config.getClientOptions(); - if (clientOptions != null) { - clientBuilder.options(clientOptions); - } - - final ClientFactoryBuilder clientFactoryBuilder = ClientFactory.builder(); - final Collection> clientFactoryOptions = config.getClientFactoryOptions(); - if (clientFactoryOptions != null && !clientFactoryOptions.isEmpty()) { - clientFactoryOptions.forEach(clientFactoryBuilder::option); - } - clientBuilder.factory(clientFactoryBuilder.build()); - - if (config.isLogging()) { - clientBuilder = clientBuilder.decorator(LoggingClient.newDecorator()); - } - - return clientBuilder.build(); + @SuppressWarnings("StringBufferReplaceableByString") + private static String getEndPoint(final URI uri) { + final StringBuilder builder = new StringBuilder() + .append(requireNonNull(uri.getScheme(), "scheme")) + .append("://").append(requireNonNull(uri.getAuthority(), "authority")); + return builder.toString(); } /** - * Provides an instance of {@link WebClientBuilder} for a given endpoint {@link URI} - * @param uri an endpoint {@link URI} - * @param protocolPreference an HTTP protocol generation preference; acceptable values: "h1" or "h2". - * @return {@link WebClientBuilder} instance to build a new {@link WebClient} + * Extracts {@code path}, {@code query) and {@code fragment} portion of the {@link URI}. + * Assuming the {@link URI} as the following: + * {@code URI = scheme:[//authority]path[?query][#fragment]} */ - private WebClientBuilder getHttpClientBuilder(final URI uri, final SessionProtocol protocolPreference) { - final SessionProtocol sessionProtocol = SessionProtocol.of(uri.getScheme()); - final String host = uri.getHost(); - final int port = uri.getPort(); - final Endpoint endpoint = (port > 0) ? Endpoint.of(host, port) : Endpoint.of(host); - switch(sessionProtocol) { - case HTTP: - if (protocolPreference == SessionProtocol.H1) { - // enforce HTTP/1 protocol - return WebClient.builder(SessionProtocol.H1C, endpoint); - } - break; - case HTTPS: - if (protocolPreference == SessionProtocol.H1) { - // enforce HTTP/1 protocol - return WebClient.builder(SessionProtocol.H1, endpoint); - } - break; - default: - break; + private static String getServicePath(final URI uri) { + final StringBuilder builder = new StringBuilder() + .append(requireNonNull(uri.getPath(), "path")); + final String query = uri.getQuery(); + if (query != null) { + builder.append('?').append(query); } - return WebClient.builder(sessionProtocol, endpoint); + final String fragment = uri.getFragment(); + if (fragment != null) { + builder.append('#').append(fragment); + } + return builder.toString(); } /** @@ -286,7 +225,7 @@ private WebClientBuilder getHttpClientBuilder(final URI uri, final SessionProtoc * @param httpVerb a {@link Verb} to match with {@link HttpMethod} * @return {@link HttpMethod} corresponding to the parameter */ - private HttpMethod getHttpMethod(final Verb httpVerb) { + private static HttpMethod getHttpMethod(final Verb httpVerb) { switch (httpVerb) { case GET: return HttpMethod.GET; diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java index 0b566de4a..97b13e5c3 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java @@ -1,104 +1,199 @@ package com.github.scribejava.httpclient.armeria; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.linecorp.armeria.client.ClientFactoryOption; -import com.linecorp.armeria.client.ClientFactoryOptionValue; -import com.linecorp.armeria.client.ClientOption; +import com.linecorp.armeria.client.ClientFactory; import com.linecorp.armeria.client.ClientOptions; -import com.linecorp.armeria.client.ClientOptionsBuilder; +import com.linecorp.armeria.client.HttpClient; +import com.linecorp.armeria.client.logging.LoggingClient; +import com.linecorp.armeria.client.retry.Backoff; +import com.linecorp.armeria.client.retry.RetryRule; +import com.linecorp.armeria.client.retry.RetryingClient; +import com.linecorp.armeria.common.HttpStatus; import com.linecorp.armeria.common.SessionProtocol; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import com.linecorp.armeria.common.logging.LogLevel; +import java.util.function.Function; +import org.slf4j.LoggerFactory; public class ArmeriaHttpClientConfig implements HttpClientConfig { - private Map options; - private Map factoryOptions; - private String protocolPreference; - private Boolean logging; - - ClientOptions getClientOptions() { - if (options == null || options.isEmpty()) { - return null; - } - final ClientOptionsBuilder builder = ClientOptions.builder(); - for (Map.Entry optionEntry : options.entrySet()) { - builder.option(ClientOption.valueOf(optionEntry.getKey()), optionEntry.getValue()); - } - return builder.build(); + private static final SessionProtocol DEFAULT_PROTOCOL_PREFERENCE = SessionProtocol.H1; // H1 or H2 + + private final ClientOptions clientOptions; + private final ClientFactory clientFactory; + private SessionProtocol protocolPreference; + private Function retry; + private Function logging; + + /** + * Creates new {@link ArmeriaHttpClientConfig} using provided {@link ClientOptions} and + * {@link ClientFactory}. + */ + public ArmeriaHttpClientConfig(ClientOptions clientOptions, ClientFactory clientFactory) { + this.clientOptions = clientOptions; + this.clientFactory = clientFactory; + protocolPreference = DEFAULT_PROTOCOL_PREFERENCE; } - public Map getOptions() { - return options; + /** + * Creates new {@link ArmeriaHttpClientConfig} using default settings. + */ + ArmeriaHttpClientConfig() { + this(null, null); } - public void setOptions(Map options) { - this.options = options; - } - - Collection> getClientFactoryOptions() { - if (factoryOptions == null || factoryOptions.isEmpty()) { - return Collections.emptyList(); - } - final List> options = new ArrayList<>(); - for (Map.Entry optionEntry : factoryOptions.entrySet()) { - options.add(ClientFactoryOption.valueOf(optionEntry.getKey()).newValue(optionEntry.getValue())); - } - // WARNING: this ClientFactoryOptions.of(options) method will override default channel options of the factory - // and cause NPE - //return ClientFactoryOptions.of(options); - return options; + /** + * Creates new {@link HttpClientConfig} using default settings. + */ + @Override + public HttpClientConfig createDefaultConfig() { + return defaultConfig(); } - public Map getFactoryOptions() { - return factoryOptions; + /** + * Creates new {@link ArmeriaHttpClientConfig} using default settings. + */ + public static ArmeriaHttpClientConfig defaultConfig() { + return new ArmeriaHttpClientConfig(); } - public void setFactoryOptions(Map factoryOptions) { - this.factoryOptions = factoryOptions; + /** + * Selects which protocol shall take preference when generic protocol scheme used by the URL, + * like {@code http} or {@code https}. + * + * @param protocolPreference specifies which protocol shall take preference. + * Acceptable values: {@code H1}, {@code HTTP1}, {@code HTTP/1.1} for + * {@code HTTP/1.1} and {@code H2}, {@code HTTP2}, {@code HTTP/2} for + * {@code HTTP/2}. + */ + public void protocolPreference(String protocolPreference) { + switch (protocolPreference.toUpperCase()) { + case "H1": + case "HTTP1": + case "HTTP/1.1": + this.protocolPreference = SessionProtocol.H1; + break; + case "H2": + case "HTTP2": + case "HTTP/2": + this.protocolPreference = SessionProtocol.H2; + break; + default: + throw new IllegalArgumentException("Invalid protocolPreference: " + protocolPreference); + } } - SessionProtocol getSessionProtocolPreference() { - if (protocolPreference == null) { - return SessionProtocol.H1; // default - } - final SessionProtocol protocol = SessionProtocol.of(protocolPreference); - switch(protocol) { + /** + * Selects which protocol shall take preference when generic protocol scheme used by the URL, + * like {@code http} or {@code https}. + * + * @param protocolPreference specifies which protocol shall take preference. + * Acceptable values: {@link SessionProtocol#H1} and + * {@link SessionProtocol#H2} + */ + public void protocolPreference(SessionProtocol protocolPreference) { + switch (protocolPreference) { case H1: - case H1C: - return SessionProtocol.H1; - case PROXY: - throw new IllegalArgumentException("protocolPreference - " + SessionProtocol.PROXY.uriText()); + this.protocolPreference = SessionProtocol.H1; + break; + case H2: + this.protocolPreference = SessionProtocol.H2; + break; default: - return SessionProtocol.H2; + throw new IllegalArgumentException("Invalid protocolPreference: " + protocolPreference); } } - public String getProtocolPreference() { - return protocolPreference; + /** + * Sets the client to retry when the remote end-point responds with one of the + * specified {@code statuses}. + * + * Uses a backoff that computes a delay using one of supported functions, such as + * {@code exponential(long, long, double)}, {@code fibonacci(long, long)}, {@code fixed(long)} + * and {@code random(long, long)} chaining with {@code withJitter(double, double)} and + * {@code withMaxAttempts(int)} from the {@code backoff} string that conforms to + * the following format: + *
      + *
    • {@code exponential=[initialDelayMillis:maxDelayMillis:multiplier]} is for + * {@code exponential(long, long, double)} (multiplier will be 2.0 if it's omitted)
    • + *
    • {@code fibonacci=[initialDelayMillis:maxDelayMillis]} is for + * {@code fibonacci(long, long)}
    • + *
    • {@code fixed=[delayMillis]} is for {@code fixed(long)}
    • + *
    • {@code random=[minDelayMillis:maxDelayMillis]} is for {@code random(long, long)}
    • + *
    • {@code jitter=[minJitterRate:maxJitterRate]} is for {@code withJitter(double, double)} + * (if only one jitter value is specified, it will be used for {@code withJitter(double)}
    • + *
    • {@code maxAttempts=[maxAttempts]} is for {@code withMaxAttempts(int)}
    • + *
    + * The order of options does not matter, and the {@code backoff} needs at least one option. + * If you don't specify the base option exponential backoff will be used. If you only specify + * a base option, jitter and maxAttempts will be set by default values. For example: + *
      + *
    • {@code exponential=200:10000:2.0,jitter=0.2} (default)
    • + *
    • {@code exponential=200:10000,jitter=0.2,maxAttempts=50} (multiplier omitted)
    • + *
    • {@code fibonacci=200:10000,jitter=0.2,maxAttempts=50}
    • + *
    • {@code fixed=100,jitter=-0.5:0.2,maxAttempts=10} (fixed backoff with jitter variation)
    • + *
    • {@code random=200:1000} (jitter and maxAttempts will be set by default values)
    • + *
    + * + * @param backoff the specification used to create a retry backoff + * @param statuses the list of HTTP statuses on which to retry + */ + public void retry(String backoff, HttpStatus... statuses) { + final Backoff retryBackoff = Backoff.of(backoff); + final RetryRule retryRule = + RetryRule.builder().onStatus(statuses).onUnprocessed().thenBackoff(retryBackoff); + retry = RetryingClient.newDecorator(retryRule); } - public void setProtocolPreference(String protocolPreference) { - this.protocolPreference = protocolPreference; + /** + * Sets the client to log requests and responses to the specified {@code logger}. + * This method explicitly specifies various log levels. The log level correspond to a value + * of {@link LogLevel} and must use one of the following values: + * {@code ["OFF", "TRACE", "DEBUG", "INFO", "WARN", "ERROR"]} + * + * @param logger the logger name (of {@link org.slf4j.Logger}) to log requests/responses to + * @param requestLevel the log level to use for logging requests, default {@code "DEBUG"} + * @param responseLevel the log level to use for logging responses, default {@code "DEBUG"} + * @param failureResponseLevel the log level to use for logging error responses, + * default {@code "WARN"} + */ + public void logging(String logger, String requestLevel, String responseLevel, + String failureResponseLevel) { + this.logging = LoggingClient.builder() + .logger(LoggerFactory.getLogger(logger)) + .requestLogLevel(LogLevel.valueOf(requestLevel)) + .successfulResponseLogLevel(LogLevel.valueOf(responseLevel)) + .failureResponseLogLevel(LogLevel.valueOf(failureResponseLevel)) + .newDecorator(); } - public boolean isLogging() { - return logging != null && logging; + /** + * Sets the client to log requests and responses to the specified {@code logger} using default + * log levels. + * + * @param logger the logger name (of {@link org.slf4j.Logger}) to log requests/responses to + */ + public void logging(String logger) { + this.logging = LoggingClient.builder() + .logger(LoggerFactory.getLogger(logger)) + .requestLogLevel(LogLevel.DEBUG) + .successfulResponseLogLevel(LogLevel.DEBUG) + .failureResponseLogLevel(LogLevel.WARN) + .newDecorator(); } - public void setLogging(boolean logging) { - this.logging = logging; + /** + * Sets the client to log requests and responses to a default logger using default log levels. + */ + public void logging() { + this.logging = LoggingClient.builder() + .requestLogLevel(LogLevel.DEBUG) + .successfulResponseLogLevel(LogLevel.DEBUG) + .failureResponseLogLevel(LogLevel.WARN) + .newDecorator(); } - @Override - public HttpClientConfig createDefaultConfig() { - return defaultConfig(); - } - - public static ArmeriaHttpClientConfig defaultConfig() { - return new ArmeriaHttpClientConfig(); + ArmeriaWebClientBuilder builder() { + return new ArmeriaWebClientBuilder(clientOptions, clientFactory, protocolPreference, + retry, logging); } } diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaWebClientBuilder.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaWebClientBuilder.java new file mode 100644 index 000000000..e79c9c27c --- /dev/null +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaWebClientBuilder.java @@ -0,0 +1,74 @@ +package com.github.scribejava.httpclient.armeria; + +import com.linecorp.armeria.client.ClientFactory; +import com.linecorp.armeria.client.ClientOptions; +import com.linecorp.armeria.client.Endpoint; +import com.linecorp.armeria.client.HttpClient; +import com.linecorp.armeria.client.WebClient; +import com.linecorp.armeria.client.WebClientBuilder; +import com.linecorp.armeria.client.logging.LoggingClient; +import com.linecorp.armeria.client.retry.RetryingClient; +import com.linecorp.armeria.common.SessionProtocol; +import java.util.function.Function; + +/** + * A builder of {@link WebClient} using supplied configuration parameters. + */ +public class ArmeriaWebClientBuilder { + + private final ClientFactory clientFactory; + private final ClientOptions clientOptions; + private final SessionProtocol protocolPreference; + private final Function retry; + private final Function logging; + + ArmeriaWebClientBuilder(ClientOptions clientOptions, ClientFactory clientFactory, + SessionProtocol protocolPreference, Function retry, + Function logging) { + this.clientOptions = clientOptions; + this.clientFactory = clientFactory; + this.protocolPreference = protocolPreference; + this.retry = retry; + this.logging = logging; + } + + WebClient newWebClient(String scheme, String authority) { + final SessionProtocol protocol = protocol(scheme); + final Endpoint endpoint = Endpoint.parse(authority); + final WebClientBuilder clientBuilder = WebClient.builder(protocol, endpoint); + if (clientOptions != null) { + clientBuilder.options(clientOptions); + } + if (clientFactory != null) { + clientBuilder.factory(clientFactory); + } + if (retry != null) { + clientBuilder.decorator(retry); + } + if (logging != null) { + clientBuilder.decorator(logging); + } + return clientBuilder.build(); + } + + private SessionProtocol protocol(String scheme) { + final SessionProtocol protocol = SessionProtocol.of(scheme); + switch(protocol) { + case HTTP: + if (protocolPreference == SessionProtocol.H1) { + // enforce HTTP/1 protocol + return SessionProtocol.H1C; + } + break; + case HTTPS: + if (protocolPreference == SessionProtocol.H1) { + // enforce HTTP/1 protocol + return SessionProtocol.H1; + } + break; + default: + break; + } + return protocol; + } +} diff --git a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java index 3cdecee1a..508617acf 100644 --- a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java +++ b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java @@ -2,6 +2,8 @@ import com.github.scribejava.core.AbstractClientTest; import com.github.scribejava.core.httpclient.HttpClient; +import com.linecorp.armeria.client.ClientFactory; +import com.linecorp.armeria.common.HttpStatus; import io.netty.channel.EventLoopGroup; import io.netty.resolver.AbstractAddressResolver; import io.netty.resolver.AddressResolver; @@ -22,10 +24,12 @@ protected HttpClient createNewClient() { // simulate DNS resolution for a mock address ("kubernetes.docker.internal") final Function> addressResolverGroupFactory = eventLoopGroup -> new MockAddressResolverGroup(); - config.setFactoryOptions(// No-Op DNS resolver to avoid resolution issues in the unit test - Collections.singletonMap("ADDRESS_RESOLVER_GROUP_FACTORY", addressResolverGroupFactory)); + // No-Op DNS resolver to avoid resolution issues in the unit test + ClientFactory.builder().addressResolverGroupFactory(addressResolverGroupFactory); // enable client-side HTTP tracing - config.setLogging(true); + config.logging("HTTP_TRACE", "INFO", "INFO", "WARN"); + // enable request retry + config.retry("exponential=200:10000,jitter=0.2,maxAttempts=5", HttpStatus.SERVICE_UNAVAILABLE); return new ArmeriaHttpClient(config); } diff --git a/scribejava-httpclient-armeria/src/test/resources/simplelogger.properties b/scribejava-httpclient-armeria/src/test/resources/simplelogger.properties deleted file mode 100644 index ce703174e..000000000 --- a/scribejava-httpclient-armeria/src/test/resources/simplelogger.properties +++ /dev/null @@ -1,29 +0,0 @@ -# SLF4J's SimpleLogger configuration file -# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err. - -# Default logging detail level for all instances of SimpleLogger. -# Must be one of ("trace", "debug", "info", "warn", or "error"). -# If not specified, defaults to "info". -org.slf4j.simpleLogger.defaultLogLevel=debug - -# Set to true if you want the current date and time to be included in output messages. -# Default is false, and will output the number of milliseconds elapsed since startup. -org.slf4j.simpleLogger.showDateTime=true - -# The date and time format to be used in the output messages. -# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat. -# If the format is not specified or is invalid, the default format is used. -# The default format is yyyy-MM-dd HH:mm:ss:SSS Z. -org.slf4j.simpleLogger.dateTimeFormat=[HH:mm:ss] - -# Set to true if you want to output the current thread name. -# Defaults to true. -#org.slf4j.simpleLogger.showThreadName=true - -# Set to true if you want the Logger instance name to be included in output messages. -# Defaults to true. -#org.slf4j.simpleLogger.showLogName=true - -# Set to true if you want the last component of the name to be included in output messages. -# Defaults to false. -org.slf4j.simpleLogger.showShortLogName=true From 6e5c62c69c546b9881d2875ff2ff4d318c0448e6 Mon Sep 17 00:00:00 2001 From: max904 Date: Tue, 26 May 2020 17:26:23 +0200 Subject: [PATCH 381/481] - plugged custom/mock address resolver to optimize the unit test execution --- .../scribejava/httpclient/armeria/ArmeriaHttpClientTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java index 508617acf..1078a563c 100644 --- a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java +++ b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java @@ -20,12 +20,13 @@ public class ArmeriaHttpClientTest extends AbstractClientTest { @Override protected HttpClient createNewClient() { - final ArmeriaHttpClientConfig config = ArmeriaHttpClientConfig.defaultConfig(); // simulate DNS resolution for a mock address ("kubernetes.docker.internal") final Function> addressResolverGroupFactory = eventLoopGroup -> new MockAddressResolverGroup(); // No-Op DNS resolver to avoid resolution issues in the unit test - ClientFactory.builder().addressResolverGroupFactory(addressResolverGroupFactory); + final ClientFactory clientFactory = + ClientFactory.builder().addressResolverGroupFactory(addressResolverGroupFactory).build(); + final ArmeriaHttpClientConfig config = new ArmeriaHttpClientConfig(null, clientFactory); // enable client-side HTTP tracing config.logging("HTTP_TRACE", "INFO", "INFO", "WARN"); // enable request retry From aeed26798f7e4bb1642ca743123de64c98d7603a Mon Sep 17 00:00:00 2001 From: max904 Date: Thu, 28 May 2020 12:02:17 +0200 Subject: [PATCH 382/481] - updated Armeria to version 0.99.6 --- scribejava-httpclient-armeria/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index e8ff5b167..51c5d8d4b 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -22,7 +22,7 @@ com.linecorp.armeria armeria - 0.99.5 + 0.99.6 com.github.scribejava From bc7ac12b2144deafdf7df00f83bca39873420f11 Mon Sep 17 00:00:00 2001 From: max904 Date: Thu, 25 Jun 2020 20:26:52 +0200 Subject: [PATCH 383/481] - updated Armeria to version 0.99.7 --- scribejava-httpclient-armeria/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 51c5d8d4b..6642e9cad 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -22,7 +22,7 @@ com.linecorp.armeria armeria - 0.99.6 + 0.99.7 com.github.scribejava From 4fa982bec3832c035c8a408aa08c8c6067962c38 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Sat, 1 Aug 2020 18:49:41 +0300 Subject: [PATCH 384/481] format code --- .../httpclient/multipart/MultipartUtils.java | 74 +-- .../httpclient/armeria/ArmeriaHttpClient.java | 606 +++++++++--------- .../armeria/ArmeriaHttpClientConfig.java | 323 +++++----- .../httpclient/armeria/ArmeriaProvider.java | 12 +- .../armeria/ArmeriaWebClientBuilder.java | 98 +-- .../armeria/ArmeriaHttpClientTest.java | 80 ++- 6 files changed, 592 insertions(+), 601 deletions(-) diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java index bbbbad078..f995e4b4e 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java @@ -7,47 +7,47 @@ public abstract class MultipartUtils { - // copied from com.github.scribejava.core.httpclient.jdk.JDKHttpClient#getPayload - public static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload) throws IOException { - final ByteArrayOutputStream os = new ByteArrayOutputStream(); + // copied from com.github.scribejava.core.httpclient.jdk.JDKHttpClient#getPayload + public static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload) throws IOException { + final ByteArrayOutputStream os = new ByteArrayOutputStream(); - final String preamble = multipartPayload.getPreamble(); - if (preamble != null) { - os.write(preamble.getBytes()); - } - final List bodyParts = multipartPayload.getBodyParts(); - if (!bodyParts.isEmpty()) { - final String boundary = multipartPayload.getBoundary(); - final byte[] startBoundary = ("\r\n--" + boundary + "\r\n").getBytes(); - - for (BodyPartPayload bodyPart : bodyParts) { - os.write(startBoundary); - - final Map bodyPartHeaders = bodyPart.getHeaders(); - if (bodyPartHeaders != null) { - for (Map.Entry header : bodyPartHeaders.entrySet()) { - os.write((header.getKey() + ": " + header.getValue() + "\r\n").getBytes()); - } + final String preamble = multipartPayload.getPreamble(); + if (preamble != null) { + os.write(preamble.getBytes()); } + final List bodyParts = multipartPayload.getBodyParts(); + if (!bodyParts.isEmpty()) { + final String boundary = multipartPayload.getBoundary(); + final byte[] startBoundary = ("\r\n--" + boundary + "\r\n").getBytes(); + + for (BodyPartPayload bodyPart : bodyParts) { + os.write(startBoundary); + + final Map bodyPartHeaders = bodyPart.getHeaders(); + if (bodyPartHeaders != null) { + for (Map.Entry header : bodyPartHeaders.entrySet()) { + os.write((header.getKey() + ": " + header.getValue() + "\r\n").getBytes()); + } + } + + if (bodyPart instanceof MultipartPayload) { + getPayload((MultipartPayload) bodyPart).writeTo(os); + } else if (bodyPart instanceof ByteArrayBodyPartPayload) { + os.write("\r\n".getBytes()); + os.write(((ByteArrayBodyPartPayload) bodyPart).getPayload()); + } else { + throw new AssertionError(bodyPart.getClass()); + } + } + + os.write(("\r\n--" + boundary + "--\r\n").getBytes()); + final String epilogue = multipartPayload.getEpilogue(); + if (epilogue != null) { + os.write((epilogue + "\r\n").getBytes()); + } - if (bodyPart instanceof MultipartPayload) { - getPayload((MultipartPayload) bodyPart).writeTo(os); - } else if (bodyPart instanceof ByteArrayBodyPartPayload) { - os.write("\r\n".getBytes()); - os.write(((ByteArrayBodyPartPayload) bodyPart).getPayload()); - } else { - throw new AssertionError(bodyPart.getClass()); } - } - - os.write(("\r\n--" + boundary + "--\r\n").getBytes()); - final String epilogue = multipartPayload.getEpilogue(); - if (epilogue != null) { - os.write((epilogue + "\r\n").getBytes()); - } - + return os; } - return os; - } } diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java index fb372f83c..b059d6f04 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java @@ -36,344 +36,346 @@ */ public class ArmeriaHttpClient extends AbstractAsyncOnlyHttpClient { - /** - * A builder of new instances of Armeria's {@link WebClient} - */ - private final ArmeriaWebClientBuilder clientBuilder; - /** - * A list of cached Endpoints. It helps avoiding building a new Endpoint per each request. - */ - private final Map httpClients = new HashMap<>(); - /** - * A read/write lock to access the list of cached Endpoints concurrently. - */ - private final ReentrantReadWriteLock httpClientsLock = new ReentrantReadWriteLock(); - - public ArmeriaHttpClient() { - this(ArmeriaHttpClientConfig.defaultConfig()); - } - - public ArmeriaHttpClient(ArmeriaHttpClientConfig config) { - this.clientBuilder = config.builder(); - } - - /** - * Cleans up the list of cached Endpoints. - */ - @Override - public void close() { - final Lock writeLock = httpClientsLock.writeLock(); - writeLock.lock(); - try { - httpClients.clear(); - } finally { - writeLock.unlock(); - } - } - - @Override - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - new BytesBody(bodyContents), callback, converter); - } - - @Override - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - new MultipartBody(bodyContents), callback, converter); - } - - @Override - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - new StringBody(bodyContents), callback, converter); - } - - @Override - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, File bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - new FileBody(bodyContents), callback, converter); - } - - private CompletableFuture doExecuteAsync(String userAgent, - Map headers, Verb httpVerb, - String completeUrl, Supplier contentSupplier, - OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - // Get the URI and Path - final URI uri = URI.create(completeUrl); - final String path = getServicePath(uri); - - // Fetch/Create WebClient instance for a given Endpoint - final WebClient client = getClient(uri); - - // Build HTTP request - final RequestHeadersBuilder headersBuilder = - RequestHeaders.of(getHttpMethod(httpVerb), path).toBuilder(); - headersBuilder.add(headers.entrySet()); - if (userAgent != null) { - headersBuilder.add(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); + /** + * A builder of new instances of Armeria's {@link WebClient} + */ + private final ArmeriaWebClientBuilder clientBuilder; + /** + * A list of cached Endpoints. It helps avoiding building a new Endpoint per each request. + */ + private final Map httpClients = new HashMap<>(); + /** + * A read/write lock to access the list of cached Endpoints concurrently. + */ + private final ReentrantReadWriteLock httpClientsLock = new ReentrantReadWriteLock(); + + public ArmeriaHttpClient() { + this(ArmeriaHttpClientConfig.defaultConfig()); } - // Build the request body and execute HTTP request - final HttpResponse response; - if (httpVerb.isPermitBody()) { // POST, PUT, PATCH and DELETE methods - final HttpData contents = contentSupplier.get(); - if (httpVerb.isRequiresBody() && contents == null) { // POST or PUT methods - throw new IllegalArgumentException( - "Contents missing for request method " + httpVerb.name()); - } - if (contents != null) { - response = client.execute(headersBuilder.build(), contents); - } else { - response = client.execute(headersBuilder.build()); - } - } else { - response = client.execute(headersBuilder.build()); + public ArmeriaHttpClient(ArmeriaHttpClientConfig config) { + this.clientBuilder = config.builder(); } - // Aggregate HTTP response (asynchronously) and return the result Future - return response.aggregate() - .thenApply(r -> whenResponseComplete(callback, converter, r)) - .exceptionally(e -> completeExceptionally(callback, e)); - } - - //------------------------------------------------------------------------------------------------ - - /** - * Provides an instance of {@link WebClient} for a given endpoint {@link URI} based on an endpoint - * as {@code scheme://authority}. - * @param uri an endpoint {@link URI} - * @return {@link WebClient} instance - */ - private WebClient getClient(final URI uri) { - final String endpoint = getEndPoint(uri); - - WebClient client; - final Lock readLock = httpClientsLock.readLock(); - readLock.lock(); - try { - client = httpClients.get(endpoint); - } finally { - readLock.unlock(); + /** + * Cleans up the list of cached Endpoints. + */ + @Override + public void close() { + final Lock writeLock = httpClientsLock.writeLock(); + writeLock.lock(); + try { + httpClients.clear(); + } finally { + writeLock.unlock(); + } } - if (client != null) { - return client; + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + new BytesBody(bodyContents), callback, converter); } - client = clientBuilder.newWebClient( - requireNonNull(uri.getScheme(), "scheme"), - requireNonNull(uri.getAuthority(), "authority")); - - final Lock writeLock = httpClientsLock.writeLock(); - writeLock.lock(); - try { - if (!httpClients.containsKey(endpoint)) { - httpClients.put(endpoint, client); - return client; - } else { - return httpClients.get(endpoint); - } - } finally { - writeLock.unlock(); + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + new MultipartBody(bodyContents), callback, converter); } - } - - /** - * Extracts {@code scheme} and {@code authority} portion of the {@link URI}. - * Assuming the {@link URI} as the following: - * {@code URI = scheme:[//authority]path[?query][#fragment]} - */ - @SuppressWarnings("StringBufferReplaceableByString") - private static String getEndPoint(final URI uri) { - final StringBuilder builder = new StringBuilder() - .append(requireNonNull(uri.getScheme(), "scheme")) - .append("://").append(requireNonNull(uri.getAuthority(), "authority")); - return builder.toString(); - } - - /** - * Extracts {@code path}, {@code query) and {@code fragment} portion of the {@link URI}. - * Assuming the {@link URI} as the following: - * {@code URI = scheme:[//authority]path[?query][#fragment]} - */ - private static String getServicePath(final URI uri) { - final StringBuilder builder = new StringBuilder() - .append(requireNonNull(uri.getPath(), "path")); - final String query = uri.getQuery(); - if (query != null) { - builder.append('?').append(query); + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + new StringBody(bodyContents), callback, converter); } - final String fragment = uri.getFragment(); - if (fragment != null) { - builder.append('#').append(fragment); + + @Override + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, File bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, + new FileBody(bodyContents), callback, converter); } - return builder.toString(); - } - - /** - * Maps {@link Verb} to {@link HttpMethod} - * @param httpVerb a {@link Verb} to match with {@link HttpMethod} - * @return {@link HttpMethod} corresponding to the parameter - */ - private static HttpMethod getHttpMethod(final Verb httpVerb) { - switch (httpVerb) { - case GET: - return HttpMethod.GET; - case POST: - return HttpMethod.POST; - case PUT: - return HttpMethod.PUT; - case DELETE: - return HttpMethod.DELETE; - case HEAD: - return HttpMethod.HEAD; - case OPTIONS: - return HttpMethod.OPTIONS; - case TRACE: - return HttpMethod.TRACE; - case PATCH: - return HttpMethod.PATCH; - default: - throw new IllegalArgumentException( - "message build error: unsupported HTTP method: " + httpVerb.name()); + + private CompletableFuture doExecuteAsync(String userAgent, + Map headers, Verb httpVerb, + String completeUrl, Supplier contentSupplier, + OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { + // Get the URI and Path + final URI uri = URI.create(completeUrl); + final String path = getServicePath(uri); + + // Fetch/Create WebClient instance for a given Endpoint + final WebClient client = getClient(uri); + + // Build HTTP request + final RequestHeadersBuilder headersBuilder + = RequestHeaders.of(getHttpMethod(httpVerb), path).toBuilder(); + headersBuilder.add(headers.entrySet()); + if (userAgent != null) { + headersBuilder.add(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); + } + + // Build the request body and execute HTTP request + final HttpResponse response; + if (httpVerb.isPermitBody()) { // POST, PUT, PATCH and DELETE methods + final HttpData contents = contentSupplier.get(); + if (httpVerb.isRequiresBody() && contents == null) { // POST or PUT methods + throw new IllegalArgumentException( + "Contents missing for request method " + httpVerb.name()); + } + if (contents != null) { + response = client.execute(headersBuilder.build(), contents); + } else { + response = client.execute(headersBuilder.build()); + } + } else { + response = client.execute(headersBuilder.build()); + } + + // Aggregate HTTP response (asynchronously) and return the result Future + return response.aggregate() + .thenApply(r -> whenResponseComplete(callback, converter, r)) + .exceptionally(e -> completeExceptionally(callback, e)); } - } - - //------------------------------------------------------------------------------------------------ - // Response asynchronous handlers - - /** - * Converts {@link AggregatedHttpResponse} to {@link Response} - * @param aggregatedResponse an instance of {@link AggregatedHttpResponse} to convert to {@link Response} - * @return a {@link Response} converted from {@link AggregatedHttpResponse} - */ - private Response convertResponse(final AggregatedHttpResponse aggregatedResponse) { - final Map headersMap = new HashMap<>(aggregatedResponse.headers().size()); - aggregatedResponse.headers() - .forEach((header, value) -> headersMap.put(header.toString(), value)); - return new Response(aggregatedResponse.status().code(), - aggregatedResponse.status().reasonPhrase(), - headersMap, aggregatedResponse.content().toInputStream()); - } - - /** - * Converts {@link AggregatedHttpResponse} to {@link Response} upon its aggregation completion - * and invokes {@link OAuthAsyncRequestCallback} for it. - * @param callback a {@link OAuthAsyncRequestCallback} callback to invoke upon response completion - * @param converter an optional {@link OAuthRequest.ResponseConverter} result converter for {@link Response} - * @param aggregatedResponse a source {@link AggregatedHttpResponse} to handle - * @param converter {@link OAuthRequest.ResponseConverter} specific type or {@link Response} - * @return either instance of {@link Response} or converted result based on {@link OAuthRequest.ResponseConverter} - */ - private T whenResponseComplete(OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter, AggregatedHttpResponse aggregatedResponse) { - final Response response = convertResponse(aggregatedResponse); - try { - @SuppressWarnings("unchecked") final T t = - converter == null ? (T) response : converter.convert(response); - if (callback != null) { - callback.onCompleted(t); - } - return t; - } catch (IOException | RuntimeException e) { - return completeExceptionally(callback, e); + + //------------------------------------------------------------------------------------------------ + /** + * Provides an instance of {@link WebClient} for a given endpoint {@link URI} based on an endpoint as + * {@code scheme://authority}. + * + * @param uri an endpoint {@link URI} + * @return {@link WebClient} instance + */ + private WebClient getClient(final URI uri) { + final String endpoint = getEndPoint(uri); + + WebClient client; + final Lock readLock = httpClientsLock.readLock(); + readLock.lock(); + try { + client = httpClients.get(endpoint); + } finally { + readLock.unlock(); + } + + if (client != null) { + return client; + } + + client = clientBuilder.newWebClient( + requireNonNull(uri.getScheme(), "scheme"), + requireNonNull(uri.getAuthority(), "authority")); + + final Lock writeLock = httpClientsLock.writeLock(); + writeLock.lock(); + try { + if (!httpClients.containsKey(endpoint)) { + httpClients.put(endpoint, client); + return client; + } else { + return httpClients.get(endpoint); + } + } finally { + writeLock.unlock(); + } } - } - - /** - * Invokes {@link OAuthAsyncRequestCallback} upon {@link Throwable} error result - * @param callback a {@link OAuthAsyncRequestCallback} callback to invoke upon response completion - * @param throwable a {@link Throwable} error result - * @param converter {@link OAuthRequest.ResponseConverter} specific type or {@link Response} - * @return null - */ - private T completeExceptionally(OAuthAsyncRequestCallback callback, Throwable throwable) { - if (callback != null) { - callback.onThrowable(throwable); + + /** + * Extracts {@code scheme} and {@code authority} portion of the {@link URI}. Assuming the {@link URI} as the + * following: {@code URI = scheme:[//authority]path[?query][#fragment]} + */ + @SuppressWarnings("StringBufferReplaceableByString") + private static String getEndPoint(final URI uri) { + final StringBuilder builder = new StringBuilder() + .append(requireNonNull(uri.getScheme(), "scheme")) + .append("://").append(requireNonNull(uri.getAuthority(), "authority")); + return builder.toString(); } - return null; - } - //------------------------------------------------------------------------------------------------ - // Body type suppliers + /** + * Extracts {@code path}, {@code query) and {@code fragment} portion of the {@link URI}. + * Assuming the {@link URI} as the following: + * {@code URI = scheme:[//authority]path[?query][#fragment]} + */ + private static String getServicePath(final URI uri) { + final StringBuilder builder = new StringBuilder() + .append(requireNonNull(uri.getPath(), "path")); + final String query = uri.getQuery(); + if (query != null) { + builder.append('?').append(query); + } + final String fragment = uri.getFragment(); + if (fragment != null) { + builder.append('#').append(fragment); + } + return builder.toString(); + } - private static class BytesBody implements Supplier { + /** + * Maps {@link Verb} to {@link HttpMethod} + * + * @param httpVerb a {@link Verb} to match with {@link HttpMethod} + * @return {@link HttpMethod} corresponding to the parameter + */ + private static HttpMethod getHttpMethod(final Verb httpVerb) { + switch (httpVerb) { + case GET: + return HttpMethod.GET; + case POST: + return HttpMethod.POST; + case PUT: + return HttpMethod.PUT; + case DELETE: + return HttpMethod.DELETE; + case HEAD: + return HttpMethod.HEAD; + case OPTIONS: + return HttpMethod.OPTIONS; + case TRACE: + return HttpMethod.TRACE; + case PATCH: + return HttpMethod.PATCH; + default: + throw new IllegalArgumentException( + "message build error: unsupported HTTP method: " + httpVerb.name()); + } + } - private final byte[] bodyContents; + //------------------------------------------------------------------------------------------------ + // Response asynchronous handlers + /** + * Converts {@link AggregatedHttpResponse} to {@link Response} + * + * @param aggregatedResponse an instance of {@link AggregatedHttpResponse} to convert to {@link Response} + * @return a {@link Response} converted from {@link AggregatedHttpResponse} + */ + private Response convertResponse(final AggregatedHttpResponse aggregatedResponse) { + final Map headersMap = new HashMap<>(aggregatedResponse.headers().size()); + aggregatedResponse.headers() + .forEach((header, value) -> headersMap.put(header.toString(), value)); + return new Response(aggregatedResponse.status().code(), + aggregatedResponse.status().reasonPhrase(), + headersMap, aggregatedResponse.content().toInputStream()); + } - BytesBody(final byte[] bodyContents) { - this.bodyContents = bodyContents; + /** + * Converts {@link AggregatedHttpResponse} to {@link Response} upon its aggregation completion and invokes + * {@link OAuthAsyncRequestCallback} for it. + * + * @param callback a {@link OAuthAsyncRequestCallback} callback to invoke upon response completion + * @param converter an optional {@link OAuthRequest.ResponseConverter} result converter for {@link Response} + * @param aggregatedResponse a source {@link AggregatedHttpResponse} to handle + * @param converter {@link OAuthRequest.ResponseConverter} specific type or {@link Response} + * @return either instance of {@link Response} or converted result based on {@link OAuthRequest.ResponseConverter} + */ + private T whenResponseComplete(OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter, AggregatedHttpResponse aggregatedResponse) { + final Response response = convertResponse(aggregatedResponse); + try { + @SuppressWarnings("unchecked") + final T t + = converter == null ? (T) response : converter.convert(response); + if (callback != null) { + callback.onCompleted(t); + } + return t; + } catch (IOException | RuntimeException e) { + return completeExceptionally(callback, e); + } } - @Override - public HttpData get() { - return (bodyContents != null) ? HttpData.wrap(bodyContents) : null; + /** + * Invokes {@link OAuthAsyncRequestCallback} upon {@link Throwable} error result + * + * @param callback a {@link OAuthAsyncRequestCallback} callback to invoke upon response completion + * @param throwable a {@link Throwable} error result + * @param converter {@link OAuthRequest.ResponseConverter} specific type or {@link Response} + * @return null + */ + private T completeExceptionally(OAuthAsyncRequestCallback callback, Throwable throwable) { + if (callback != null) { + callback.onThrowable(throwable); + } + return null; } - } - private static class StringBody implements Supplier { + //------------------------------------------------------------------------------------------------ + // Body type suppliers + private static class BytesBody implements Supplier { - private final String bodyContents; + private final byte[] bodyContents; - StringBody(final String bodyContents) { - this.bodyContents = bodyContents; - } + BytesBody(final byte[] bodyContents) { + this.bodyContents = bodyContents; + } - @Override - public HttpData get() { - return (bodyContents != null) ? HttpData.ofUtf8(bodyContents) : null; + @Override + public HttpData get() { + return (bodyContents != null) ? HttpData.wrap(bodyContents) : null; + } } - } - private static class FileBody implements Supplier { + private static class StringBody implements Supplier { - private final File bodyContents; + private final String bodyContents; - FileBody(final File bodyContents) { - this.bodyContents = bodyContents; - } + StringBody(final String bodyContents) { + this.bodyContents = bodyContents; + } - @Override - public HttpData get() { - try { - return (bodyContents != null) - ? HttpData.wrap(Files.readAllBytes(bodyContents.toPath())) - : null; - } catch (IOException e) { - throw new RuntimeException(e); - } + @Override + public HttpData get() { + return (bodyContents != null) ? HttpData.ofUtf8(bodyContents) : null; + } } - } - private static class MultipartBody implements Supplier { + private static class FileBody implements Supplier { + + private final File bodyContents; - private final MultipartPayload bodyContents; + FileBody(final File bodyContents) { + this.bodyContents = bodyContents; + } - MultipartBody(final MultipartPayload bodyContents) { - this.bodyContents = bodyContents; + @Override + public HttpData get() { + try { + return (bodyContents != null) + ? HttpData.wrap(Files.readAllBytes(bodyContents.toPath())) + : null; + } catch (IOException e) { + throw new RuntimeException(e); + } + } } - @Override - public HttpData get() { - try { - return (bodyContents != null) - ? HttpData.wrap(MultipartUtils.getPayload(bodyContents).toByteArray()) - : null; - } catch (IOException e) { - throw new RuntimeException(e); - } + private static class MultipartBody implements Supplier { + + private final MultipartPayload bodyContents; + + MultipartBody(final MultipartPayload bodyContents) { + this.bodyContents = bodyContents; + } + + @Override + public HttpData get() { + try { + return (bodyContents != null) + ? HttpData.wrap(MultipartUtils.getPayload(bodyContents).toByteArray()) + : null; + } catch (IOException e) { + throw new RuntimeException(e); + } + } } - } - //------------------------------------------------------------------------------------------------ + //------------------------------------------------------------------------------------------------ } diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java index 97b13e5c3..a0f503222 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java @@ -16,184 +16,175 @@ public class ArmeriaHttpClientConfig implements HttpClientConfig { - private static final SessionProtocol DEFAULT_PROTOCOL_PREFERENCE = SessionProtocol.H1; // H1 or H2 + private static final SessionProtocol DEFAULT_PROTOCOL_PREFERENCE = SessionProtocol.H1; // H1 or H2 - private final ClientOptions clientOptions; - private final ClientFactory clientFactory; - private SessionProtocol protocolPreference; - private Function retry; - private Function logging; + private final ClientOptions clientOptions; + private final ClientFactory clientFactory; + private SessionProtocol protocolPreference; + private Function retry; + private Function logging; - /** - * Creates new {@link ArmeriaHttpClientConfig} using provided {@link ClientOptions} and - * {@link ClientFactory}. - */ - public ArmeriaHttpClientConfig(ClientOptions clientOptions, ClientFactory clientFactory) { - this.clientOptions = clientOptions; - this.clientFactory = clientFactory; - protocolPreference = DEFAULT_PROTOCOL_PREFERENCE; - } + /** + * Creates new {@link ArmeriaHttpClientConfig} using provided {@link ClientOptions} and {@link ClientFactory}. + */ + public ArmeriaHttpClientConfig(ClientOptions clientOptions, ClientFactory clientFactory) { + this.clientOptions = clientOptions; + this.clientFactory = clientFactory; + protocolPreference = DEFAULT_PROTOCOL_PREFERENCE; + } - /** - * Creates new {@link ArmeriaHttpClientConfig} using default settings. - */ - ArmeriaHttpClientConfig() { - this(null, null); - } + /** + * Creates new {@link ArmeriaHttpClientConfig} using default settings. + */ + ArmeriaHttpClientConfig() { + this(null, null); + } - /** - * Creates new {@link HttpClientConfig} using default settings. - */ - @Override - public HttpClientConfig createDefaultConfig() { - return defaultConfig(); - } + /** + * Creates new {@link HttpClientConfig} using default settings. + */ + @Override + public HttpClientConfig createDefaultConfig() { + return defaultConfig(); + } - /** - * Creates new {@link ArmeriaHttpClientConfig} using default settings. - */ - public static ArmeriaHttpClientConfig defaultConfig() { - return new ArmeriaHttpClientConfig(); - } + /** + * Creates new {@link ArmeriaHttpClientConfig} using default settings. + */ + public static ArmeriaHttpClientConfig defaultConfig() { + return new ArmeriaHttpClientConfig(); + } - /** - * Selects which protocol shall take preference when generic protocol scheme used by the URL, - * like {@code http} or {@code https}. - * - * @param protocolPreference specifies which protocol shall take preference. - * Acceptable values: {@code H1}, {@code HTTP1}, {@code HTTP/1.1} for - * {@code HTTP/1.1} and {@code H2}, {@code HTTP2}, {@code HTTP/2} for - * {@code HTTP/2}. - */ - public void protocolPreference(String protocolPreference) { - switch (protocolPreference.toUpperCase()) { - case "H1": - case "HTTP1": - case "HTTP/1.1": - this.protocolPreference = SessionProtocol.H1; - break; - case "H2": - case "HTTP2": - case "HTTP/2": - this.protocolPreference = SessionProtocol.H2; - break; - default: - throw new IllegalArgumentException("Invalid protocolPreference: " + protocolPreference); + /** + * Selects which protocol shall take preference when generic protocol scheme used by the URL, like {@code http} or + * {@code https}. + * + * @param protocolPreference specifies which protocol shall take preference. Acceptable values: {@code H1}, + * {@code HTTP1}, {@code HTTP/1.1} for {@code HTTP/1.1} and {@code H2}, {@code HTTP2}, {@code HTTP/2} for + * {@code HTTP/2}. + */ + public void protocolPreference(String protocolPreference) { + switch (protocolPreference.toUpperCase()) { + case "H1": + case "HTTP1": + case "HTTP/1.1": + this.protocolPreference = SessionProtocol.H1; + break; + case "H2": + case "HTTP2": + case "HTTP/2": + this.protocolPreference = SessionProtocol.H2; + break; + default: + throw new IllegalArgumentException("Invalid protocolPreference: " + protocolPreference); + } } - } - /** - * Selects which protocol shall take preference when generic protocol scheme used by the URL, - * like {@code http} or {@code https}. - * - * @param protocolPreference specifies which protocol shall take preference. - * Acceptable values: {@link SessionProtocol#H1} and - * {@link SessionProtocol#H2} - */ - public void protocolPreference(SessionProtocol protocolPreference) { - switch (protocolPreference) { - case H1: - this.protocolPreference = SessionProtocol.H1; - break; - case H2: - this.protocolPreference = SessionProtocol.H2; - break; - default: - throw new IllegalArgumentException("Invalid protocolPreference: " + protocolPreference); + /** + * Selects which protocol shall take preference when generic protocol scheme used by the URL, like {@code http} or + * {@code https}. + * + * @param protocolPreference specifies which protocol shall take preference. Acceptable values: + * {@link SessionProtocol#H1} and {@link SessionProtocol#H2} + */ + public void protocolPreference(SessionProtocol protocolPreference) { + switch (protocolPreference) { + case H1: + this.protocolPreference = SessionProtocol.H1; + break; + case H2: + this.protocolPreference = SessionProtocol.H2; + break; + default: + throw new IllegalArgumentException("Invalid protocolPreference: " + protocolPreference); + } } - } - /** - * Sets the client to retry when the remote end-point responds with one of the - * specified {@code statuses}. - * - * Uses a backoff that computes a delay using one of supported functions, such as - * {@code exponential(long, long, double)}, {@code fibonacci(long, long)}, {@code fixed(long)} - * and {@code random(long, long)} chaining with {@code withJitter(double, double)} and - * {@code withMaxAttempts(int)} from the {@code backoff} string that conforms to - * the following format: - *
      - *
    • {@code exponential=[initialDelayMillis:maxDelayMillis:multiplier]} is for - * {@code exponential(long, long, double)} (multiplier will be 2.0 if it's omitted)
    • - *
    • {@code fibonacci=[initialDelayMillis:maxDelayMillis]} is for - * {@code fibonacci(long, long)}
    • - *
    • {@code fixed=[delayMillis]} is for {@code fixed(long)}
    • - *
    • {@code random=[minDelayMillis:maxDelayMillis]} is for {@code random(long, long)}
    • - *
    • {@code jitter=[minJitterRate:maxJitterRate]} is for {@code withJitter(double, double)} - * (if only one jitter value is specified, it will be used for {@code withJitter(double)}
    • - *
    • {@code maxAttempts=[maxAttempts]} is for {@code withMaxAttempts(int)}
    • - *
    - * The order of options does not matter, and the {@code backoff} needs at least one option. - * If you don't specify the base option exponential backoff will be used. If you only specify - * a base option, jitter and maxAttempts will be set by default values. For example: - *
      - *
    • {@code exponential=200:10000:2.0,jitter=0.2} (default)
    • - *
    • {@code exponential=200:10000,jitter=0.2,maxAttempts=50} (multiplier omitted)
    • - *
    • {@code fibonacci=200:10000,jitter=0.2,maxAttempts=50}
    • - *
    • {@code fixed=100,jitter=-0.5:0.2,maxAttempts=10} (fixed backoff with jitter variation)
    • - *
    • {@code random=200:1000} (jitter and maxAttempts will be set by default values)
    • - *
    - * - * @param backoff the specification used to create a retry backoff - * @param statuses the list of HTTP statuses on which to retry - */ - public void retry(String backoff, HttpStatus... statuses) { - final Backoff retryBackoff = Backoff.of(backoff); - final RetryRule retryRule = - RetryRule.builder().onStatus(statuses).onUnprocessed().thenBackoff(retryBackoff); - retry = RetryingClient.newDecorator(retryRule); - } + /** + * Sets the client to retry when the remote end-point responds with one of the specified {@code statuses}. + * + * Uses a backoff that computes a delay using one of supported functions, such as + * {@code exponential(long, long, double)}, {@code fibonacci(long, long)}, {@code fixed(long)} and + * {@code random(long, long)} chaining with {@code withJitter(double, double)} and {@code withMaxAttempts(int)} from + * the {@code backoff} string that conforms to the following format: + *
      + *
    • {@code exponential=[initialDelayMillis:maxDelayMillis:multiplier]} is for + * {@code exponential(long, long, double)} (multiplier will be 2.0 if it's omitted)
    • + *
    • {@code fibonacci=[initialDelayMillis:maxDelayMillis]} is for {@code fibonacci(long, long)}
    • + *
    • {@code fixed=[delayMillis]} is for {@code fixed(long)}
    • + *
    • {@code random=[minDelayMillis:maxDelayMillis]} is for {@code random(long, long)}
    • + *
    • {@code jitter=[minJitterRate:maxJitterRate]} is for {@code withJitter(double, double)} (if only one jitter + * value is specified, it will be used for {@code withJitter(double)}
    • + *
    • {@code maxAttempts=[maxAttempts]} is for {@code withMaxAttempts(int)}
    • + *
    + * The order of options does not matter, and the {@code backoff} needs at least one option. If you don't specify the + * base option exponential backoff will be used. If you only specify a base option, jitter and maxAttempts will be + * set by default values. For example: + *
      + *
    • {@code exponential=200:10000:2.0,jitter=0.2} (default)
    • + *
    • {@code exponential=200:10000,jitter=0.2,maxAttempts=50} (multiplier omitted)
    • + *
    • {@code fibonacci=200:10000,jitter=0.2,maxAttempts=50}
    • + *
    • {@code fixed=100,jitter=-0.5:0.2,maxAttempts=10} (fixed backoff with jitter variation)
    • + *
    • {@code random=200:1000} (jitter and maxAttempts will be set by default values)
    • + *
    + * + * @param backoff the specification used to create a retry backoff + * @param statuses the list of HTTP statuses on which to retry + */ + public void retry(String backoff, HttpStatus... statuses) { + final Backoff retryBackoff = Backoff.of(backoff); + final RetryRule retryRule + = RetryRule.builder().onStatus(statuses).onUnprocessed().thenBackoff(retryBackoff); + retry = RetryingClient.newDecorator(retryRule); + } - /** - * Sets the client to log requests and responses to the specified {@code logger}. - * This method explicitly specifies various log levels. The log level correspond to a value - * of {@link LogLevel} and must use one of the following values: - * {@code ["OFF", "TRACE", "DEBUG", "INFO", "WARN", "ERROR"]} - * - * @param logger the logger name (of {@link org.slf4j.Logger}) to log requests/responses to - * @param requestLevel the log level to use for logging requests, default {@code "DEBUG"} - * @param responseLevel the log level to use for logging responses, default {@code "DEBUG"} - * @param failureResponseLevel the log level to use for logging error responses, - * default {@code "WARN"} - */ - public void logging(String logger, String requestLevel, String responseLevel, - String failureResponseLevel) { - this.logging = LoggingClient.builder() - .logger(LoggerFactory.getLogger(logger)) - .requestLogLevel(LogLevel.valueOf(requestLevel)) - .successfulResponseLogLevel(LogLevel.valueOf(responseLevel)) - .failureResponseLogLevel(LogLevel.valueOf(failureResponseLevel)) - .newDecorator(); - } + /** + * Sets the client to log requests and responses to the specified {@code logger}. This method explicitly specifies + * various log levels. The log level correspond to a value of {@link LogLevel} and must use one of the following + * values: {@code ["OFF", "TRACE", "DEBUG", "INFO", "WARN", "ERROR"]} + * + * @param logger the logger name (of {@link org.slf4j.Logger}) to log requests/responses to + * @param requestLevel the log level to use for logging requests, default {@code "DEBUG"} + * @param responseLevel the log level to use for logging responses, default {@code "DEBUG"} + * @param failureResponseLevel the log level to use for logging error responses, default {@code "WARN"} + */ + public void logging(String logger, String requestLevel, String responseLevel, + String failureResponseLevel) { + this.logging = LoggingClient.builder() + .logger(LoggerFactory.getLogger(logger)) + .requestLogLevel(LogLevel.valueOf(requestLevel)) + .successfulResponseLogLevel(LogLevel.valueOf(responseLevel)) + .failureResponseLogLevel(LogLevel.valueOf(failureResponseLevel)) + .newDecorator(); + } - /** - * Sets the client to log requests and responses to the specified {@code logger} using default - * log levels. - * - * @param logger the logger name (of {@link org.slf4j.Logger}) to log requests/responses to - */ - public void logging(String logger) { - this.logging = LoggingClient.builder() - .logger(LoggerFactory.getLogger(logger)) - .requestLogLevel(LogLevel.DEBUG) - .successfulResponseLogLevel(LogLevel.DEBUG) - .failureResponseLogLevel(LogLevel.WARN) - .newDecorator(); - } + /** + * Sets the client to log requests and responses to the specified {@code logger} using default log levels. + * + * @param logger the logger name (of {@link org.slf4j.Logger}) to log requests/responses to + */ + public void logging(String logger) { + this.logging = LoggingClient.builder() + .logger(LoggerFactory.getLogger(logger)) + .requestLogLevel(LogLevel.DEBUG) + .successfulResponseLogLevel(LogLevel.DEBUG) + .failureResponseLogLevel(LogLevel.WARN) + .newDecorator(); + } - /** - * Sets the client to log requests and responses to a default logger using default log levels. - */ - public void logging() { - this.logging = LoggingClient.builder() - .requestLogLevel(LogLevel.DEBUG) - .successfulResponseLogLevel(LogLevel.DEBUG) - .failureResponseLogLevel(LogLevel.WARN) - .newDecorator(); - } + /** + * Sets the client to log requests and responses to a default logger using default log levels. + */ + public void logging() { + this.logging = LoggingClient.builder() + .requestLogLevel(LogLevel.DEBUG) + .successfulResponseLogLevel(LogLevel.DEBUG) + .failureResponseLogLevel(LogLevel.WARN) + .newDecorator(); + } - ArmeriaWebClientBuilder builder() { - return new ArmeriaWebClientBuilder(clientOptions, clientFactory, protocolPreference, - retry, logging); - } + ArmeriaWebClientBuilder builder() { + return new ArmeriaWebClientBuilder(clientOptions, clientFactory, protocolPreference, + retry, logging); + } } diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaProvider.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaProvider.java index b352a8b07..323eb7599 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaProvider.java +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaProvider.java @@ -6,11 +6,11 @@ public class ArmeriaProvider implements HttpClientProvider { - @Override - public HttpClient createClient(HttpClientConfig config) { - if (config instanceof ArmeriaHttpClientConfig) { - return new ArmeriaHttpClient((ArmeriaHttpClientConfig) config); + @Override + public HttpClient createClient(HttpClientConfig config) { + if (config instanceof ArmeriaHttpClientConfig) { + return new ArmeriaHttpClient((ArmeriaHttpClientConfig) config); + } + return null; } - return null; - } } diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaWebClientBuilder.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaWebClientBuilder.java index e79c9c27c..6972fadd0 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaWebClientBuilder.java +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaWebClientBuilder.java @@ -16,59 +16,59 @@ */ public class ArmeriaWebClientBuilder { - private final ClientFactory clientFactory; - private final ClientOptions clientOptions; - private final SessionProtocol protocolPreference; - private final Function retry; - private final Function logging; + private final ClientFactory clientFactory; + private final ClientOptions clientOptions; + private final SessionProtocol protocolPreference; + private final Function retry; + private final Function logging; - ArmeriaWebClientBuilder(ClientOptions clientOptions, ClientFactory clientFactory, - SessionProtocol protocolPreference, Function retry, - Function logging) { - this.clientOptions = clientOptions; - this.clientFactory = clientFactory; - this.protocolPreference = protocolPreference; - this.retry = retry; - this.logging = logging; - } - - WebClient newWebClient(String scheme, String authority) { - final SessionProtocol protocol = protocol(scheme); - final Endpoint endpoint = Endpoint.parse(authority); - final WebClientBuilder clientBuilder = WebClient.builder(protocol, endpoint); - if (clientOptions != null) { - clientBuilder.options(clientOptions); - } - if (clientFactory != null) { - clientBuilder.factory(clientFactory); - } - if (retry != null) { - clientBuilder.decorator(retry); + ArmeriaWebClientBuilder(ClientOptions clientOptions, ClientFactory clientFactory, + SessionProtocol protocolPreference, Function retry, + Function logging) { + this.clientOptions = clientOptions; + this.clientFactory = clientFactory; + this.protocolPreference = protocolPreference; + this.retry = retry; + this.logging = logging; } - if (logging != null) { - clientBuilder.decorator(logging); - } - return clientBuilder.build(); - } - private SessionProtocol protocol(String scheme) { - final SessionProtocol protocol = SessionProtocol.of(scheme); - switch(protocol) { - case HTTP: - if (protocolPreference == SessionProtocol.H1) { - // enforce HTTP/1 protocol - return SessionProtocol.H1C; + WebClient newWebClient(String scheme, String authority) { + final SessionProtocol protocol = protocol(scheme); + final Endpoint endpoint = Endpoint.parse(authority); + final WebClientBuilder clientBuilder = WebClient.builder(protocol, endpoint); + if (clientOptions != null) { + clientBuilder.options(clientOptions); + } + if (clientFactory != null) { + clientBuilder.factory(clientFactory); } - break; - case HTTPS: - if (protocolPreference == SessionProtocol.H1) { - // enforce HTTP/1 protocol - return SessionProtocol.H1; + if (retry != null) { + clientBuilder.decorator(retry); + } + if (logging != null) { + clientBuilder.decorator(logging); + } + return clientBuilder.build(); + } + + private SessionProtocol protocol(String scheme) { + final SessionProtocol protocol = SessionProtocol.of(scheme); + switch (protocol) { + case HTTP: + if (protocolPreference == SessionProtocol.H1) { + // enforce HTTP/1 protocol + return SessionProtocol.H1C; + } + break; + case HTTPS: + if (protocolPreference == SessionProtocol.H1) { + // enforce HTTP/1 protocol + return SessionProtocol.H1; + } + break; + default: + break; } - break; - default: - break; + return protocol; } - return protocol; - } } diff --git a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java index 1078a563c..728668e8f 100644 --- a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java +++ b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java @@ -18,57 +18,55 @@ public class ArmeriaHttpClientTest extends AbstractClientTest { - @Override - protected HttpClient createNewClient() { - // simulate DNS resolution for a mock address ("kubernetes.docker.internal") - final Function> - addressResolverGroupFactory = eventLoopGroup -> new MockAddressResolverGroup(); - // No-Op DNS resolver to avoid resolution issues in the unit test - final ClientFactory clientFactory = - ClientFactory.builder().addressResolverGroupFactory(addressResolverGroupFactory).build(); - final ArmeriaHttpClientConfig config = new ArmeriaHttpClientConfig(null, clientFactory); - // enable client-side HTTP tracing - config.logging("HTTP_TRACE", "INFO", "INFO", "WARN"); - // enable request retry - config.retry("exponential=200:10000,jitter=0.2,maxAttempts=5", HttpStatus.SERVICE_UNAVAILABLE); - return new ArmeriaHttpClient(config); - } + @Override + protected HttpClient createNewClient() { + // simulate DNS resolution for a mock address ("kubernetes.docker.internal") + final Function> addressResolverGroupFactory = eventLoopGroup -> new MockAddressResolverGroup(); + // No-Op DNS resolver to avoid resolution issues in the unit test + final ClientFactory clientFactory + = ClientFactory.builder().addressResolverGroupFactory(addressResolverGroupFactory).build(); + final ArmeriaHttpClientConfig config = new ArmeriaHttpClientConfig(null, clientFactory); + // enable client-side HTTP tracing + config.logging("HTTP_TRACE", "INFO", "INFO", "WARN"); + // enable request retry + config.retry("exponential=200:10000,jitter=0.2,maxAttempts=5", HttpStatus.SERVICE_UNAVAILABLE); + return new ArmeriaHttpClient(config); + } - //------------------------------------------------------------------------------------------------ - // No-Op DNS resolver to avoid resolution issues in the unit test + //------------------------------------------------------------------------------------------------ + // No-Op DNS resolver to avoid resolution issues in the unit test + static class MockAddressResolverGroup extends AddressResolverGroup { - static class MockAddressResolverGroup extends AddressResolverGroup { + private MockAddressResolverGroup() { + } - private MockAddressResolverGroup() { + protected AddressResolver newResolver(EventExecutor executor) { + return new MockAddressResolver(executor); + } } - protected AddressResolver newResolver(EventExecutor executor) { - return new MockAddressResolver(executor); - } - } + static class MockAddressResolver extends AbstractAddressResolver { - static class MockAddressResolver extends AbstractAddressResolver { + private MockAddressResolver(EventExecutor executor) { + super(executor); + } - private MockAddressResolver(EventExecutor executor) { - super(executor); - } + protected boolean doIsResolved(InetSocketAddress address) { + return !address.isUnresolved(); + } - protected boolean doIsResolved(InetSocketAddress address) { - return !address.isUnresolved(); - } - - private InetSocketAddress resolveToLoopback(InetSocketAddress unresolvedAddress) { - return new InetSocketAddress(InetAddress.getLoopbackAddress(), unresolvedAddress.getPort()); - } + private InetSocketAddress resolveToLoopback(InetSocketAddress unresolvedAddress) { + return new InetSocketAddress(InetAddress.getLoopbackAddress(), unresolvedAddress.getPort()); + } - protected void doResolve(InetSocketAddress unresolvedAddress, Promise promise) { - promise.setSuccess(resolveToLoopback(unresolvedAddress)); - } + protected void doResolve(InetSocketAddress unresolvedAddress, Promise promise) { + promise.setSuccess(resolveToLoopback(unresolvedAddress)); + } - protected void doResolveAll(InetSocketAddress unresolvedAddress, Promise> promise) { - promise.setSuccess(Collections.singletonList(resolveToLoopback(unresolvedAddress))); + protected void doResolveAll(InetSocketAddress unresolvedAddress, Promise> promise) { + promise.setSuccess(Collections.singletonList(resolveToLoopback(unresolvedAddress))); + } } - } - //------------------------------------------------------------------------------------------------ + //------------------------------------------------------------------------------------------------ } From eccd3dd165e28447b7b6f9c574c7ab2289c42617 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Sat, 1 Aug 2020 20:04:50 +0300 Subject: [PATCH 385/481] Add Armeria HTTP client (thanks to https://github.com/max904-github) --- README.md | 1 + changelog | 3 +- pom.xml | 3 + scribejava-apis/pom.xml | 6 + .../apis/examples/Google20ArmeriaExample.java | 118 ++++++ .../core/httpclient/jdk/JDKHttpClient.java | 53 +-- .../multipart/MultipartPayload.java | 52 ++- .../httpclient/multipart/MultipartUtils.java | 35 +- .../httpclient/jdk/JDKHttpClientTest.java | 268 ------------- .../multipart/MultipartPayloadTest.java | 108 ----- .../multipart/MultipartUtilsTest.java | 371 ++++++++++++++++++ .../httpclient/ahc/AhcHttpClient.java | 9 +- scribejava-httpclient-armeria/pom.xml | 28 +- .../httpclient/armeria/ArmeriaHttpClient.java | 126 +++--- .../armeria/ArmeriaHttpClientConfig.java | 146 +------ .../armeria/ArmeriaHttpClientTest.java | 43 +- 16 files changed, 683 insertions(+), 687 deletions(-) create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20ArmeriaExample.java rename {scribejava-httpclient-armeria => scribejava-core}/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java (58%) delete mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java diff --git a/README.md b/README.md index 199e1c7a5..aa3645dc5 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ ScribeJava support out-of-box several HTTP clients: * Async Http Client asynchttpclient 2.x (maven module scribejava-httpclient-ahc) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20AsyncAHCExample.java) * OkHttp (maven module scribejava-httpclient-okhttp) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/GitHubAsyncOkHttpExample.java) * Apache HttpComponents HttpClient (maven module scribejava-httpclient-apache) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java) + * Armeria HTTP client (required >= java 8) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20ArmeriaExample.java) * any externally created HTTP client [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java) just add corresponding maven modules to your pom diff --git a/changelog b/changelog index 953ac5d16..2a5d5269a 100644 --- a/changelog +++ b/changelog @@ -2,7 +2,8 @@ * Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) * make Response accept resources to autoclose and autoclose it (thanks to https://github.com/drei01) * fix url encoding in POST payload (it's needed for 'application/x-www-form-urlencoded' Content-Type) - + unit tests (thanks to https://github.com/max904-github) + + unit tests (thanks to https://github.com/max904-github) + * Add Armeria HTTP client (thanks to https://github.com/max904-github) [6.9.0] * Add Xero API (https://www.xero.com/) (thanks to https://github.com/SidneyAllen) diff --git a/pom.xml b/pom.xml index a5119ada7..f067fb747 100644 --- a/pom.xml +++ b/pom.xml @@ -146,6 +146,9 @@ UTF-8 ${java.release} true + + -Xlint:-options +
    diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index fe2dd76c0..aac24aa20 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -44,6 +44,12 @@ ${project.version} test
    + + com.github.scribejava + scribejava-httpclient-armeria + ${project.version} + test + diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20ArmeriaExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20ArmeriaExample.java new file mode 100644 index 000000000..04fddb1da --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20ArmeriaExample.java @@ -0,0 +1,118 @@ +package com.github.scribejava.apis.examples; + +import java.util.Random; +import java.util.Scanner; +import com.github.scribejava.apis.GoogleApi20; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.httpclient.armeria.ArmeriaHttpClientConfig; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +public class Google20ArmeriaExample { + + private static final String NETWORK_NAME = "Google Armeria"; + private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/oauth2/v3/userinfo"; + + private Google20ArmeriaExample() { + } + + @SuppressWarnings("PMD.SystemPrintln") + public static void main(String... args) throws InterruptedException, ExecutionException, IOException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your client secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + + try (OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .defaultScope("profile") // replace with desired scope + .callback("http://example.com/callback") + .httpClientConfig(ArmeriaHttpClientConfig.defaultConfig()) + .build(GoogleApi20.instance())) { + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + //pass access_type=offline to get refresh token + //https://developers.google.com/identity/protocols/OAuth2WebServer#preparing-to-start-the-oauth-20-flow + final Map additionalParams = new HashMap<>(); + additionalParams.put("access_type", "offline"); + //force to reget refresh token (if user are asked not the first time) + additionalParams.put("prompt", "consent"); + final String authorizationUrl = service.createAuthorizationUrlBuilder() + .state(secretState) + .additionalParams(additionalParams) + .build(); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + System.out.println("Trading the Authorization Code for an Access Token..."); + OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + + "')"); + + System.out.println("Refreshing the Access Token..."); + accessToken = service.refreshAccessToken(accessToken.getRefreshToken()); + System.out.println("Refreshed the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + while (true) { + System.out.println("Paste fieldnames to fetch (leave empty to get profile, 'exit' to stop example)"); + System.out.print(">>"); + final String query = in.nextLine(); + System.out.println(); + + final String requestUrl; + if ("exit".equals(query)) { + break; + } else if (query == null || query.isEmpty()) { + requestUrl = PROTECTED_RESOURCE_URL; + } else { + requestUrl = PROTECTED_RESOURCE_URL + "?fields=" + query; + } + + final OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl); + service.signRequest(accessToken, request); + System.out.println(); + try (Response response = service.execute(request)) { + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } + System.out.println(); + } + } + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index 3f4648a77..a18617633 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -1,10 +1,9 @@ package com.github.scribejava.core.httpclient.jdk; import com.github.scribejava.core.exceptions.OAuthException; -import com.github.scribejava.core.httpclient.multipart.BodyPartPayload; import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.multipart.ByteArrayBodyPartPayload; import com.github.scribejava.core.httpclient.multipart.MultipartPayload; +import com.github.scribejava.core.httpclient.multipart.MultipartUtils; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; @@ -207,7 +206,7 @@ private static void addBody(HttpURLConnection connection, MultipartPayload multi } if (requiresBody) { - final ByteArrayOutputStream os = getPayload(multipartPayload); + final ByteArrayOutputStream os = MultipartUtils.getPayload(multipartPayload); final int contentLength = os.size(); final OutputStream outputStream = prepareConnectionForBodyAndGetOutputStream(connection, contentLength); if (contentLength > 0) { @@ -216,46 +215,16 @@ private static void addBody(HttpURLConnection connection, MultipartPayload multi } } + /** + * @param multipartPayload multipartPayload + * @return ByteArrayOutputStream + * @throws IOException + * @deprecated use {@link com.github.scribejava.core.httpclient.multipart.MultipartUtils#getPayload( + * com.github.scribejava.core.httpclient.multipart.MultipartPayload) } + */ + @Deprecated static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload) throws IOException { - final ByteArrayOutputStream os = new ByteArrayOutputStream(); - - final String preamble = multipartPayload.getPreamble(); - if (preamble != null) { - os.write(preamble.getBytes()); - } - final List bodyParts = multipartPayload.getBodyParts(); - if (!bodyParts.isEmpty()) { - final String boundary = multipartPayload.getBoundary(); - final byte[] startBoundary = ("\r\n--" + boundary + "\r\n").getBytes(); - - for (BodyPartPayload bodyPart : bodyParts) { - os.write(startBoundary); - - final Map bodyPartHeaders = bodyPart.getHeaders(); - if (bodyPartHeaders != null) { - for (Map.Entry header : bodyPartHeaders.entrySet()) { - os.write((header.getKey() + ": " + header.getValue() + "\r\n").getBytes()); - } - } - - if (bodyPart instanceof MultipartPayload) { - getPayload((MultipartPayload) bodyPart).writeTo(os); - } else if (bodyPart instanceof ByteArrayBodyPartPayload) { - os.write("\r\n".getBytes()); - os.write(((ByteArrayBodyPartPayload) bodyPart).getPayload()); - } else { - throw new AssertionError(bodyPart.getClass()); - } - } - - os.write(("\r\n--" + boundary + "--\r\n").getBytes()); - final String epilogue = multipartPayload.getEpilogue(); - if (epilogue != null) { - os.write((epilogue + "\r\n").getBytes()); - } - - } - return os; + return MultipartUtils.getPayload(multipartPayload); } private static OutputStream prepareConnectionForBodyAndGetOutputStream(HttpURLConnection connection, diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java index 7e3f8cfde..26efa66fe 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java @@ -5,16 +5,8 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; public class MultipartPayload extends BodyPartPayload { - private static final String B_CHARS_NO_SPACE_PATTERN = "0-9a-zA-Z'()+_,-./:=?"; - private static final String B_CHARS_PATTERN = B_CHARS_NO_SPACE_PATTERN + " "; - private static final String BOUNDARY_PATTERN = '[' + B_CHARS_PATTERN + "]{0,69}[" + B_CHARS_NO_SPACE_PATTERN + ']'; - private static final Pattern BOUNDARY_REGEXP = Pattern.compile(BOUNDARY_PATTERN); - private static final Pattern BOUNDARY_FROM_HEADER_REGEXP - = Pattern.compile("; boundary=\"?(" + BOUNDARY_PATTERN + ")\"?"); private static final String DEFAULT_SUBTYPE = "form-data"; @@ -24,7 +16,7 @@ public class MultipartPayload extends BodyPartPayload { private String epilogue; public MultipartPayload() { - this(null, generateDefaultBoundary(), null); + this(null, MultipartUtils.generateDefaultBoundary(), null); } public MultipartPayload(String boundary) { @@ -50,7 +42,7 @@ public MultipartPayload(String subtype, String boundary, Map hea private static Map composeHeaders(String subtype, String boundary, Map headersIn) throws IllegalArgumentException { - checkBoundarySyntax(boundary); + MultipartUtils.checkBoundarySyntax(boundary); final Map headersOut; String contentTypeHeader = headersIn == null ? null : headersIn.get(HttpClient.CONTENT_TYPE); if (contentTypeHeader == null) { @@ -64,7 +56,7 @@ private static Map composeHeaders(String subtype, String boundar } } else { headersOut = headersIn; - final String parsedBoundary = parseBoundaryFromHeader(contentTypeHeader); + final String parsedBoundary = MultipartUtils.parseBoundaryFromHeader(contentTypeHeader); if (parsedBoundary == null) { headersOut.put(HttpClient.CONTENT_TYPE, contentTypeHeader + "; boundary=\"" + boundary + '"'); } else if (!parsedBoundary.equals(boundary)) { @@ -75,28 +67,32 @@ private static Map composeHeaders(String subtype, String boundar return headersOut; } + /** + * + * @param boundary boundary + * @deprecated use + * {@link com.github.scribejava.core.httpclient.multipart.MultipartUtils#checkBoundarySyntax(java.lang.String)} + */ + @Deprecated static void checkBoundarySyntax(String boundary) { - if (boundary == null || !BOUNDARY_REGEXP.matcher(boundary).matches()) { - throw new IllegalArgumentException("{'boundary'='" + boundary + "'} has invalid syntax. Should be '" - + BOUNDARY_PATTERN + "'."); - } + MultipartUtils.checkBoundarySyntax(boundary); } private static String parseOrGenerateBoundary(Map headers) { - final String parsedBoundary = parseBoundaryFromHeader(headers.get(HttpClient.CONTENT_TYPE)); - return parsedBoundary == null ? generateDefaultBoundary() : parsedBoundary; - } - - private static String generateDefaultBoundary() { - return "----ScribeJava----" + System.currentTimeMillis(); - } - + final String parsedBoundary = MultipartUtils.parseBoundaryFromHeader(headers.get(HttpClient.CONTENT_TYPE)); + return parsedBoundary == null ? MultipartUtils.generateDefaultBoundary() : parsedBoundary; + } + + /** + * + * @param contentTypeHeader contentTypeHeader + * @return String + * @deprecated use + * {@link com.github.scribejava.core.httpclient.multipart.MultipartUtils#parseBoundaryFromHeader(java.lang.String)} + */ + @Deprecated static String parseBoundaryFromHeader(String contentTypeHeader) { - if (contentTypeHeader == null) { - return null; - } - final Matcher matcher = BOUNDARY_FROM_HEADER_REGEXP.matcher(contentTypeHeader); - return matcher.find() ? matcher.group(1) : null; + return MultipartUtils.parseBoundaryFromHeader(contentTypeHeader); } public void addFileBodyPart(byte[] fileContent) { diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java similarity index 58% rename from scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java rename to scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java index f995e4b4e..dc42d4d60 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java @@ -4,10 +4,40 @@ import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; -public abstract class MultipartUtils { +public class MultipartUtils { + + private static final String B_CHARS_NO_SPACE_PATTERN = "0-9a-zA-Z'()+_,-./:=?"; + private static final String B_CHARS_PATTERN = B_CHARS_NO_SPACE_PATTERN + " "; + private static final String BOUNDARY_PATTERN = '[' + B_CHARS_PATTERN + "]{0,69}[" + B_CHARS_NO_SPACE_PATTERN + ']'; + private static final Pattern BOUNDARY_REGEXP = Pattern.compile(BOUNDARY_PATTERN); + private static final Pattern BOUNDARY_FROM_HEADER_REGEXP + = Pattern.compile("; boundary=\"?(" + BOUNDARY_PATTERN + ")\"?"); + + private MultipartUtils() { + } + + public static void checkBoundarySyntax(String boundary) { + if (boundary == null || !BOUNDARY_REGEXP.matcher(boundary).matches()) { + throw new IllegalArgumentException("{'boundary'='" + boundary + "'} has invalid syntax. Should be '" + + BOUNDARY_PATTERN + "'."); + } + } + + public static String parseBoundaryFromHeader(String contentTypeHeader) { + if (contentTypeHeader == null) { + return null; + } + final Matcher matcher = BOUNDARY_FROM_HEADER_REGEXP.matcher(contentTypeHeader); + return matcher.find() ? matcher.group(1) : null; + } + + public static String generateDefaultBoundary() { + return "----ScribeJava----" + System.currentTimeMillis(); + } - // copied from com.github.scribejava.core.httpclient.jdk.JDKHttpClient#getPayload public static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload) throws IOException { final ByteArrayOutputStream os = new ByteArrayOutputStream(); @@ -49,5 +79,4 @@ public static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload } return os; } - } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java index 79a4a23f0..6ac1070fa 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientTest.java @@ -2,15 +2,6 @@ import com.github.scribejava.core.AbstractClientTest; import com.github.scribejava.core.httpclient.HttpClient; -import com.github.scribejava.core.httpclient.multipart.ByteArrayBodyPartPayload; -import com.github.scribejava.core.httpclient.multipart.FileByteArrayBodyPartPayload; -import com.github.scribejava.core.httpclient.multipart.MultipartPayload; -import java.io.IOException; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; -import org.junit.Assert; -import org.junit.Test; public class JDKHttpClientTest extends AbstractClientTest { @@ -18,263 +9,4 @@ public class JDKHttpClientTest extends AbstractClientTest { protected HttpClient createNewClient() { return new JDKHttpClient(); } - - @Test - public void testEmptyMultipartPayload() throws IOException { - final MultipartPayload mP = new MultipartPayload(); - - final StringBuilder sb = new StringBuilder(); - for (Map.Entry header : mP.getHeaders().entrySet()) { - sb.append(header.getKey()) - .append(": ") - .append(header.getValue()) - .append("\r\n"); - } - - sb.append("\r\n").append(JDKHttpClient.getPayload(mP).toString()); - Assert.assertEquals("Content-Type: multipart/form-data; boundary=\"" + mP.getBoundary() + "\"\r\n\r\n", - sb.toString()); - } - - @Test - public void testSimpleMultipartPayload() throws IOException { - final Map headers = new LinkedHashMap<>(); - headers.put("X-Header", "X-Value"); - headers.put("Content-Disposition", "Content-Disposition-Value"); - final MultipartPayload mP = new MultipartPayload("mixed", "simple boundary", headers); - mP.setPreamble("This is the preamble. It is to be ignored, though it\n" - + "is a handy place for composition agents to include an\n" - + "explanatory note to non-MIME conformant readers."); - - mP.addBodyPart(("This is implicitly typed plain US-ASCII text.\n" - + "It does NOT end with a linebreak.").getBytes()); - - final ByteArrayBodyPartPayload bP = new ByteArrayBodyPartPayload( - ("This is explicitly typed plain US-ASCII text.\n" - + "It DOES end with a linebreak.\n").getBytes(), - Collections.singletonMap(HttpClient.CONTENT_TYPE, "text/plain; charset=us-ascii")); - mP.addBodyPart(bP); - - mP.setEpilogue("This is the epilogue. It is also to be ignored."); - - final StringBuilder sb = new StringBuilder(); - for (Map.Entry header : mP.getHeaders().entrySet()) { - sb.append(header.getKey()) - .append(": ") - .append(header.getValue()) - .append("\r\n"); - } - sb.append("\r\n").append(JDKHttpClient.getPayload(mP).toString()); - Assert.assertEquals("X-Header: X-Value\r\n" - + "Content-Disposition: Content-Disposition-Value\r\n" - + "Content-Type: multipart/mixed; boundary=\"simple boundary\"\r\n" - + "\r\n" - + "This is the preamble. It is to be ignored, though it\n" - + "is a handy place for composition agents to include an\n" - + "explanatory note to non-MIME conformant readers." - + "\r\n" - + "--simple boundary\r\n" - + "\r\n" - + "This is implicitly typed plain US-ASCII text.\n" - + "It does NOT end with a linebreak." - + "\r\n" - + "--simple boundary\r\n" - + "Content-Type: text/plain; charset=us-ascii\r\n" - + "\r\n" - + "This is explicitly typed plain US-ASCII text.\n" - + "It DOES end with a linebreak.\n" - + "\r\n" - + "--simple boundary--\r\n" - + "This is the epilogue. It is also to be ignored.\r\n", - sb.toString()); - } - - @Test - public void testCRLFMultipartPayload() throws IOException { - final MultipartPayload mP = new MultipartPayload("simple-boundary"); - mP.addBodyPart("It does NOT end with a linebreak.".getBytes()); - mP.addBodyPart("It does end with a \\r linebreak.\r".getBytes()); - mP.addBodyPart("It does end with a \\n linebreak.\n".getBytes()); - mP.addBodyPart("It does end with a \\r\\n linebreak.\r\n".getBytes()); - mP.addBodyPart("the last one".getBytes()); - - final StringBuilder sb = new StringBuilder(); - for (Map.Entry header : mP.getHeaders().entrySet()) { - sb.append(header.getKey()) - .append(": ") - .append(header.getValue()) - .append("\r\n"); - } - sb.append("\r\n").append(JDKHttpClient.getPayload(mP).toString()); - Assert.assertEquals("Content-Type: multipart/form-data; boundary=\"simple-boundary\"\r\n" - + "\r\n" - + "\r\n" - + "--simple-boundary\r\n" - + "\r\n" - + "It does NOT end with a linebreak." - + "\r\n" - + "--simple-boundary\r\n" - + "\r\n" - + "It does end with a \\r linebreak.\r" - + "\r\n" - + "--simple-boundary\r\n" - + "\r\n" - + "It does end with a \\n linebreak.\n" - + "\r\n" - + "--simple-boundary\r\n" - + "\r\n" - + "It does end with a \\r\\n linebreak.\r\n" - + "\r\n" - + "--simple-boundary\r\n" - + "\r\n" - + "the last one" - + "\r\n" - + "--simple-boundary--\r\n", - sb.toString()); - } - - @Test - public void testFileByteArrayBodyPartPayloadMultipartPayload() throws IOException { - final MultipartPayload mP = new MultipartPayload("testFileByteArrayBodyPartPayloadMultipartPayload boundary"); - mP.addBodyPart(new FileByteArrayBodyPartPayload("fileContent".getBytes(), "name", "filename.ext")); - - final StringBuilder sb = new StringBuilder(); - for (Map.Entry header : mP.getHeaders().entrySet()) { - sb.append(header.getKey()) - .append(": ") - .append(header.getValue()) - .append("\r\n"); - } - - sb.append("\r\n").append(JDKHttpClient.getPayload(mP).toString()); - Assert.assertEquals("Content-Type: multipart/form-data; " - + "boundary=\"testFileByteArrayBodyPartPayloadMultipartPayload boundary\"\r\n" - + "\r\n" - + "\r\n" - + "--testFileByteArrayBodyPartPayloadMultipartPayload boundary\r\n" - + "Content-Disposition: form-data; name=\"name\"; filename=\"filename.ext\"\r\n" - + "\r\n" - + "fileContent" - + "\r\n" - + "--testFileByteArrayBodyPartPayloadMultipartPayload boundary--\r\n", - sb.toString() - ); - } - - @Test - public void testComplexMultipartPayload() throws IOException { - final MultipartPayload mP = new MultipartPayload("mixed", "unique-boundary-1"); - - mP.setPreamble("This is the preamble area of a multipart message.\n" - + "Mail readers that understand multipart format\n" - + "should ignore this preamble.\n" - + "\n" - + "If you are reading this text, you might want to\n" - + "consider changing to a mail reader that understands\n" - + "how to properly display multipart messages.\n"); - - mP.addBodyPart("... Some text appears here ...".getBytes()); - - mP.addBodyPart(("This could have been part of the previous part, but\n" - + "illustrates explicit versus implicit typing of body\n" - + "parts.\n").getBytes(), "text/plain; charset=US-ASCII"); - - final MultipartPayload innerMP = new MultipartPayload("parallel", "unique-boundary-2"); - mP.addBodyPart(innerMP); - - final Map audioHeaders = new LinkedHashMap<>(); - audioHeaders.put("Content-Type", "audio/basic"); - audioHeaders.put("Content-Transfer-Encoding", "base64"); - innerMP.addBodyPart(("... base64-encoded 8000 Hz single-channel\n" - + " mu-law-format audio data goes here ...").getBytes(), audioHeaders); - - final Map imageHeaders = new LinkedHashMap<>(); - imageHeaders.put("Content-Type", "image/jpeg"); - imageHeaders.put("Content-Transfer-Encoding", "base64"); - innerMP.addBodyPart("... base64-encoded image data goes here ...".getBytes(), imageHeaders); - - mP.addBodyPart(("This is enriched.\n" - + "as defined in RFC 1896\n" - + "\n" - + "Isn't it\n" - + "cool?\n").getBytes(), "text/enriched"); - - mP.addBodyPart(("From: (mailbox in US-ASCII)\n" - + "To: (address in US-ASCII)\n" - + "Subject: (subject in US-ASCII)\n" - + "Content-Type: Text/plain; charset=ISO-8859-1\n" - + "Content-Transfer-Encoding: Quoted-printable\n" - + "\n" - + "... Additional text in ISO-8859-1 goes here ...\n").getBytes(), "message/rfc822"); - - final StringBuilder sb = new StringBuilder(); - for (Map.Entry header : mP.getHeaders().entrySet()) { - sb.append(header.getKey()) - .append(": ") - .append(header.getValue()) - .append("\r\n"); - } - sb.append("\r\n").append(JDKHttpClient.getPayload(mP).toString()); - Assert.assertEquals("Content-Type: multipart/mixed; boundary=\"unique-boundary-1\"\r\n" - + "\r\n" - + "This is the preamble area of a multipart message.\n" - + "Mail readers that understand multipart format\n" - + "should ignore this preamble.\n" - + "\n" - + "If you are reading this text, you might want to\n" - + "consider changing to a mail reader that understands\n" - + "how to properly display multipart messages.\n" - + "\r\n" - + "--unique-boundary-1\r\n" - + "\r\n" - + "... Some text appears here ..." - + "\r\n" - + "--unique-boundary-1\r\n" - + "Content-Type: text/plain; charset=US-ASCII\r\n" - + "\r\n" - + "This could have been part of the previous part, but\n" - + "illustrates explicit versus implicit typing of body\n" - + "parts.\n" - + "\r\n" - + "--unique-boundary-1\r\n" - + "Content-Type: multipart/parallel; boundary=\"unique-boundary-2\"\r\n" - + "\r\n" - + "--unique-boundary-2\r\n" - + "Content-Type: audio/basic\r\n" - + "Content-Transfer-Encoding: base64\r\n" - + "\r\n" - + "... base64-encoded 8000 Hz single-channel\n" - + " mu-law-format audio data goes here ..." - + "\r\n" - + "--unique-boundary-2\r\n" - + "Content-Type: image/jpeg\r\n" - + "Content-Transfer-Encoding: base64\r\n" - + "\r\n" - + "... base64-encoded image data goes here ..." - + "\r\n" - + "--unique-boundary-2--\r\n" - + "\r\n" - + "--unique-boundary-1\r\n" - + "Content-Type: text/enriched\r\n" - + "\r\n" - + "This is enriched.\n" - + "as defined in RFC 1896\n" - + "\n" - + "Isn't it\n" - + "cool?\n" - + "\r\n" - + "--unique-boundary-1\r\n" - + "Content-Type: message/rfc822\r\n" - + "\r\n" - + "From: (mailbox in US-ASCII)\n" - + "To: (address in US-ASCII)\n" - + "Subject: (subject in US-ASCII)\n" - + "Content-Type: Text/plain; charset=ISO-8859-1\n" - + "Content-Transfer-Encoding: Quoted-printable\n" - + "\n" - + "... Additional text in ISO-8859-1 goes here ...\n" - + "\r\n" - + "--unique-boundary-1--\r\n", - sb.toString()); - } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java deleted file mode 100644 index 4abc36ee5..000000000 --- a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartPayloadTest.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.github.scribejava.core.httpclient.multipart; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; -import org.junit.Test; -import org.junit.function.ThrowingRunnable; - -public class MultipartPayloadTest { - - @Test - public void testValidCheckBoundarySyntax() { - MultipartPayload.checkBoundarySyntax("0aA'()+_,-./:=?"); - MultipartPayload.checkBoundarySyntax("0aA'()+_,- ./:=?"); - MultipartPayload.checkBoundarySyntax(" 0aA'()+_,-./:=?"); - MultipartPayload.checkBoundarySyntax("1234567890123456789012345678901234567890123456789012345678901234567890"); - } - - @Test - public void testNonValidLastWhiteSpaceCheckBoundarySyntax() { - testBoundary("0aA'()+_,-./:=? "); - } - - @Test - public void testNonValidEmptyCheckBoundarySyntax() { - testBoundary(""); - } - - @Test - public void testNonValidIllegalSymbolCheckBoundarySyntax() { - testBoundary("0aA'()+_;,-./:=? "); - } - - @Test - public void testNonValidTooLongCheckBoundarySyntax() { - testBoundary("12345678901234567890123456789012345678901234567890123456789012345678901"); - } - - @Test - public void testNonValidNullCheckBoundarySyntax() { - testBoundary(null); - } - - @Test - public void testParseBoundaryFromHeader() { - assertNull(MultipartPayload.parseBoundaryFromHeader(null)); - - assertEquals("0aA'()+_,-./:=?", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_,-./:=?\"")); - - assertEquals("0aA'()+_, -./:=?", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_, -./:=?\"")); - - assertEquals("0aA'()+_, -./:=?", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_, -./:=? \"")); - - assertEquals("0aA'()+_,-./:=?", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_,-./:=?")); - - assertEquals("0aA'()+_, -./:=?", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_, -./:=?")); - - assertEquals("0aA'()+_, -./:=?", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_, -./:=? ")); - - assertEquals(" 0aA'()+_, -./:=?", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary= 0aA'()+_, -./:=?")); - - assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundar=0aA'()+_, -./:=? ")); - assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; ")); - assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype;")); - assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype")); - assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=")); - - assertEquals("0aA'()+_,", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_,; -./:=? ")); - - assertEquals("0aA'()+_, -./:=?", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_, -./:=?")); - - assertEquals("0aA'()+_, -./:=?", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_, -./:=?\"")); - - assertEquals("1234567890123456789012345678901234567890123456789012345678901234567890", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; " - + "boundary=1234567890123456789012345678901234567890123456789012345678901234567890")); - - assertEquals("1234567890123456789012345678901234567890123456789012345678901234567890", - MultipartPayload.parseBoundaryFromHeader("multipart/subtype; " - + "boundary=12345678901234567890123456789012345678901234567890123456789012345678901")); - - assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=")); - assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"\"")); - assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=;123")); - assertNull(MultipartPayload.parseBoundaryFromHeader("multipart/subtype; boundary=\"\"123")); - } - - private static void testBoundary(final String boundary) { - final IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { - @Override - public void run() throws Throwable { - MultipartPayload.checkBoundarySyntax(boundary); - } - }); - assertTrue(thrown.getMessage().startsWith("{'boundary'='" + boundary + "'} has invalid syntax. Should be '")); - } -} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java new file mode 100644 index 000000000..cac5def30 --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java @@ -0,0 +1,371 @@ +package com.github.scribejava.core.httpclient.multipart; + +import com.github.scribejava.core.httpclient.HttpClient; +import java.io.IOException; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import org.junit.function.ThrowingRunnable; + +public class MultipartUtilsTest { + + @Test + public void testEmptyMultipartPayload() throws IOException { + final MultipartPayload mP = new MultipartPayload(); + + final StringBuilder sb = new StringBuilder(); + for (Map.Entry header : mP.getHeaders().entrySet()) { + sb.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + + sb.append("\r\n").append(MultipartUtils.getPayload(mP).toString()); + assertEquals("Content-Type: multipart/form-data; boundary=\"" + mP.getBoundary() + "\"\r\n\r\n", sb.toString()); + } + + @Test + public void testSimpleMultipartPayload() throws IOException { + final Map headers = new LinkedHashMap<>(); + headers.put("X-Header", "X-Value"); + headers.put("Content-Disposition", "Content-Disposition-Value"); + final MultipartPayload mP = new MultipartPayload("mixed", "simple boundary", headers); + mP.setPreamble("This is the preamble. It is to be ignored, though it\n" + + "is a handy place for composition agents to include an\n" + + "explanatory note to non-MIME conformant readers."); + + mP.addBodyPart(("This is implicitly typed plain US-ASCII text.\n" + + "It does NOT end with a linebreak.").getBytes()); + + final ByteArrayBodyPartPayload bP = new ByteArrayBodyPartPayload( + ("This is explicitly typed plain US-ASCII text.\n" + + "It DOES end with a linebreak.\n").getBytes(), + Collections.singletonMap(HttpClient.CONTENT_TYPE, "text/plain; charset=us-ascii")); + mP.addBodyPart(bP); + + mP.setEpilogue("This is the epilogue. It is also to be ignored."); + + final StringBuilder sb = new StringBuilder(); + for (Map.Entry header : mP.getHeaders().entrySet()) { + sb.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + sb.append("\r\n").append(MultipartUtils.getPayload(mP).toString()); + assertEquals("X-Header: X-Value\r\n" + + "Content-Disposition: Content-Disposition-Value\r\n" + + "Content-Type: multipart/mixed; boundary=\"simple boundary\"\r\n" + + "\r\n" + + "This is the preamble. It is to be ignored, though it\n" + + "is a handy place for composition agents to include an\n" + + "explanatory note to non-MIME conformant readers." + + "\r\n" + + "--simple boundary\r\n" + + "\r\n" + + "This is implicitly typed plain US-ASCII text.\n" + + "It does NOT end with a linebreak." + + "\r\n" + + "--simple boundary\r\n" + + "Content-Type: text/plain; charset=us-ascii\r\n" + + "\r\n" + + "This is explicitly typed plain US-ASCII text.\n" + + "It DOES end with a linebreak.\n" + + "\r\n" + + "--simple boundary--\r\n" + + "This is the epilogue. It is also to be ignored.\r\n", + sb.toString()); + } + + @Test + public void testCRLFMultipartPayload() throws IOException { + final MultipartPayload mP = new MultipartPayload("simple-boundary"); + mP.addBodyPart("It does NOT end with a linebreak.".getBytes()); + mP.addBodyPart("It does end with a \\r linebreak.\r".getBytes()); + mP.addBodyPart("It does end with a \\n linebreak.\n".getBytes()); + mP.addBodyPart("It does end with a \\r\\n linebreak.\r\n".getBytes()); + mP.addBodyPart("the last one".getBytes()); + + final StringBuilder sb = new StringBuilder(); + for (Map.Entry header : mP.getHeaders().entrySet()) { + sb.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + sb.append("\r\n").append(MultipartUtils.getPayload(mP).toString()); + assertEquals("Content-Type: multipart/form-data; boundary=\"simple-boundary\"\r\n" + + "\r\n" + + "\r\n" + + "--simple-boundary\r\n" + + "\r\n" + + "It does NOT end with a linebreak." + + "\r\n" + + "--simple-boundary\r\n" + + "\r\n" + + "It does end with a \\r linebreak.\r" + + "\r\n" + + "--simple-boundary\r\n" + + "\r\n" + + "It does end with a \\n linebreak.\n" + + "\r\n" + + "--simple-boundary\r\n" + + "\r\n" + + "It does end with a \\r\\n linebreak.\r\n" + + "\r\n" + + "--simple-boundary\r\n" + + "\r\n" + + "the last one" + + "\r\n" + + "--simple-boundary--\r\n", + sb.toString()); + } + + @Test + public void testFileByteArrayBodyPartPayloadMultipartPayload() throws IOException { + final MultipartPayload mP = new MultipartPayload("testFileByteArrayBodyPartPayloadMultipartPayload boundary"); + mP.addBodyPart(new FileByteArrayBodyPartPayload("fileContent".getBytes(), "name", "filename.ext")); + + final StringBuilder sb = new StringBuilder(); + for (Map.Entry header : mP.getHeaders().entrySet()) { + sb.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + + sb.append("\r\n").append(MultipartUtils.getPayload(mP).toString()); + assertEquals("Content-Type: multipart/form-data; " + + "boundary=\"testFileByteArrayBodyPartPayloadMultipartPayload boundary\"\r\n" + + "\r\n" + + "\r\n" + + "--testFileByteArrayBodyPartPayloadMultipartPayload boundary\r\n" + + "Content-Disposition: form-data; name=\"name\"; filename=\"filename.ext\"\r\n" + + "\r\n" + + "fileContent" + + "\r\n" + + "--testFileByteArrayBodyPartPayloadMultipartPayload boundary--\r\n", + sb.toString() + ); + } + + @Test + public void testComplexMultipartPayload() throws IOException { + final MultipartPayload mP = new MultipartPayload("mixed", "unique-boundary-1"); + + mP.setPreamble("This is the preamble area of a multipart message.\n" + + "Mail readers that understand multipart format\n" + + "should ignore this preamble.\n" + + "\n" + + "If you are reading this text, you might want to\n" + + "consider changing to a mail reader that understands\n" + + "how to properly display multipart messages.\n"); + + mP.addBodyPart("... Some text appears here ...".getBytes()); + + mP.addBodyPart(("This could have been part of the previous part, but\n" + + "illustrates explicit versus implicit typing of body\n" + + "parts.\n").getBytes(), "text/plain; charset=US-ASCII"); + + final MultipartPayload innerMP = new MultipartPayload("parallel", "unique-boundary-2"); + mP.addBodyPart(innerMP); + + final Map audioHeaders = new LinkedHashMap<>(); + audioHeaders.put("Content-Type", "audio/basic"); + audioHeaders.put("Content-Transfer-Encoding", "base64"); + innerMP.addBodyPart(("... base64-encoded 8000 Hz single-channel\n" + + " mu-law-format audio data goes here ...").getBytes(), audioHeaders); + + final Map imageHeaders = new LinkedHashMap<>(); + imageHeaders.put("Content-Type", "image/jpeg"); + imageHeaders.put("Content-Transfer-Encoding", "base64"); + innerMP.addBodyPart("... base64-encoded image data goes here ...".getBytes(), imageHeaders); + + mP.addBodyPart(("This is enriched.\n" + + "as defined in RFC 1896\n" + + "\n" + + "Isn't it\n" + + "cool?\n").getBytes(), "text/enriched"); + + mP.addBodyPart(("From: (mailbox in US-ASCII)\n" + + "To: (address in US-ASCII)\n" + + "Subject: (subject in US-ASCII)\n" + + "Content-Type: Text/plain; charset=ISO-8859-1\n" + + "Content-Transfer-Encoding: Quoted-printable\n" + + "\n" + + "... Additional text in ISO-8859-1 goes here ...\n").getBytes(), "message/rfc822"); + + final StringBuilder sb = new StringBuilder(); + for (Map.Entry header : mP.getHeaders().entrySet()) { + sb.append(header.getKey()) + .append(": ") + .append(header.getValue()) + .append("\r\n"); + } + sb.append("\r\n").append(MultipartUtils.getPayload(mP).toString()); + assertEquals("Content-Type: multipart/mixed; boundary=\"unique-boundary-1\"\r\n" + + "\r\n" + + "This is the preamble area of a multipart message.\n" + + "Mail readers that understand multipart format\n" + + "should ignore this preamble.\n" + + "\n" + + "If you are reading this text, you might want to\n" + + "consider changing to a mail reader that understands\n" + + "how to properly display multipart messages.\n" + + "\r\n" + + "--unique-boundary-1\r\n" + + "\r\n" + + "... Some text appears here ..." + + "\r\n" + + "--unique-boundary-1\r\n" + + "Content-Type: text/plain; charset=US-ASCII\r\n" + + "\r\n" + + "This could have been part of the previous part, but\n" + + "illustrates explicit versus implicit typing of body\n" + + "parts.\n" + + "\r\n" + + "--unique-boundary-1\r\n" + + "Content-Type: multipart/parallel; boundary=\"unique-boundary-2\"\r\n" + + "\r\n" + + "--unique-boundary-2\r\n" + + "Content-Type: audio/basic\r\n" + + "Content-Transfer-Encoding: base64\r\n" + + "\r\n" + + "... base64-encoded 8000 Hz single-channel\n" + + " mu-law-format audio data goes here ..." + + "\r\n" + + "--unique-boundary-2\r\n" + + "Content-Type: image/jpeg\r\n" + + "Content-Transfer-Encoding: base64\r\n" + + "\r\n" + + "... base64-encoded image data goes here ..." + + "\r\n" + + "--unique-boundary-2--\r\n" + + "\r\n" + + "--unique-boundary-1\r\n" + + "Content-Type: text/enriched\r\n" + + "\r\n" + + "This is enriched.\n" + + "as defined in RFC 1896\n" + + "\n" + + "Isn't it\n" + + "cool?\n" + + "\r\n" + + "--unique-boundary-1\r\n" + + "Content-Type: message/rfc822\r\n" + + "\r\n" + + "From: (mailbox in US-ASCII)\n" + + "To: (address in US-ASCII)\n" + + "Subject: (subject in US-ASCII)\n" + + "Content-Type: Text/plain; charset=ISO-8859-1\n" + + "Content-Transfer-Encoding: Quoted-printable\n" + + "\n" + + "... Additional text in ISO-8859-1 goes here ...\n" + + "\r\n" + + "--unique-boundary-1--\r\n", + sb.toString()); + } + + @Test + public void testParseBoundaryFromHeader() { + assertNull(MultipartUtils.parseBoundaryFromHeader(null)); + + assertEquals("0aA'()+_,-./:=?", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_,-./:=?\"")); + + assertEquals("0aA'()+_, -./:=?", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_, -./:=?\"")); + + assertEquals("0aA'()+_, -./:=?", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_, -./:=? \"")); + + assertEquals("0aA'()+_,-./:=?", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_,-./:=?")); + + assertEquals("0aA'()+_, -./:=?", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_, -./:=?")); + + assertEquals("0aA'()+_, -./:=?", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_, -./:=? ")); + + assertEquals(" 0aA'()+_, -./:=?", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary= 0aA'()+_, -./:=?")); + + assertNull(MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundar=0aA'()+_, -./:=? ")); + assertNull(MultipartUtils.parseBoundaryFromHeader("multipart/subtype; ")); + assertNull(MultipartUtils.parseBoundaryFromHeader("multipart/subtype;")); + assertNull(MultipartUtils.parseBoundaryFromHeader("multipart/subtype")); + assertNull(MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=")); + + assertEquals("0aA'()+_,", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_,; -./:=? ")); + + assertEquals("0aA'()+_, -./:=?", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=\"0aA'()+_, -./:=?")); + + assertEquals("0aA'()+_, -./:=?", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=0aA'()+_, -./:=?\"")); + + assertEquals("1234567890123456789012345678901234567890123456789012345678901234567890", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; " + + "boundary=1234567890123456789012345678901234567890123456789012345678901234567890")); + + assertEquals("1234567890123456789012345678901234567890123456789012345678901234567890", + MultipartUtils.parseBoundaryFromHeader("multipart/subtype; " + + "boundary=12345678901234567890123456789012345678901234567890123456789012345678901")); + + assertNull(MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=")); + assertNull(MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=\"\"")); + assertNull(MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=;123")); + assertNull(MultipartUtils.parseBoundaryFromHeader("multipart/subtype; boundary=\"\"123")); + } + + @Test + public void testValidCheckBoundarySyntax() { + MultipartUtils.checkBoundarySyntax("0aA'()+_,-./:=?"); + MultipartUtils.checkBoundarySyntax("0aA'()+_,- ./:=?"); + MultipartUtils.checkBoundarySyntax(" 0aA'()+_,-./:=?"); + MultipartUtils.checkBoundarySyntax("1234567890123456789012345678901234567890123456789012345678901234567890"); + } + + @Test + public void testNonValidLastWhiteSpaceCheckBoundarySyntax() { + testNotValidBoundary("0aA'()+_,-./:=? "); + } + + @Test + public void testNonValidEmptyCheckBoundarySyntax() { + testNotValidBoundary(""); + } + + @Test + public void testNonValidIllegalSymbolCheckBoundarySyntax() { + testNotValidBoundary("0aA'()+_;,-./:=? "); + } + + @Test + public void testNonValidTooLongCheckBoundarySyntax() { + testNotValidBoundary("12345678901234567890123456789012345678901234567890123456789012345678901"); + } + + @Test + public void testNonValidNullCheckBoundarySyntax() { + testNotValidBoundary(null); + } + + private static void testNotValidBoundary(final String boundary) { + final IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + MultipartUtils.checkBoundarySyntax(boundary); + } + }); + assertTrue(thrown.getMessage().startsWith("{'boundary'='" + boundary + "'} has invalid syntax. Should be '")); + } +} diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java index 882293a43..4da925590 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java @@ -42,8 +42,7 @@ public void close() throws IOException { @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - final byte[] bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { + byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new ByteArrayConsumer(bodyContents), callback, converter); } @@ -58,16 +57,14 @@ public Future executeAsync(String userAgent, Map headers, @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - final String bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { + String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new StringConsumer(bodyContents), callback, converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, - final File bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { + File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new FileConsumer(bodyContents), callback, converter); } diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 6642e9cad..b67e66998 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -9,6 +9,7 @@ ../pom.xml + com.github.scribejava scribejava-httpclient-armeria ScribeJava Async Armeria Client support jar @@ -22,13 +23,7 @@ com.linecorp.armeria armeria - 0.99.7 - - - com.github.scribejava - scribejava-apis - ${project.version} - test + 0.99.8 com.github.scribejava @@ -37,25 +32,10 @@ test-jar test - - org.slf4j - slf4j-simple - 1.7.30 - test - - - maven-compiler-plugin - 3.8.1 - - UTF-8 - 8 - true - - org.apache.felix maven-bundle-plugin @@ -66,4 +46,8 @@ + + + 8 + diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java index b059d6f04..982ddc63a 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClient.java @@ -15,11 +15,14 @@ import com.linecorp.armeria.common.HttpData; import com.linecorp.armeria.common.HttpMethod; import com.linecorp.armeria.common.HttpResponse; +import com.linecorp.armeria.common.HttpStatus; +import com.linecorp.armeria.common.MediaType; import com.linecorp.armeria.common.RequestHeaders; import com.linecorp.armeria.common.RequestHeadersBuilder; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.net.URI; import java.nio.file.Files; import java.util.HashMap; @@ -54,7 +57,7 @@ public ArmeriaHttpClient() { } public ArmeriaHttpClient(ArmeriaHttpClientConfig config) { - this.clientBuilder = config.builder(); + clientBuilder = config.createClientBuilder(); } /** @@ -72,41 +75,36 @@ public void close() { } @Override - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - new BytesBody(bodyContents), callback, converter); + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new BytesBody(bodyContents), callback, + converter); } @Override - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + MultipartPayload bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - new MultipartBody(bodyContents), callback, converter); + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new MultipartBody(bodyContents), callback, + converter); } @Override - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - new StringBody(bodyContents), callback, converter); + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new StringBody(bodyContents), callback, + converter); } @Override - public Future executeAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, File bodyContents, OAuthAsyncRequestCallback callback, - OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, - new FileBody(bodyContents), callback, converter); + public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, + File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new FileBody(bodyContents), callback, + converter); } - private CompletableFuture doExecuteAsync(String userAgent, - Map headers, Verb httpVerb, - String completeUrl, Supplier contentSupplier, - OAuthAsyncRequestCallback callback, + private CompletableFuture doExecuteAsync(String userAgent, Map headers, Verb httpVerb, + String completeUrl, Supplier contentSupplier, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { // Get the URI and Path final URI uri = URI.create(completeUrl); @@ -116,8 +114,8 @@ private CompletableFuture doExecuteAsync(String userAgent, final WebClient client = getClient(uri); // Build HTTP request - final RequestHeadersBuilder headersBuilder - = RequestHeaders.of(getHttpMethod(httpVerb), path).toBuilder(); + final RequestHeadersBuilder headersBuilder = RequestHeaders.of(getHttpMethod(httpVerb), path).toBuilder(); + headersBuilder.add(headers.entrySet()); if (userAgent != null) { headersBuilder.add(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent); @@ -128,9 +126,13 @@ private CompletableFuture doExecuteAsync(String userAgent, if (httpVerb.isPermitBody()) { // POST, PUT, PATCH and DELETE methods final HttpData contents = contentSupplier.get(); if (httpVerb.isRequiresBody() && contents == null) { // POST or PUT methods - throw new IllegalArgumentException( - "Contents missing for request method " + httpVerb.name()); + throw new IllegalArgumentException("Contents missing for request method " + httpVerb.name()); + } + + if (headersBuilder.contentType() == null) { + headersBuilder.contentType(MediaType.FORM_DATA); } + if (contents != null) { response = client.execute(headersBuilder.build(), contents); } else { @@ -142,11 +144,10 @@ private CompletableFuture doExecuteAsync(String userAgent, // Aggregate HTTP response (asynchronously) and return the result Future return response.aggregate() - .thenApply(r -> whenResponseComplete(callback, converter, r)) - .exceptionally(e -> completeExceptionally(callback, e)); + .thenApply(aggregatedResponse -> whenResponseComplete(callback, converter, aggregatedResponse)) + .exceptionally(throwable -> completeExceptionally(callback, throwable)); } - //------------------------------------------------------------------------------------------------ /** * Provides an instance of {@link WebClient} for a given endpoint {@link URI} based on an endpoint as * {@code scheme://authority}. @@ -154,7 +155,7 @@ private CompletableFuture doExecuteAsync(String userAgent, * @param uri an endpoint {@link URI} * @return {@link WebClient} instance */ - private WebClient getClient(final URI uri) { + private WebClient getClient(URI uri) { final String endpoint = getEndPoint(uri); WebClient client; @@ -189,23 +190,20 @@ private WebClient getClient(final URI uri) { } /** - * Extracts {@code scheme} and {@code authority} portion of the {@link URI}. Assuming the {@link URI} as the - * following: {@code URI = scheme:[//authority]path[?query][#fragment]} + * Extracts {@code scheme} and {@code authority} portion of the {@link URI}. + * + * Assuming the {@link URI} as the following: {@code URI = scheme:[//authority]path[?query][#fragment]} */ - @SuppressWarnings("StringBufferReplaceableByString") - private static String getEndPoint(final URI uri) { - final StringBuilder builder = new StringBuilder() - .append(requireNonNull(uri.getScheme(), "scheme")) - .append("://").append(requireNonNull(uri.getAuthority(), "authority")); - return builder.toString(); + private static String getEndPoint(URI uri) { + return requireNonNull(uri.getScheme(), "scheme") + "://" + requireNonNull(uri.getAuthority(), "authority"); } /** - * Extracts {@code path}, {@code query) and {@code fragment} portion of the {@link URI}. - * Assuming the {@link URI} as the following: - * {@code URI = scheme:[//authority]path[?query][#fragment]} + * Extracts {@code path}, {@code query} and {@code fragment} portion of the {@link URI}. + * + * Assuming the {@link URI} as the following: {@code URI = scheme:[//authority]path[?query][#fragment]} */ - private static String getServicePath(final URI uri) { + private static String getServicePath(URI uri) { final StringBuilder builder = new StringBuilder() .append(requireNonNull(uri.getPath(), "path")); final String query = uri.getQuery(); @@ -225,7 +223,7 @@ private static String getServicePath(final URI uri) { * @param httpVerb a {@link Verb} to match with {@link HttpMethod} * @return {@link HttpMethod} corresponding to the parameter */ - private static HttpMethod getHttpMethod(final Verb httpVerb) { + private static HttpMethod getHttpMethod(Verb httpVerb) { switch (httpVerb) { case GET: return HttpMethod.GET; @@ -249,7 +247,6 @@ private static HttpMethod getHttpMethod(final Verb httpVerb) { } } - //------------------------------------------------------------------------------------------------ // Response asynchronous handlers /** * Converts {@link AggregatedHttpResponse} to {@link Response} @@ -257,13 +254,14 @@ private static HttpMethod getHttpMethod(final Verb httpVerb) { * @param aggregatedResponse an instance of {@link AggregatedHttpResponse} to convert to {@link Response} * @return a {@link Response} converted from {@link AggregatedHttpResponse} */ - private Response convertResponse(final AggregatedHttpResponse aggregatedResponse) { - final Map headersMap = new HashMap<>(aggregatedResponse.headers().size()); - aggregatedResponse.headers() - .forEach((header, value) -> headersMap.put(header.toString(), value)); - return new Response(aggregatedResponse.status().code(), - aggregatedResponse.status().reasonPhrase(), - headersMap, aggregatedResponse.content().toInputStream()); + private Response convertResponse(AggregatedHttpResponse aggregatedResponse) { + final Map headersMap = new HashMap<>(); + aggregatedResponse.headers().forEach((header, value) -> headersMap.put(header.toString(), value)); + + final HttpStatus status = aggregatedResponse.status(); + final InputStream inputStream = aggregatedResponse.content().toInputStream(); + + return new Response(status.code(), status.reasonPhrase(), headersMap, inputStream, inputStream); } /** @@ -281,8 +279,7 @@ private T whenResponseComplete(OAuthAsyncRequestCallback callback, final Response response = convertResponse(aggregatedResponse); try { @SuppressWarnings("unchecked") - final T t - = converter == null ? (T) response : converter.convert(response); + final T t = converter == null ? (T) response : converter.convert(response); if (callback != null) { callback.onCompleted(t); } @@ -307,13 +304,12 @@ private T completeExceptionally(OAuthAsyncRequestCallback callback, Throw return null; } - //------------------------------------------------------------------------------------------------ // Body type suppliers private static class BytesBody implements Supplier { private final byte[] bodyContents; - BytesBody(final byte[] bodyContents) { + BytesBody(byte[] bodyContents) { this.bodyContents = bodyContents; } @@ -327,7 +323,7 @@ private static class StringBody implements Supplier { private final String bodyContents; - StringBody(final String bodyContents) { + StringBody(String bodyContents) { this.bodyContents = bodyContents; } @@ -341,7 +337,7 @@ private static class FileBody implements Supplier { private final File bodyContents; - FileBody(final File bodyContents) { + FileBody(File bodyContents) { this.bodyContents = bodyContents; } @@ -351,8 +347,8 @@ public HttpData get() { return (bodyContents != null) ? HttpData.wrap(Files.readAllBytes(bodyContents.toPath())) : null; - } catch (IOException e) { - throw new RuntimeException(e); + } catch (IOException ioE) { + throw new RuntimeException(ioE); } } } @@ -361,7 +357,7 @@ private static class MultipartBody implements Supplier { private final MultipartPayload bodyContents; - MultipartBody(final MultipartPayload bodyContents) { + MultipartBody(MultipartPayload bodyContents) { this.bodyContents = bodyContents; } @@ -371,11 +367,9 @@ public HttpData get() { return (bodyContents != null) ? HttpData.wrap(MultipartUtils.getPayload(bodyContents).toByteArray()) : null; - } catch (IOException e) { - throw new RuntimeException(e); + } catch (IOException ioE) { + throw new RuntimeException(ioE); } } } - - //------------------------------------------------------------------------------------------------ } diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java index a0f503222..19fc27f48 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java @@ -5,14 +5,9 @@ import com.linecorp.armeria.client.ClientOptions; import com.linecorp.armeria.client.HttpClient; import com.linecorp.armeria.client.logging.LoggingClient; -import com.linecorp.armeria.client.retry.Backoff; -import com.linecorp.armeria.client.retry.RetryRule; import com.linecorp.armeria.client.retry.RetryingClient; -import com.linecorp.armeria.common.HttpStatus; import com.linecorp.armeria.common.SessionProtocol; -import com.linecorp.armeria.common.logging.LogLevel; import java.util.function.Function; -import org.slf4j.LoggerFactory; public class ArmeriaHttpClientConfig implements HttpClientConfig { @@ -26,6 +21,9 @@ public class ArmeriaHttpClientConfig implements HttpClientConfig { /** * Creates new {@link ArmeriaHttpClientConfig} using provided {@link ClientOptions} and {@link ClientFactory}. + * + * @param clientOptions clientOptions + * @param clientFactory clientFactory */ public ArmeriaHttpClientConfig(ClientOptions clientOptions, ClientFactory clientFactory) { this.clientOptions = clientOptions; @@ -33,13 +31,6 @@ public ArmeriaHttpClientConfig(ClientOptions clientOptions, ClientFactory client protocolPreference = DEFAULT_PROTOCOL_PREFERENCE; } - /** - * Creates new {@link ArmeriaHttpClientConfig} using default settings. - */ - ArmeriaHttpClientConfig() { - this(null, null); - } - /** * Creates new {@link HttpClientConfig} using default settings. */ @@ -50,34 +41,11 @@ public HttpClientConfig createDefaultConfig() { /** * Creates new {@link ArmeriaHttpClientConfig} using default settings. - */ - public static ArmeriaHttpClientConfig defaultConfig() { - return new ArmeriaHttpClientConfig(); - } - - /** - * Selects which protocol shall take preference when generic protocol scheme used by the URL, like {@code http} or - * {@code https}. * - * @param protocolPreference specifies which protocol shall take preference. Acceptable values: {@code H1}, - * {@code HTTP1}, {@code HTTP/1.1} for {@code HTTP/1.1} and {@code H2}, {@code HTTP2}, {@code HTTP/2} for - * {@code HTTP/2}. + * @return ArmeriaHttpClientConfig */ - public void protocolPreference(String protocolPreference) { - switch (protocolPreference.toUpperCase()) { - case "H1": - case "HTTP1": - case "HTTP/1.1": - this.protocolPreference = SessionProtocol.H1; - break; - case "H2": - case "HTTP2": - case "HTTP/2": - this.protocolPreference = SessionProtocol.H2; - break; - default: - throw new IllegalArgumentException("Invalid protocolPreference: " + protocolPreference); - } + public static ArmeriaHttpClientConfig defaultConfig() { + return new ArmeriaHttpClientConfig(null, null); } /** @@ -87,104 +55,22 @@ public void protocolPreference(String protocolPreference) { * @param protocolPreference specifies which protocol shall take preference. Acceptable values: * {@link SessionProtocol#H1} and {@link SessionProtocol#H2} */ - public void protocolPreference(SessionProtocol protocolPreference) { - switch (protocolPreference) { - case H1: - this.protocolPreference = SessionProtocol.H1; - break; - case H2: - this.protocolPreference = SessionProtocol.H2; - break; - default: - throw new IllegalArgumentException("Invalid protocolPreference: " + protocolPreference); + public void setProtocolPreference(SessionProtocol protocolPreference) { + if (protocolPreference != SessionProtocol.H1 && protocolPreference != SessionProtocol.H2) { + throw new IllegalArgumentException("Invalid protocolPreference: " + protocolPreference); } + this.protocolPreference = protocolPreference; } - /** - * Sets the client to retry when the remote end-point responds with one of the specified {@code statuses}. - * - * Uses a backoff that computes a delay using one of supported functions, such as - * {@code exponential(long, long, double)}, {@code fibonacci(long, long)}, {@code fixed(long)} and - * {@code random(long, long)} chaining with {@code withJitter(double, double)} and {@code withMaxAttempts(int)} from - * the {@code backoff} string that conforms to the following format: - *
      - *
    • {@code exponential=[initialDelayMillis:maxDelayMillis:multiplier]} is for - * {@code exponential(long, long, double)} (multiplier will be 2.0 if it's omitted)
    • - *
    • {@code fibonacci=[initialDelayMillis:maxDelayMillis]} is for {@code fibonacci(long, long)}
    • - *
    • {@code fixed=[delayMillis]} is for {@code fixed(long)}
    • - *
    • {@code random=[minDelayMillis:maxDelayMillis]} is for {@code random(long, long)}
    • - *
    • {@code jitter=[minJitterRate:maxJitterRate]} is for {@code withJitter(double, double)} (if only one jitter - * value is specified, it will be used for {@code withJitter(double)}
    • - *
    • {@code maxAttempts=[maxAttempts]} is for {@code withMaxAttempts(int)}
    • - *
    - * The order of options does not matter, and the {@code backoff} needs at least one option. If you don't specify the - * base option exponential backoff will be used. If you only specify a base option, jitter and maxAttempts will be - * set by default values. For example: - *
      - *
    • {@code exponential=200:10000:2.0,jitter=0.2} (default)
    • - *
    • {@code exponential=200:10000,jitter=0.2,maxAttempts=50} (multiplier omitted)
    • - *
    • {@code fibonacci=200:10000,jitter=0.2,maxAttempts=50}
    • - *
    • {@code fixed=100,jitter=-0.5:0.2,maxAttempts=10} (fixed backoff with jitter variation)
    • - *
    • {@code random=200:1000} (jitter and maxAttempts will be set by default values)
    • - *
    - * - * @param backoff the specification used to create a retry backoff - * @param statuses the list of HTTP statuses on which to retry - */ - public void retry(String backoff, HttpStatus... statuses) { - final Backoff retryBackoff = Backoff.of(backoff); - final RetryRule retryRule - = RetryRule.builder().onStatus(statuses).onUnprocessed().thenBackoff(retryBackoff); - retry = RetryingClient.newDecorator(retryRule); - } - - /** - * Sets the client to log requests and responses to the specified {@code logger}. This method explicitly specifies - * various log levels. The log level correspond to a value of {@link LogLevel} and must use one of the following - * values: {@code ["OFF", "TRACE", "DEBUG", "INFO", "WARN", "ERROR"]} - * - * @param logger the logger name (of {@link org.slf4j.Logger}) to log requests/responses to - * @param requestLevel the log level to use for logging requests, default {@code "DEBUG"} - * @param responseLevel the log level to use for logging responses, default {@code "DEBUG"} - * @param failureResponseLevel the log level to use for logging error responses, default {@code "WARN"} - */ - public void logging(String logger, String requestLevel, String responseLevel, - String failureResponseLevel) { - this.logging = LoggingClient.builder() - .logger(LoggerFactory.getLogger(logger)) - .requestLogLevel(LogLevel.valueOf(requestLevel)) - .successfulResponseLogLevel(LogLevel.valueOf(responseLevel)) - .failureResponseLogLevel(LogLevel.valueOf(failureResponseLevel)) - .newDecorator(); + public void setRetry(Function retry) { + this.retry = retry; } - /** - * Sets the client to log requests and responses to the specified {@code logger} using default log levels. - * - * @param logger the logger name (of {@link org.slf4j.Logger}) to log requests/responses to - */ - public void logging(String logger) { - this.logging = LoggingClient.builder() - .logger(LoggerFactory.getLogger(logger)) - .requestLogLevel(LogLevel.DEBUG) - .successfulResponseLogLevel(LogLevel.DEBUG) - .failureResponseLogLevel(LogLevel.WARN) - .newDecorator(); - } - - /** - * Sets the client to log requests and responses to a default logger using default log levels. - */ - public void logging() { - this.logging = LoggingClient.builder() - .requestLogLevel(LogLevel.DEBUG) - .successfulResponseLogLevel(LogLevel.DEBUG) - .failureResponseLogLevel(LogLevel.WARN) - .newDecorator(); + public void setLogging(Function logging) { + this.logging = logging; } - ArmeriaWebClientBuilder builder() { - return new ArmeriaWebClientBuilder(clientOptions, clientFactory, protocolPreference, - retry, logging); + ArmeriaWebClientBuilder createClientBuilder() { + return new ArmeriaWebClientBuilder(clientOptions, clientFactory, protocolPreference, retry, logging); } } diff --git a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java index 728668e8f..efad5cd25 100644 --- a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java +++ b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java @@ -3,7 +3,12 @@ import com.github.scribejava.core.AbstractClientTest; import com.github.scribejava.core.httpclient.HttpClient; import com.linecorp.armeria.client.ClientFactory; +import com.linecorp.armeria.client.logging.LoggingClient; +import com.linecorp.armeria.client.retry.Backoff; +import com.linecorp.armeria.client.retry.RetryRule; +import com.linecorp.armeria.client.retry.RetryingClient; import com.linecorp.armeria.common.HttpStatus; +import com.linecorp.armeria.common.logging.LogLevel; import io.netty.channel.EventLoopGroup; import io.netty.resolver.AbstractAddressResolver; import io.netty.resolver.AddressResolver; @@ -15,42 +20,54 @@ import java.util.Collections; import java.util.List; import java.util.function.Function; +import org.slf4j.LoggerFactory; public class ArmeriaHttpClientTest extends AbstractClientTest { @Override protected HttpClient createNewClient() { // simulate DNS resolution for a mock address ("kubernetes.docker.internal") - final Function> addressResolverGroupFactory = eventLoopGroup -> new MockAddressResolverGroup(); + final Function> addressRGF + = eventLoopGroup -> new MockAddressResolverGroup(); // No-Op DNS resolver to avoid resolution issues in the unit test - final ClientFactory clientFactory - = ClientFactory.builder().addressResolverGroupFactory(addressResolverGroupFactory).build(); + final ClientFactory clientFactory = ClientFactory.builder().addressResolverGroupFactory(addressRGF).build(); final ArmeriaHttpClientConfig config = new ArmeriaHttpClientConfig(null, clientFactory); + // enable client-side HTTP tracing - config.logging("HTTP_TRACE", "INFO", "INFO", "WARN"); + config.setLogging(LoggingClient.builder() + .logger(LoggerFactory.getLogger("HTTP_TRACE")) + .requestLogLevel(LogLevel.valueOf("INFO")) + .successfulResponseLogLevel(LogLevel.valueOf("INFO")) + .failureResponseLogLevel(LogLevel.valueOf("WARN")) + .newDecorator()); + // enable request retry - config.retry("exponential=200:10000,jitter=0.2,maxAttempts=5", HttpStatus.SERVICE_UNAVAILABLE); + final Backoff retryBackoff = Backoff.of("exponential=200:10000,jitter=0.2,maxAttempts=5"); + final RetryRule retryRule = RetryRule.builder() + .onStatus(HttpStatus.SERVICE_UNAVAILABLE) + .onUnprocessed() + .thenBackoff(retryBackoff); + config.setRetry(RetryingClient.newDecorator(retryRule)); + return new ArmeriaHttpClient(config); } - //------------------------------------------------------------------------------------------------ // No-Op DNS resolver to avoid resolution issues in the unit test - static class MockAddressResolverGroup extends AddressResolverGroup { - - private MockAddressResolverGroup() { - } + private static class MockAddressResolverGroup extends AddressResolverGroup { + @Override protected AddressResolver newResolver(EventExecutor executor) { return new MockAddressResolver(executor); } } - static class MockAddressResolver extends AbstractAddressResolver { + private static class MockAddressResolver extends AbstractAddressResolver { private MockAddressResolver(EventExecutor executor) { super(executor); } + @Override protected boolean doIsResolved(InetSocketAddress address) { return !address.isUnresolved(); } @@ -59,14 +76,14 @@ private InetSocketAddress resolveToLoopback(InetSocketAddress unresolvedAddress) return new InetSocketAddress(InetAddress.getLoopbackAddress(), unresolvedAddress.getPort()); } + @Override protected void doResolve(InetSocketAddress unresolvedAddress, Promise promise) { promise.setSuccess(resolveToLoopback(unresolvedAddress)); } + @Override protected void doResolveAll(InetSocketAddress unresolvedAddress, Promise> promise) { promise.setSuccess(Collections.singletonList(resolveToLoopback(unresolvedAddress))); } } - - //------------------------------------------------------------------------------------------------ } From e8f8d381fac24662f501a71afc30a7f80aca267b Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 4 Aug 2020 11:11:42 +0300 Subject: [PATCH 386/481] upgrade jackson-databind 2.11.1 -> 2.11.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f067fb747..1f6ca8fb5 100644 --- a/pom.xml +++ b/pom.xml @@ -54,7 +54,7 @@ com.fasterxml.jackson.core jackson-databind - 2.11.1 + 2.11.2 junit From a05870b733a2b6643902aa30d6cd67e6d9c6e861 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 4 Aug 2020 16:30:52 +0300 Subject: [PATCH 387/481] prepare v7.0.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index aa3645dc5..7e1a5ea34 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 6.9.0 + 7.0.0 ``` @@ -142,7 +142,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 6.9.0 + 7.0.0 ``` diff --git a/changelog b/changelog index 2a5d5269a..034418596 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[7.0.0] * Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) * make Response accept resources to autoclose and autoclose it (thanks to https://github.com/drei01) * fix url encoding in POST payload (it's needed for 'application/x-www-form-urlencoded' Content-Type) From 8213f57f1990fd92ec2ed938f1521be267c3cab4 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 4 Aug 2020 16:34:05 +0300 Subject: [PATCH 388/481] [maven-release-plugin] prepare release scribejava-7.0.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 1f6ca8fb5..2b530e6fb 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 6.9.1-SNAPSHOT + 7.0.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -35,7 +35,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-7.0.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index aac24aa20..cf4df4880 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.1-SNAPSHOT + 7.0.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 0fc1965c9..935506e28 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.1-SNAPSHOT + 7.0.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index fa0ce5dc5..f10367ed3 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.1-SNAPSHOT + 7.0.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 7a0933f34..9c10db72f 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.1-SNAPSHOT + 7.0.0 ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index b67e66998..210d1de14 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.1-SNAPSHOT + 7.0.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 1bf4a7f51..758f39a47 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.1-SNAPSHOT + 7.0.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index cf5ac1998..ce422e508 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 6.9.1-SNAPSHOT + 7.0.0 ../pom.xml From 6cb1e3ea1b7c3c35a364366e6a74fea00d431903 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 4 Aug 2020 16:34:13 +0300 Subject: [PATCH 389/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 2b530e6fb..98a48b4cc 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 7.0.0 + 7.0.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -35,7 +35,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-7.0.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index cf4df4880..1509132ab 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 935506e28..52856291f 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index f10367ed3..b604bff4d 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 9c10db72f..19151acab 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 210d1de14..5a78abf22 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 758f39a47..e1956ea11 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index ce422e508..4a10618f8 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.0 + 7.0.1-SNAPSHOT ../pom.xml From 88e598801840ebefd8408a1a8a9a667e9af08982 Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Tue, 4 Aug 2020 16:42:26 +0300 Subject: [PATCH 390/481] prepare new snapshot --- changelog | 2 ++ .../core/httpclient/jdk/JDKHttpClient.java | 12 ---------- .../multipart/MultipartPayload.java | 23 ------------------- 3 files changed, 2 insertions(+), 35 deletions(-) diff --git a/changelog b/changelog index 034418596..056b84c73 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,5 @@ +[SNAPSHOT] + [7.0.0] * Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) * make Response accept resources to autoclose and autoclose it (thanks to https://github.com/drei01) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index a18617633..f386049c7 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -215,18 +215,6 @@ private static void addBody(HttpURLConnection connection, MultipartPayload multi } } - /** - * @param multipartPayload multipartPayload - * @return ByteArrayOutputStream - * @throws IOException - * @deprecated use {@link com.github.scribejava.core.httpclient.multipart.MultipartUtils#getPayload( - * com.github.scribejava.core.httpclient.multipart.MultipartPayload) } - */ - @Deprecated - static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload) throws IOException { - return MultipartUtils.getPayload(multipartPayload); - } - private static OutputStream prepareConnectionForBodyAndGetOutputStream(HttpURLConnection connection, int contentLength) throws IOException { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java index 26efa66fe..e68bb6465 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java @@ -67,34 +67,11 @@ private static Map composeHeaders(String subtype, String boundar return headersOut; } - /** - * - * @param boundary boundary - * @deprecated use - * {@link com.github.scribejava.core.httpclient.multipart.MultipartUtils#checkBoundarySyntax(java.lang.String)} - */ - @Deprecated - static void checkBoundarySyntax(String boundary) { - MultipartUtils.checkBoundarySyntax(boundary); - } - private static String parseOrGenerateBoundary(Map headers) { final String parsedBoundary = MultipartUtils.parseBoundaryFromHeader(headers.get(HttpClient.CONTENT_TYPE)); return parsedBoundary == null ? MultipartUtils.generateDefaultBoundary() : parsedBoundary; } - /** - * - * @param contentTypeHeader contentTypeHeader - * @return String - * @deprecated use - * {@link com.github.scribejava.core.httpclient.multipart.MultipartUtils#parseBoundaryFromHeader(java.lang.String)} - */ - @Deprecated - static String parseBoundaryFromHeader(String contentTypeHeader) { - return MultipartUtils.parseBoundaryFromHeader(contentTypeHeader); - } - public void addFileBodyPart(byte[] fileContent) { addBodyPart(new FileByteArrayBodyPartPayload(fileContent)); } From 6007a9e712c4b7219d86a4e945835fdcd875943d Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 12 Aug 2020 16:53:07 +0300 Subject: [PATCH 391/481] update armeria and okhttp --- pom.xml | 2 +- .../src/main/java/com/github/scribejava/apis/AWeberApi.java | 1 + .../src/main/java/com/github/scribejava/apis/EtsyApi.java | 1 + .../src/main/java/com/github/scribejava/apis/FlickrApi.java | 1 + .../github/scribejava/apis/polar/PolarOAuth2AccessToken.java | 2 ++ .../src/main/java/com/github/scribejava/core/java8/Base64.java | 2 ++ scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 98a48b4cc..1c48b2b1e 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,7 @@ com.squareup.okhttp3 mockwebserver - 4.8.0 + 4.8.1 test diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java index 84e5117df..9ad3a185a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/AWeberApi.java @@ -12,6 +12,7 @@ protected AWeberApi() { } private static class InstanceHolder { + private static final AWeberApi INSTANCE = new AWeberApi(); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java index 289f83588..00ca72918 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/EtsyApi.java @@ -23,6 +23,7 @@ private EtsyApi(String... scopes) { } private static class InstanceHolder { + private static final EtsyApi INSTANCE = new EtsyApi(); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java index 33432f2bb..eedb89890 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FlickrApi.java @@ -29,6 +29,7 @@ protected FlickrApi(FlickrPerm perm) { } private static class InstanceHolder { + private static final FlickrApi INSTANCE = new FlickrApi(); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth2AccessToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth2AccessToken.java index d9ea04035..99710728f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth2AccessToken.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuth2AccessToken.java @@ -6,6 +6,8 @@ public class PolarOAuth2AccessToken extends OAuth2AccessToken { + private static final long serialVersionUID = 1L; + private final String userId; public PolarOAuth2AccessToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java index 9e855a617..221e7f24d 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java @@ -448,6 +448,7 @@ public static class Decoder { * */ private static final int[] FROM_BASE_64 = new int[256]; + static { Arrays.fill(FROM_BASE_64, -1); for (int i = 0; i < Encoder.TO_BASE_64.length; i++) { @@ -460,6 +461,7 @@ public static class Decoder { * Lookup table for decoding "URL and Filename safe Base64 Alphabet" as specified in Table2 of the RFC 4648. */ private static final int[] FROM_BASE_64_URL = new int[256]; + static { Arrays.fill(FROM_BASE_64_URL, -1); for (int i = 0; i < Encoder.TO_BASE_64_URL.length; i++) { diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 5a78abf22..e1df25813 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -23,7 +23,7 @@ com.linecorp.armeria armeria - 0.99.8 + 0.99.9 com.github.scribejava diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 4a10618f8..a364d2fcc 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 4.8.0 + 4.8.1 com.github.scribejava From 923d7e4a483914b75380fb3a52765408331f7a3f Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 26 Aug 2020 16:38:19 +0300 Subject: [PATCH 392/481] add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) --- changelog | 1 + .../scribejava/core/httpclient/jdk/JDKHttpClient.java | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/changelog b/changelog index 056b84c73..1b58bb61a 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,5 @@ [SNAPSHOT] + * add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) [7.0.0] * Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java index eb15bec1e..b500ba997 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java @@ -114,11 +114,12 @@ public Response execute(String userAgent, Map headers, Verb http private Response doExecute(String userAgent, Map headers, Verb httpVerb, String completeUrl, BodyType bodyType, Object bodyContents) throws IOException { + final URL url = new URL(completeUrl); final HttpURLConnection connection; if (config.getProxy() == null) { - connection = (HttpURLConnection) new URL(completeUrl).openConnection(); - }else { - connection = (HttpURLConnection) new URL(completeUrl).openConnection(config.getProxy()); + connection = (HttpURLConnection) url.openConnection(); + } else { + connection = (HttpURLConnection) url.openConnection(config.getProxy()); } connection.setInstanceFollowRedirects(config.isFollowRedirects()); connection.setRequestMethod(httpVerb.name()); From cbad67e169e634fa8250aa184a45b59d1fe4c805 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Thu, 27 Aug 2020 12:16:06 +0300 Subject: [PATCH 393/481] add chaining methods for HTTP clients configs --- .../httpclient/jdk/JDKHttpClientConfig.java | 34 +++++++++++++++++-- .../armeria/ArmeriaHttpClientConfig.java | 17 ++++++++++ .../armeria/ArmeriaHttpClientTest.java | 3 +- .../httpclient/ning/NingHttpClientConfig.java | 5 +++ 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java index baa431b83..3b322b0af 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java @@ -28,6 +28,11 @@ public void setConnectTimeout(Integer connectTimeout) { this.connectTimeout = connectTimeout; } + public JDKHttpClientConfig withConnectTimeout(Integer connectTimeout) { + this.connectTimeout = connectTimeout; + return this; + } + public Integer getReadTimeout() { return readTimeout; } @@ -36,8 +41,9 @@ public void setReadTimeout(Integer readTimeout) { this.readTimeout = readTimeout; } - public boolean isFollowRedirects() { - return followRedirects; + public JDKHttpClientConfig withReadTimeout(Integer readTimeout) { + this.readTimeout = readTimeout; + return this; } public void setProxy(Proxy proxy) { @@ -48,6 +54,15 @@ public Proxy getProxy() { return proxy; } + public JDKHttpClientConfig withProxy(Proxy proxy) { + this.proxy = proxy; + return this; + } + + public boolean isFollowRedirects() { + return followRedirects; + } + /** * Sets whether the underlying Http Connection follows redirects or not. * @@ -60,4 +75,19 @@ public Proxy getProxy() { public void setFollowRedirects(boolean followRedirects) { this.followRedirects = followRedirects; } + + /** + * Sets whether the underlying Http Connection follows redirects or not. + * + * Defaults to true (follow redirects) + * + * @see http://docs.oracle.com/javase/6/docs/api/java/net/HttpURLConnection.html#setInstanceFollowRedirects(boolean) + * @param followRedirects boolean + * @return this for chaining methods invocations + */ + public JDKHttpClientConfig withFollowRedirects(boolean followRedirects) { + this.followRedirects = followRedirects; + return this; + } } diff --git a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java index 19fc27f48..f9d494f52 100644 --- a/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java +++ b/scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java @@ -33,6 +33,8 @@ public ArmeriaHttpClientConfig(ClientOptions clientOptions, ClientFactory client /** * Creates new {@link HttpClientConfig} using default settings. + * + * @return new {@link HttpClientConfig} using default settings. */ @Override public HttpClientConfig createDefaultConfig() { @@ -62,14 +64,29 @@ public void setProtocolPreference(SessionProtocol protocolPreference) { this.protocolPreference = protocolPreference; } + public ArmeriaHttpClientConfig withProtocolPreference(SessionProtocol protocolPreference) { + setProtocolPreference(protocolPreference); + return this; + } + public void setRetry(Function retry) { this.retry = retry; } + public ArmeriaHttpClientConfig withRetry(Function retry) { + this.retry = retry; + return this; + } + public void setLogging(Function logging) { this.logging = logging; } + public ArmeriaHttpClientConfig withLogging(Function logging) { + this.logging = logging; + return this; + } + ArmeriaWebClientBuilder createClientBuilder() { return new ArmeriaWebClientBuilder(clientOptions, clientFactory, protocolPreference, retry, logging); } diff --git a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java index efad5cd25..c94d6b369 100644 --- a/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java +++ b/scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java @@ -47,9 +47,8 @@ protected HttpClient createNewClient() { .onStatus(HttpStatus.SERVICE_UNAVAILABLE) .onUnprocessed() .thenBackoff(retryBackoff); - config.setRetry(RetryingClient.newDecorator(retryRule)); - return new ArmeriaHttpClient(config); + return new ArmeriaHttpClient(config.withRetry(RetryingClient.newDecorator(retryRule))); } // No-Op DNS resolver to avoid resolution issues in the unit test diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClientConfig.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClientConfig.java index 9eb5d83c2..6e8842cc7 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClientConfig.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClientConfig.java @@ -20,6 +20,11 @@ public void setNingAsyncHttpProviderClassName(String ningAsyncHttpProviderClassN this.ningAsyncHttpProviderClassName = ningAsyncHttpProviderClassName; } + public NingHttpClientConfig withNingAsyncHttpProviderClassName(String ningAsyncHttpProviderClassName) { + this.ningAsyncHttpProviderClassName = ningAsyncHttpProviderClassName; + return this; + } + public AsyncHttpClientConfig getConfig() { return config; } From 440371e35cdbcdb192cb34ccd2438416ae83451b Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Thu, 27 Aug 2020 12:55:28 +0300 Subject: [PATCH 394/481] fix typo (change "Verfier" to "Verifier") (thanks to https://github.com/afkbrb) --- changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog b/changelog index 1b58bb61a..7c3fcde1b 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) + * fix typo (change "Verfier" to "Verifier") (thanks to https://github.com/afkbrb) [7.0.0] * Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) From 02efd0069de74ad5b318ee5c561e2a9aba615448 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Thu, 27 Aug 2020 13:05:53 +0300 Subject: [PATCH 395/481] update armeria to 1.0.0 --- pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 1c48b2b1e..1f250ab9f 100644 --- a/pom.xml +++ b/pom.xml @@ -167,7 +167,7 @@ org.apache.maven.plugins maven-resources-plugin - 3.1.0 + 3.2.0 UTF-8 diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index e1df25813..6e42a82a8 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -23,7 +23,7 @@ com.linecorp.armeria armeria - 0.99.9 + 1.0.0 com.github.scribejava From 3f7a5cba7ba47c9275ed71a63a9da8f42bd91499 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Fri, 28 Aug 2020 18:04:01 +0300 Subject: [PATCH 396/481] fix a bit Multipart CRLF handling and improve readability of unit tests --- .../httpclient/multipart/MultipartUtils.java | 11 +- .../multipart/MultipartUtilsTest.java | 125 ++++++++---------- 2 files changed, 59 insertions(+), 77 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java index dc42d4d60..4a01817f1 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java @@ -43,12 +43,12 @@ public static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload final String preamble = multipartPayload.getPreamble(); if (preamble != null) { - os.write(preamble.getBytes()); + os.write((preamble + "\r\n").getBytes()); } final List bodyParts = multipartPayload.getBodyParts(); if (!bodyParts.isEmpty()) { final String boundary = multipartPayload.getBoundary(); - final byte[] startBoundary = ("\r\n--" + boundary + "\r\n").getBytes(); + final byte[] startBoundary = ("--" + boundary + "\r\n").getBytes(); for (BodyPartPayload bodyPart : bodyParts) { os.write(startBoundary); @@ -60,20 +60,21 @@ public static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload } } + os.write("\r\n".getBytes()); if (bodyPart instanceof MultipartPayload) { getPayload((MultipartPayload) bodyPart).writeTo(os); } else if (bodyPart instanceof ByteArrayBodyPartPayload) { - os.write("\r\n".getBytes()); os.write(((ByteArrayBodyPartPayload) bodyPart).getPayload()); } else { throw new AssertionError(bodyPart.getClass()); } + os.write("\r\n".getBytes()); //CRLF for the next (starting or closing) boundary } - os.write(("\r\n--" + boundary + "--\r\n").getBytes()); + os.write(("--" + boundary + "--").getBytes()); final String epilogue = multipartPayload.getEpilogue(); if (epilogue != null) { - os.write((epilogue + "\r\n").getBytes()); + os.write(("\r\n" + epilogue).getBytes()); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java index cac5def30..6d26743ba 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java @@ -18,16 +18,18 @@ public class MultipartUtilsTest { public void testEmptyMultipartPayload() throws IOException { final MultipartPayload mP = new MultipartPayload(); - final StringBuilder sb = new StringBuilder(); + final StringBuilder headersString = new StringBuilder(); for (Map.Entry header : mP.getHeaders().entrySet()) { - sb.append(header.getKey()) + headersString.append(header.getKey()) .append(": ") .append(header.getValue()) .append("\r\n"); } - sb.append("\r\n").append(MultipartUtils.getPayload(mP).toString()); - assertEquals("Content-Type: multipart/form-data; boundary=\"" + mP.getBoundary() + "\"\r\n\r\n", sb.toString()); + assertEquals("Content-Type: multipart/form-data; boundary=\"" + mP.getBoundary() + "\"\r\n", + headersString.toString()); + + assertEquals("", MultipartUtils.getPayload(mP).toString()); } @Test @@ -51,36 +53,34 @@ public void testSimpleMultipartPayload() throws IOException { mP.setEpilogue("This is the epilogue. It is also to be ignored."); - final StringBuilder sb = new StringBuilder(); + final StringBuilder headersString = new StringBuilder(); for (Map.Entry header : mP.getHeaders().entrySet()) { - sb.append(header.getKey()) + headersString.append(header.getKey()) .append(": ") .append(header.getValue()) .append("\r\n"); } - sb.append("\r\n").append(MultipartUtils.getPayload(mP).toString()); + assertEquals("X-Header: X-Value\r\n" + "Content-Disposition: Content-Disposition-Value\r\n" - + "Content-Type: multipart/mixed; boundary=\"simple boundary\"\r\n" - + "\r\n" - + "This is the preamble. It is to be ignored, though it\n" + + "Content-Type: multipart/mixed; boundary=\"simple boundary\"\r\n", + headersString.toString()); + + assertEquals("This is the preamble. It is to be ignored, though it\n" + "is a handy place for composition agents to include an\n" + "explanatory note to non-MIME conformant readers." - + "\r\n" - + "--simple boundary\r\n" + + "\r\n--simple boundary\r\n" + "\r\n" + "This is implicitly typed plain US-ASCII text.\n" + "It does NOT end with a linebreak." - + "\r\n" - + "--simple boundary\r\n" + + "\r\n--simple boundary\r\n" + "Content-Type: text/plain; charset=us-ascii\r\n" + "\r\n" + "This is explicitly typed plain US-ASCII text.\n" + "It DOES end with a linebreak.\n" - + "\r\n" - + "--simple boundary--\r\n" - + "This is the epilogue. It is also to be ignored.\r\n", - sb.toString()); + + "\r\n--simple boundary--" + + "\r\nThis is the epilogue. It is also to be ignored.", + MultipartUtils.getPayload(mP).toString()); } @Test @@ -92,39 +92,33 @@ public void testCRLFMultipartPayload() throws IOException { mP.addBodyPart("It does end with a \\r\\n linebreak.\r\n".getBytes()); mP.addBodyPart("the last one".getBytes()); - final StringBuilder sb = new StringBuilder(); + final StringBuilder headersString = new StringBuilder(); for (Map.Entry header : mP.getHeaders().entrySet()) { - sb.append(header.getKey()) + headersString.append(header.getKey()) .append(": ") .append(header.getValue()) .append("\r\n"); } - sb.append("\r\n").append(MultipartUtils.getPayload(mP).toString()); - assertEquals("Content-Type: multipart/form-data; boundary=\"simple-boundary\"\r\n" - + "\r\n" - + "\r\n" - + "--simple-boundary\r\n" + + assertEquals("Content-Type: multipart/form-data; boundary=\"simple-boundary\"\r\n", headersString.toString()); + + assertEquals("--simple-boundary\r\n" + "\r\n" + "It does NOT end with a linebreak." - + "\r\n" - + "--simple-boundary\r\n" + + "\r\n--simple-boundary\r\n" + "\r\n" + "It does end with a \\r linebreak.\r" - + "\r\n" - + "--simple-boundary\r\n" + + "\r\n--simple-boundary\r\n" + "\r\n" + "It does end with a \\n linebreak.\n" - + "\r\n" - + "--simple-boundary\r\n" + + "\r\n--simple-boundary\r\n" + "\r\n" + "It does end with a \\r\\n linebreak.\r\n" - + "\r\n" - + "--simple-boundary\r\n" + + "\r\n--simple-boundary\r\n" + "\r\n" + "the last one" - + "\r\n" - + "--simple-boundary--\r\n", - sb.toString()); + + "\r\n--simple-boundary--", + MultipartUtils.getPayload(mP).toString()); } @Test @@ -132,27 +126,24 @@ public void testFileByteArrayBodyPartPayloadMultipartPayload() throws IOExceptio final MultipartPayload mP = new MultipartPayload("testFileByteArrayBodyPartPayloadMultipartPayload boundary"); mP.addBodyPart(new FileByteArrayBodyPartPayload("fileContent".getBytes(), "name", "filename.ext")); - final StringBuilder sb = new StringBuilder(); + final StringBuilder headersString = new StringBuilder(); for (Map.Entry header : mP.getHeaders().entrySet()) { - sb.append(header.getKey()) + headersString.append(header.getKey()) .append(": ") .append(header.getValue()) .append("\r\n"); } - sb.append("\r\n").append(MultipartUtils.getPayload(mP).toString()); assertEquals("Content-Type: multipart/form-data; " - + "boundary=\"testFileByteArrayBodyPartPayloadMultipartPayload boundary\"\r\n" - + "\r\n" - + "\r\n" - + "--testFileByteArrayBodyPartPayloadMultipartPayload boundary\r\n" + + "boundary=\"testFileByteArrayBodyPartPayloadMultipartPayload boundary\"\r\n", + headersString.toString()); + + assertEquals("--testFileByteArrayBodyPartPayloadMultipartPayload boundary\r\n" + "Content-Disposition: form-data; name=\"name\"; filename=\"filename.ext\"\r\n" + "\r\n" + "fileContent" - + "\r\n" - + "--testFileByteArrayBodyPartPayloadMultipartPayload boundary--\r\n", - sb.toString() - ); + + "\r\n--testFileByteArrayBodyPartPayloadMultipartPayload boundary--", + MultipartUtils.getPayload(mP).toString()); } @Test @@ -201,54 +192,46 @@ public void testComplexMultipartPayload() throws IOException { + "\n" + "... Additional text in ISO-8859-1 goes here ...\n").getBytes(), "message/rfc822"); - final StringBuilder sb = new StringBuilder(); + final StringBuilder headersString = new StringBuilder(); for (Map.Entry header : mP.getHeaders().entrySet()) { - sb.append(header.getKey()) + headersString.append(header.getKey()) .append(": ") .append(header.getValue()) .append("\r\n"); } - sb.append("\r\n").append(MultipartUtils.getPayload(mP).toString()); - assertEquals("Content-Type: multipart/mixed; boundary=\"unique-boundary-1\"\r\n" - + "\r\n" - + "This is the preamble area of a multipart message.\n" + assertEquals("Content-Type: multipart/mixed; boundary=\"unique-boundary-1\"\r\n", headersString.toString()); + + assertEquals("This is the preamble area of a multipart message.\n" + "Mail readers that understand multipart format\n" + "should ignore this preamble.\n" + "\n" + "If you are reading this text, you might want to\n" + "consider changing to a mail reader that understands\n" + "how to properly display multipart messages.\n" - + "\r\n" - + "--unique-boundary-1\r\n" + + "\r\n--unique-boundary-1\r\n" + "\r\n" + "... Some text appears here ..." - + "\r\n" - + "--unique-boundary-1\r\n" + + "\r\n--unique-boundary-1\r\n" + "Content-Type: text/plain; charset=US-ASCII\r\n" + "\r\n" + "This could have been part of the previous part, but\n" + "illustrates explicit versus implicit typing of body\n" + "parts.\n" - + "\r\n" - + "--unique-boundary-1\r\n" + + "\r\n--unique-boundary-1\r\n" + "Content-Type: multipart/parallel; boundary=\"unique-boundary-2\"\r\n" - + "\r\n" - + "--unique-boundary-2\r\n" + + "\r\n--unique-boundary-2\r\n" + "Content-Type: audio/basic\r\n" + "Content-Transfer-Encoding: base64\r\n" + "\r\n" + "... base64-encoded 8000 Hz single-channel\n" + " mu-law-format audio data goes here ..." - + "\r\n" - + "--unique-boundary-2\r\n" + + "\r\n--unique-boundary-2\r\n" + "Content-Type: image/jpeg\r\n" + "Content-Transfer-Encoding: base64\r\n" + "\r\n" + "... base64-encoded image data goes here ..." - + "\r\n" - + "--unique-boundary-2--\r\n" - + "\r\n" - + "--unique-boundary-1\r\n" + + "\r\n--unique-boundary-2--" + + "\r\n--unique-boundary-1\r\n" + "Content-Type: text/enriched\r\n" + "\r\n" + "This is enriched.\n" @@ -256,8 +239,7 @@ public void testComplexMultipartPayload() throws IOException { + "\n" + "Isn't it\n" + "cool?\n" - + "\r\n" - + "--unique-boundary-1\r\n" + + "\r\n--unique-boundary-1\r\n" + "Content-Type: message/rfc822\r\n" + "\r\n" + "From: (mailbox in US-ASCII)\n" @@ -267,9 +249,8 @@ public void testComplexMultipartPayload() throws IOException { + "Content-Transfer-Encoding: Quoted-printable\n" + "\n" + "... Additional text in ISO-8859-1 goes here ...\n" - + "\r\n" - + "--unique-boundary-1--\r\n", - sb.toString()); + + "\r\n--unique-boundary-1--", + MultipartUtils.getPayload(mP).toString()); } @Test From 5ac44578dcd0d8e113a0b36e045404b2600c2ac9 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 16:04:30 +0300 Subject: [PATCH 397/481] fix Multipart support in JDKHttpClient (thanks to https://github.com/eos1d3) --- changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog b/changelog index 7c3fcde1b..27e0079c8 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) * fix typo (change "Verfier" to "Verifier") (thanks to https://github.com/afkbrb) + * fix Multipart support in JDKHttpClient (thanks to https://github.com/eos1d3) [7.0.0] * Add Polar API (https://www.polar.com/) (thanks to https://github.com/vidi42) From 92b86e4702d0be7bdc4189ee4fff788c313b3c54 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 16:14:07 +0300 Subject: [PATCH 398/481] update deps --- pom.xml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 1f250ab9f..9a740ad66 100644 --- a/pom.xml +++ b/pom.xml @@ -104,7 +104,7 @@ com.puppycrawl.tools checkstyle - 8.35 + 8.36 @@ -126,11 +126,6 @@ maven-clean-plugin 3.1.0
    - - org.apache.maven.plugins - maven-enforcer-plugin - 1.4.1 - org.apache.maven.plugins maven-install-plugin @@ -274,7 +269,7 @@ 7 - 6.26.0 + 6.27.0 From 6388969b8d07021b90486f2d25ce8e23816913a1 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 17:47:54 +0300 Subject: [PATCH 399/481] prepare v7.1.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7e1a5ea34..c239f14ba 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 7.0.0 + 7.1.0 ``` @@ -142,7 +142,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 7.0.0 + 7.1.0 ``` diff --git a/changelog b/changelog index 27e0079c8..5b618aa08 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[7.1.0] * add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) * fix typo (change "Verfier" to "Verifier") (thanks to https://github.com/afkbrb) * fix Multipart support in JDKHttpClient (thanks to https://github.com/eos1d3) From 3374f30eaa93c904849dbd62886d63da9b1e1b58 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 18:04:11 +0300 Subject: [PATCH 400/481] [maven-release-plugin] prepare release scribejava-7.1.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 9a740ad66..cae7d8ad2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 7.0.1-SNAPSHOT + 7.1.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -35,7 +35,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-7.1.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 1509132ab..974e02f65 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 52856291f..aa935d40c 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index b604bff4d..f67ca4090 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 19151acab..a63371ad3 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 6e42a82a8..1ea52a7d9 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index e1956ea11..7ec8fcdfa 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index a364d2fcc..245389246 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.0 ../pom.xml From 785d997806ace82c67b7f711d9f36e60132d5d42 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 18:04:35 +0300 Subject: [PATCH 401/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index cae7d8ad2..d803884d8 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 7.1.0 + 7.1.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -35,7 +35,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-7.1.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 974e02f65..5ab03a194 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index aa935d40c..108ed7484 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index f67ca4090..5501543c0 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index a63371ad3..96ff1daf6 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 1ea52a7d9..e11eae975 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 7ec8fcdfa..3a10d359b 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 245389246..3b087ff4e 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.1.1-SNAPSHOT ../pom.xml From fc54cd7d81e89a15bdee3cc822978300d3ddc60f Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 18:53:14 +0300 Subject: [PATCH 402/481] Revert "[maven-release-plugin] prepare for next development iteration" This reverts commit 785d997806ace82c67b7f711d9f36e60132d5d42. --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index d803884d8..cae7d8ad2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 7.1.1-SNAPSHOT + 7.1.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -35,7 +35,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-7.1.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 5ab03a194..974e02f65 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 108ed7484..aa935d40c 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 5501543c0..f67ca4090 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 96ff1daf6..a63371ad3 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index e11eae975..1ea52a7d9 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 3a10d359b..7ec8fcdfa 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1-SNAPSHOT + 7.1.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 3b087ff4e..245389246 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1-SNAPSHOT + 7.1.0 ../pom.xml From d908a3a8bf4fc3c60fd6dd7b03849ec30163d5ab Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 18:53:20 +0300 Subject: [PATCH 403/481] Revert "[maven-release-plugin] prepare release scribejava-7.1.0" This reverts commit 3374f30eaa93c904849dbd62886d63da9b1e1b58. --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index cae7d8ad2..9a740ad66 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 7.1.0 + 7.0.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -35,7 +35,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-7.1.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 974e02f65..1509132ab 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index aa935d40c..52856291f 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index f67ca4090..b604bff4d 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index a63371ad3..19151acab 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 1ea52a7d9..6e42a82a8 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 7ec8fcdfa..e1956ea11 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 245389246..a364d2fcc 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.0 + 7.0.1-SNAPSHOT ../pom.xml From c55dd67d16205582e7a74e7394df3b821cc38375 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 18:53:25 +0300 Subject: [PATCH 404/481] Revert "prepare v7.1.0" This reverts commit 6388969b8d07021b90486f2d25ce8e23816913a1. --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c239f14ba..7e1a5ea34 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 7.1.0 + 7.0.0 ``` @@ -142,7 +142,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 7.1.0 + 7.0.0 ``` diff --git a/changelog b/changelog index 5b618aa08..27e0079c8 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[7.1.0] +[SNAPSHOT] * add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) * fix typo (change "Verfier" to "Verifier") (thanks to https://github.com/afkbrb) * fix Multipart support in JDKHttpClient (thanks to https://github.com/eos1d3) From 8aae9804c8d6bb28ca1ddb6b03a207aff2aa7651 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 18:54:55 +0300 Subject: [PATCH 405/481] prepare v7.1.1 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7e1a5ea34..e6426bc00 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 7.0.0 + 7.1.1 ``` @@ -142,7 +142,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 7.0.0 + 7.1.1 ``` diff --git a/changelog b/changelog index 27e0079c8..926f3af56 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[7.1.1] * add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) * fix typo (change "Verfier" to "Verifier") (thanks to https://github.com/afkbrb) * fix Multipart support in JDKHttpClient (thanks to https://github.com/eos1d3) From 101c1039fe70d0092a8a995d92ba99a7e461e4ef Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 18:56:07 +0300 Subject: [PATCH 406/481] [maven-release-plugin] prepare release scribejava-7.1.1 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 9a740ad66..d9d0d1802 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 7.0.1-SNAPSHOT + 7.1.1 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -35,7 +35,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-7.1.1 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 1509132ab..891373d8e 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.1 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 52856291f..47ee01211 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.1 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index b604bff4d..e6fd0e903 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.1 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 19151acab..f5a0e5537 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.1 ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 6e42a82a8..968e883b4 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.1 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index e1956ea11..0f857c963 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.1 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index a364d2fcc..3449005e8 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.0.1-SNAPSHOT + 7.1.1 ../pom.xml From 7d128d31a4dfe3bee7e3edd5732cf4fa19d0c89e Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Sep 2020 18:56:15 +0300 Subject: [PATCH 407/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index d9d0d1802..69c7cb46d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 7.1.1 + 7.1.2-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -35,7 +35,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-7.1.1 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 891373d8e..24dbcaa1e 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1 + 7.1.2-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 47ee01211..79a016cf2 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1 + 7.1.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index e6fd0e903..6b6d8578b 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1 + 7.1.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index f5a0e5537..393c4fc83 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1 + 7.1.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 968e883b4..9c7325e58 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1 + 7.1.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 0f857c963..cf992b25a 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1 + 7.1.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 3449005e8..0ad7a7540 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.1 + 7.1.2-SNAPSHOT ../pom.xml From 01aa0b2526d50f3ee1caa8c13404ac951aa67661 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Thu, 17 Sep 2020 19:50:32 +0300 Subject: [PATCH 408/481] * add Kakao API (https://kakao.com/) (thanks to https://github.com/v0o0v) --- README.md | 1 + changelog | 3 +++ .../src/main/java/com/github/scribejava/apis/HHApi.java | 1 + .../src/main/java/com/github/scribejava/apis/KakaoApi.java | 1 + .../java/com/github/scribejava/apis/examples/KakaoExample.java | 2 +- 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e6426bc00..f3d1c4149 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ ScribeJava support out-of-box several HTTP clients: * HiOrg-Server (https://www.hiorg-server.de/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java) * Imgur (http://imgur.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java) * Kaixin 开心网 (http://www.kaixin001.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java) +* Kakao (https://kakao.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KakaoExample.java) * Keycloak (https://www.keycloak.org/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java) * LinkedIn (https://www.linkedin.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExample.java), [example with custom scopes](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedInExampleWithScopes.java) * Mail.Ru (https://mail.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruExample.java), [example with Async Ning HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/MailruAsyncExample.java) diff --git a/changelog b/changelog index 926f3af56..a30a391ea 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * add Kakao API (https://kakao.com/) (thanks to https://github.com/v0o0v) + [7.1.1] * add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) * fix typo (change "Verfier" to "Verifier") (thanks to https://github.com/afkbrb) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java index bd1224fe6..61476eaef 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/HHApi.java @@ -10,6 +10,7 @@ protected HHApi() { } private static class InstanceHolder { + private static final HHApi INSTANCE = new HHApi(); } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/KakaoApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/KakaoApi.java index 948705496..6587fe32f 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/KakaoApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/KakaoApi.java @@ -10,6 +10,7 @@ protected KakaoApi() { } private static class InstanceHolder { + private static final KakaoApi INSTANCE = new KakaoApi(); } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KakaoExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KakaoExample.java index 89b7b4f1d..643182ea8 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KakaoExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KakaoExample.java @@ -22,7 +22,7 @@ private KakaoExample() { @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { - // Replace these with your client id and secret + // Replace this with your client id final String clientId = "your client id"; final OAuth20Service service = new ServiceBuilder(clientId) From acb09724868ad29da24ab9ce210418c606922428 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 22 Sep 2020 16:48:20 +0300 Subject: [PATCH 409/481] support chunks in JDKHttpClient's Multipart (thanks to https://github.com/eos1d3) --- changelog | 1 + .../httpclient/multipart/BodyPartPayload.java | 6 +- .../multipart/ByteArrayBodyPartPayload.java | 36 +++- .../FileByteArrayBodyPartPayload.java | 25 +++ .../multipart/MultipartPayload.java | 65 +++++++ .../httpclient/multipart/MultipartUtils.java | 3 +- .../scribejava/core/model/OAuthRequest.java | 171 +++++++++++++++++- .../multipart/MultipartUtilsTest.java | 35 ++-- 8 files changed, 316 insertions(+), 26 deletions(-) diff --git a/changelog b/changelog index a30a391ea..9f29b77ef 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * add Kakao API (https://kakao.com/) (thanks to https://github.com/v0o0v) + * support chunks in JDKHttpClient's Multipart (thanks to https://github.com/eos1d3) [7.1.1] * add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/BodyPartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/BodyPartPayload.java index ee426176b..ddd6e9cb2 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/BodyPartPayload.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/BodyPartPayload.java @@ -13,7 +13,7 @@ public BodyPartPayload() { } public BodyPartPayload(String contentType) { - this(contentType == null ? null : Collections.singletonMap(HttpClient.CONTENT_TYPE, contentType)); + this(convertContentTypeToHeaders(contentType)); } public BodyPartPayload(Map headers) { @@ -23,4 +23,8 @@ public BodyPartPayload(Map headers) { public Map getHeaders() { return headers; } + + protected static Map convertContentTypeToHeaders(String contentType) { + return contentType == null ? null : Collections.singletonMap(HttpClient.CONTENT_TYPE, contentType); + } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/ByteArrayBodyPartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/ByteArrayBodyPartPayload.java index 7fd0d6d98..c706d7481 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/ByteArrayBodyPartPayload.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/ByteArrayBodyPartPayload.java @@ -5,22 +5,46 @@ public class ByteArrayBodyPartPayload extends BodyPartPayload { private final byte[] payload; + private final int off; + private final int len; - public ByteArrayBodyPartPayload(byte[] payload) { + public ByteArrayBodyPartPayload(byte[] payload, int off, int len, Map headers) { + super(headers); this.payload = payload; + this.off = off; + this.len = len; + } + + public ByteArrayBodyPartPayload(byte[] payload, Map headers) { + this(payload, 0, payload.length, headers); } public ByteArrayBodyPartPayload(byte[] payload, String contentType) { - super(contentType); - this.payload = payload; + this(payload, convertContentTypeToHeaders(contentType)); } - public ByteArrayBodyPartPayload(byte[] payload, Map headers) { - super(headers); - this.payload = payload; + public ByteArrayBodyPartPayload(byte[] payload, int off, int len, String contentType) { + this(payload, off, len, convertContentTypeToHeaders(contentType)); + } + + public ByteArrayBodyPartPayload(byte[] payload) { + this(payload, (Map) null); + } + + public ByteArrayBodyPartPayload(byte[] payload, int off, int len) { + this(payload, off, len, (Map) null); } public byte[] getPayload() { return payload; } + + public int getOff() { + return off; + } + + public int getLen() { + return len; + } + } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/FileByteArrayBodyPartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/FileByteArrayBodyPartPayload.java index 524977819..41b3e72bf 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/FileByteArrayBodyPartPayload.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/FileByteArrayBodyPartPayload.java @@ -11,26 +11,51 @@ public FileByteArrayBodyPartPayload(byte[] payload) { this(payload, null); } + public FileByteArrayBodyPartPayload(byte[] payload, int off, int len) { + this(payload, off, len, null); + } + public FileByteArrayBodyPartPayload(byte[] payload, String name) { this(payload, name, null); } + public FileByteArrayBodyPartPayload(byte[] payload, int off, int len, String name) { + this(payload, off, len, name, null); + } + public FileByteArrayBodyPartPayload(byte[] payload, String name, String filename) { this(null, payload, name, filename); } + public FileByteArrayBodyPartPayload(byte[] payload, int off, int len, String name, String filename) { + this(null, payload, off, len, name, filename); + } + public FileByteArrayBodyPartPayload(String contentType, byte[] payload) { this(contentType, payload, null); } + public FileByteArrayBodyPartPayload(String contentType, byte[] payload, int off, int len) { + this(contentType, payload, off, len, null); + } + public FileByteArrayBodyPartPayload(String contentType, byte[] payload, String name) { this(contentType, payload, name, null); } + public FileByteArrayBodyPartPayload(String contentType, byte[] payload, int off, int len, String name) { + this(contentType, payload, off, len, name, null); + } + public FileByteArrayBodyPartPayload(String contentType, byte[] payload, String name, String filename) { super(payload, composeHeaders(contentType, name, filename)); } + public FileByteArrayBodyPartPayload(String contentType, byte[] payload, int off, int len, String name, + String filename) { + super(payload, off, len, composeHeaders(contentType, name, filename)); + } + private static Map composeHeaders(String contentType, String name, String filename) { String contentDispositionHeader = "form-data"; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java index e68bb6465..6f7a5b093 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java @@ -72,26 +72,71 @@ private static String parseOrGenerateBoundary(Map headers) { return parsedBoundary == null ? MultipartUtils.generateDefaultBoundary() : parsedBoundary; } + /** + * + * @param fileContent fileContent + * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileBodyPart(byte[] fileContent) { addBodyPart(new FileByteArrayBodyPartPayload(fileContent)); } + /** + * + * @param fileContent fileContent + * @param name name + * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileBodyPart(byte[] fileContent, String name) { addBodyPart(new FileByteArrayBodyPartPayload(fileContent, name)); } + /** + * + * @param fileContent fileContent + * @param name name + * @param filename filename + * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileBodyPart(byte[] fileContent, String name, String filename) { addBodyPart(new FileByteArrayBodyPartPayload(fileContent, name, filename)); } + /** + * + * @param contentType contentType + * @param fileContent fileContent + * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileBodyPart(String contentType, byte[] fileContent) { addBodyPart(new FileByteArrayBodyPartPayload(contentType, fileContent)); } + /** + * + * @param contentType contentType + * @param fileContent fileContent + * @param name name + * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileBodyPart(String contentType, byte[] fileContent, String name) { addBodyPart(new FileByteArrayBodyPartPayload(contentType, fileContent, name)); } + /** + * + * @param contentType contentType + * @param fileContent fileContent + * @param name name + * @param filename filename + * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileBodyPart(String contentType, byte[] fileContent, String name, String filename) { addBodyPart(new FileByteArrayBodyPartPayload(contentType, fileContent, name, filename)); } @@ -108,14 +153,34 @@ public void addBodyPart(MultipartPayload multipartPayload) { bodyParts.add(multipartPayload); } + /** + * + * @param bodyPartPayload bodyPartPayload + * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addBodyPart(byte[] bodyPartPayload) { addBodyPart(new ByteArrayBodyPartPayload(bodyPartPayload)); } + /** + * + * @param bodyPartPayload bodyPartPayload + * @param contentType contentType + * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addBodyPart(byte[] bodyPartPayload, String contentType) { addBodyPart(new ByteArrayBodyPartPayload(bodyPartPayload, contentType)); } + /** + * + * @param bodyPartPayload bodyPartPayload + * @param headers headers + * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addBodyPart(byte[] bodyPartPayload, Map headers) { addBodyPart(new ByteArrayBodyPartPayload(bodyPartPayload, headers)); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java index 4a01817f1..bdbeaf542 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartUtils.java @@ -64,7 +64,8 @@ public static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload if (bodyPart instanceof MultipartPayload) { getPayload((MultipartPayload) bodyPart).writeTo(os); } else if (bodyPart instanceof ByteArrayBodyPartPayload) { - os.write(((ByteArrayBodyPartPayload) bodyPart).getPayload()); + final ByteArrayBodyPartPayload byteArrayBodyPart = (ByteArrayBodyPartPayload) bodyPart; + os.write(byteArrayBodyPart.getPayload(), byteArrayBodyPart.getOff(), byteArrayBodyPart.getLen()); } else { throw new AssertionError(bodyPart.getClass()); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index 79c66695f..2194545fa 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -1,6 +1,7 @@ package com.github.scribejava.core.model; import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.httpclient.multipart.BodyPartPayload; import com.github.scribejava.core.httpclient.multipart.FileByteArrayBodyPartPayload; import com.github.scribejava.core.httpclient.multipart.MultipartPayload; import java.io.File; @@ -160,100 +161,268 @@ public void initMultipartPayload(String subtype, String boundary, Map headers) { initMultipartPayload(); addByteArrayBodyPartPayloadInMultipartPayload(bodyPartPayload, headers); } + /** + * + * @param bodyPartPayload bodyPartPayload + * @deprecated use + * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addByteArrayBodyPartPayloadInMultipartPayload(byte[] bodyPartPayload) { multipartPayload.addBodyPart(bodyPartPayload); } + /** + * + * @param bodyPartPayload bodyPartPayload + * @param contentType contentType + * @deprecated use + * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addByteArrayBodyPartPayloadInMultipartPayload(byte[] bodyPartPayload, String contentType) { multipartPayload.addBodyPart(bodyPartPayload, contentType); } + /** + * + * @param bodyPartPayload bodyPartPayload + * @param headers headers + * @deprecated use + * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addByteArrayBodyPartPayloadInMultipartPayload(byte[] bodyPartPayload, Map headers) { multipartPayload.addBodyPart(bodyPartPayload, headers); } + /** + * + * @param fileContent fileContent + * @deprecated use + * {@link #setBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void setFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent) { initMultipartPayload(); addFileByteArrayBodyPartPayloadInMultipartPayload(fileContent); } + /** + * + * @param contentType contentType + * @param fileContent fileContent + * @deprecated use + * {@link #setBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void setFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent) { initMultipartPayload(); addFileByteArrayBodyPartPayloadInMultipartPayload(contentType, fileContent); } + /** + * + * @param fileContent fileContent + * @param name name + * @deprecated use + * {@link #setBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void setFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent, String name) { initMultipartPayload(); addFileByteArrayBodyPartPayloadInMultipartPayload(fileContent, name); } + /** + * + * @param contentType contentType + * @param fileContent fileContent + * @param name name + * @deprecated use + * {@link #setBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void setFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent, String name) { initMultipartPayload(); addFileByteArrayBodyPartPayloadInMultipartPayload(contentType, fileContent, name); } + /** + * + * @param fileContent fileContent + * @param name name + * @param filename filename + * @deprecated use + * {@link #setBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void setFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent, String name, String filename) { initMultipartPayload(); addFileByteArrayBodyPartPayloadInMultipartPayload(fileContent, name, filename); } + /** + * + * @param contentType contentType + * @param fileContent fileContent + * @param name name + * @param filename filename + * @deprecated use + * {@link #setBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void setFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent, String name, String filename) { initMultipartPayload(); addFileByteArrayBodyPartPayloadInMultipartPayload(contentType, fileContent, name, filename); } + /** + * + * @param fileByteArrayBodyPartPayload fileByteArrayBodyPartPayload + * @deprecated use + * {@link #setBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void setFileByteArrayBodyPartPayloadInMultipartPayload( FileByteArrayBodyPartPayload fileByteArrayBodyPartPayload) { + setBodyPartPayloadInMultipartPayload(fileByteArrayBodyPartPayload); + } + + public void setBodyPartPayloadInMultipartPayload(BodyPartPayload bodyPartPayload) { initMultipartPayload(); - addFileByteArrayBodyPartPayloadInMultipartPayload(fileByteArrayBodyPartPayload); + addBodyPartPayloadInMultipartPayload(bodyPartPayload); } + /** + * + * @param fileContent fileContent + * @deprecated use + * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent) { multipartPayload.addFileBodyPart(fileContent); } + /** + * + * @param contentType contentType + * @param fileContent fileContent + * @deprecated use + * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent) { multipartPayload.addFileBodyPart(contentType, fileContent); } + /** + * + * @param fileContent fileContent + * @param name name + * @deprecated use + * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent, String name) { multipartPayload.addFileBodyPart(fileContent, name); } + /** + * @param contentType contentType + * @param fileContent fileContent + * @param name name + * @deprecated use + * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent, String name) { multipartPayload.addFileBodyPart(contentType, fileContent, name); } + /** + * + * @param fileContent fileContent + * @param name name + * @param filename filename + * @deprecated use + * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent, String name, String filename) { multipartPayload.addFileBodyPart(fileContent, name, filename); } + /** + * @param contentType contentType + * @param fileContent fileContent + * @param name name + * @param filename filename + * @deprecated use + * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent, String name, String filename) { multipartPayload.addFileBodyPart(contentType, fileContent, name, filename); } + /** + * + * @param fileByteArrayBodyPartPayload fileByteArrayBodyPartPayload + * @deprecated use + * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} + */ + @Deprecated public void addFileByteArrayBodyPartPayloadInMultipartPayload( FileByteArrayBodyPartPayload fileByteArrayBodyPartPayload) { multipartPayload.addBodyPart(fileByteArrayBodyPartPayload); } + public void addBodyPartPayloadInMultipartPayload(BodyPartPayload bodyPartPayload) { + multipartPayload.addBodyPart(bodyPartPayload); + } + /** * Set body payload. This method is used when the HTTP body is not a form-url-encoded string, but another thing. * Like for example XML. Note: The contents are not part of the OAuth signature diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java index 6d26743ba..c726dd9a7 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/httpclient/multipart/MultipartUtilsTest.java @@ -42,8 +42,8 @@ public void testSimpleMultipartPayload() throws IOException { + "is a handy place for composition agents to include an\n" + "explanatory note to non-MIME conformant readers."); - mP.addBodyPart(("This is implicitly typed plain US-ASCII text.\n" - + "It does NOT end with a linebreak.").getBytes()); + mP.addBodyPart(new ByteArrayBodyPartPayload(("This is implicitly typed plain US-ASCII text.\n" + + "It does NOT end with a linebreak.").getBytes())); final ByteArrayBodyPartPayload bP = new ByteArrayBodyPartPayload( ("This is explicitly typed plain US-ASCII text.\n" @@ -86,11 +86,11 @@ public void testSimpleMultipartPayload() throws IOException { @Test public void testCRLFMultipartPayload() throws IOException { final MultipartPayload mP = new MultipartPayload("simple-boundary"); - mP.addBodyPart("It does NOT end with a linebreak.".getBytes()); - mP.addBodyPart("It does end with a \\r linebreak.\r".getBytes()); - mP.addBodyPart("It does end with a \\n linebreak.\n".getBytes()); - mP.addBodyPart("It does end with a \\r\\n linebreak.\r\n".getBytes()); - mP.addBodyPart("the last one".getBytes()); + mP.addBodyPart(new ByteArrayBodyPartPayload("It does NOT end with a linebreak.".getBytes())); + mP.addBodyPart(new ByteArrayBodyPartPayload("It does end with a \\r linebreak.\r".getBytes())); + mP.addBodyPart(new ByteArrayBodyPartPayload("It does end with a \\n linebreak.\n".getBytes())); + mP.addBodyPart(new ByteArrayBodyPartPayload("It does end with a \\r\\n linebreak.\r\n".getBytes())); + mP.addBodyPart(new ByteArrayBodyPartPayload("the last one".getBytes())); final StringBuilder headersString = new StringBuilder(); for (Map.Entry header : mP.getHeaders().entrySet()) { @@ -158,11 +158,11 @@ public void testComplexMultipartPayload() throws IOException { + "consider changing to a mail reader that understands\n" + "how to properly display multipart messages.\n"); - mP.addBodyPart("... Some text appears here ...".getBytes()); + mP.addBodyPart(new ByteArrayBodyPartPayload("... Some text appears here ...".getBytes())); - mP.addBodyPart(("This could have been part of the previous part, but\n" + mP.addBodyPart(new ByteArrayBodyPartPayload(("This could have been part of the previous part, but\n" + "illustrates explicit versus implicit typing of body\n" - + "parts.\n").getBytes(), "text/plain; charset=US-ASCII"); + + "parts.\n").getBytes(), "text/plain; charset=US-ASCII")); final MultipartPayload innerMP = new MultipartPayload("parallel", "unique-boundary-2"); mP.addBodyPart(innerMP); @@ -170,27 +170,28 @@ public void testComplexMultipartPayload() throws IOException { final Map audioHeaders = new LinkedHashMap<>(); audioHeaders.put("Content-Type", "audio/basic"); audioHeaders.put("Content-Transfer-Encoding", "base64"); - innerMP.addBodyPart(("... base64-encoded 8000 Hz single-channel\n" - + " mu-law-format audio data goes here ...").getBytes(), audioHeaders); + innerMP.addBodyPart(new ByteArrayBodyPartPayload(("... base64-encoded 8000 Hz single-channel\n" + + " mu-law-format audio data goes here ...").getBytes(), audioHeaders)); final Map imageHeaders = new LinkedHashMap<>(); imageHeaders.put("Content-Type", "image/jpeg"); imageHeaders.put("Content-Transfer-Encoding", "base64"); - innerMP.addBodyPart("... base64-encoded image data goes here ...".getBytes(), imageHeaders); + innerMP.addBodyPart(new ByteArrayBodyPartPayload("... base64-encoded image data goes here ...".getBytes(), + imageHeaders)); - mP.addBodyPart(("This is enriched.\n" + mP.addBodyPart(new ByteArrayBodyPartPayload(("This is enriched.\n" + "as defined in RFC 1896\n" + "\n" + "Isn't it\n" - + "cool?\n").getBytes(), "text/enriched"); + + "cool?\n").getBytes(), "text/enriched")); - mP.addBodyPart(("From: (mailbox in US-ASCII)\n" + mP.addBodyPart(new ByteArrayBodyPartPayload(("From: (mailbox in US-ASCII)\n" + "To: (address in US-ASCII)\n" + "Subject: (subject in US-ASCII)\n" + "Content-Type: Text/plain; charset=ISO-8859-1\n" + "Content-Transfer-Encoding: Quoted-printable\n" + "\n" - + "... Additional text in ISO-8859-1 goes here ...\n").getBytes(), "message/rfc822"); + + "... Additional text in ISO-8859-1 goes here ...\n").getBytes(), "message/rfc822")); final StringBuilder headersString = new StringBuilder(); for (Map.Entry header : mP.getHeaders().entrySet()) { From 08d6ecb0bc140b4f25bafea489e77ae7bc6f350c Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Mon, 9 Nov 2020 10:17:28 +0300 Subject: [PATCH 410/481] add support for OAuth 2.0 Device Authorization Grant (RFC 8628) (thanks to https://github.com/rebarbora-mckvak) --- README.md | 1 + changelog | 1 + .../github/scribejava/apis/GoogleApi20.java | 19 +- ...oogleDeviceAuthorizationJsonExtractor.java | 25 ++ .../BaseMicrosoftAzureActiveDirectoryApi.java | 5 - ...ogle20DeviceAuthorizationGrantExample.java | 82 ++++++ .../apis/examples/Google20Example.java | 4 +- .../core/builder/api/DefaultApi20.java | 16 +- .../extractors/AbstractJsonExtractor.java | 22 ++ .../DeviceAuthorizationJsonExtractor.java | 64 +++++ .../OAuth2AccessTokenJsonExtractor.java | 18 +- .../core/model/DeviceAuthorization.java | 105 ++++++++ .../scribejava/core/model/DeviceCode.java | 38 --- .../scribejava/core/oauth/OAuth20Service.java | 241 ++++++++++++------ .../scribejava/core/oauth2/OAuth2Error.java | 21 +- 15 files changed, 496 insertions(+), 166 deletions(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleDeviceAuthorizationJsonExtractor.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20DeviceAuthorizationGrantExample.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractJsonExtractor.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/extractors/DeviceAuthorizationJsonExtractor.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceAuthorization.java delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceCode.java diff --git a/README.md b/README.md index f3d1c4149..8c7f3a07a 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ ScribeJava support out-of-box several HTTP clients: * [RFC 6750](https://tools.ietf.org/html/rfc6750) The OAuth 2.0 Authorization Framework: Bearer Token Usage * [RFC 7636](https://tools.ietf.org/html/rfc7636) Proof Key for Code Exchange by OAuth Public Clients (PKCE), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20WithPKCEExample.java) * [RFC 7009](https://tools.ietf.org/html/rfc7009) OAuth 2.0 Token Revocation, [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20RevokeExample.java) + * [RFC 8628](https://tools.ietf.org/html/rfc8628) OAuth 2.0 Device Authorization Grant [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20DeviceAuthorizationGrantExample.java) * [RFC 5849](https://tools.ietf.org/html/rfc5849) The OAuth 1.0 Protocol, [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TwitterExample.java) ### Supports all (50+) major 1.0a and 2.0 OAuth APIs out-of-the-box diff --git a/changelog b/changelog index 9f29b77ef..c029807e2 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * add Kakao API (https://kakao.com/) (thanks to https://github.com/v0o0v) * support chunks in JDKHttpClient's Multipart (thanks to https://github.com/eos1d3) + * add support for OAuth 2.0 Device Authorization Grant (RFC 8628) (thanks to https://github.com/rebarbora-mckvak) [7.1.1] * add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java index b4ab24d39..e3de4c746 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/GoogleApi20.java @@ -1,7 +1,9 @@ package com.github.scribejava.apis; +import com.github.scribejava.apis.google.GoogleDeviceAuthorizationJsonExtractor; import com.github.scribejava.apis.openid.OpenIdJsonTokenExtractor; import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.DeviceAuthorizationJsonExtractor; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.model.OAuth2AccessToken; @@ -11,6 +13,7 @@ protected GoogleApi20() { } private static class InstanceHolder { + private static final GoogleApi20 INSTANCE = new GoogleApi20(); } @@ -20,12 +23,12 @@ public static GoogleApi20 instance() { @Override public String getAccessTokenEndpoint() { - return "https://www.googleapis.com/oauth2/v4/token"; + return "https://oauth2.googleapis.com/token"; } @Override protected String getAuthorizationBaseUrl() { - return "https://accounts.google.com/o/oauth2/auth"; + return "https://accounts.google.com/o/oauth2/v2/auth"; } @Override @@ -35,6 +38,16 @@ public TokenExtractor getAccessTokenExtractor() { @Override public String getRevokeTokenEndpoint() { - return "https://accounts.google.com/o/oauth2/revoke"; + return "https://oauth2.googleapis.com/revoke"; + } + + @Override + public String getDeviceAuthorizationEndpoint() { + return "https://oauth2.googleapis.com/device/code"; + } + + @Override + public DeviceAuthorizationJsonExtractor getDeviceAuthorizationExtractor() { + return GoogleDeviceAuthorizationJsonExtractor.instance(); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleDeviceAuthorizationJsonExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleDeviceAuthorizationJsonExtractor.java new file mode 100644 index 000000000..d3dd77772 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/google/GoogleDeviceAuthorizationJsonExtractor.java @@ -0,0 +1,25 @@ +package com.github.scribejava.apis.google; + +import com.github.scribejava.core.extractors.DeviceAuthorizationJsonExtractor; + +public class GoogleDeviceAuthorizationJsonExtractor extends DeviceAuthorizationJsonExtractor { + + protected GoogleDeviceAuthorizationJsonExtractor() { + } + + private static class InstanceHolder { + + private static final GoogleDeviceAuthorizationJsonExtractor INSTANCE + = new GoogleDeviceAuthorizationJsonExtractor(); + } + + public static GoogleDeviceAuthorizationJsonExtractor instance() { + return GoogleDeviceAuthorizationJsonExtractor.InstanceHolder.INSTANCE; + } + + @Override + protected String getVerificationUriParamName() { + return "verification_url"; + } + +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java index 8dc5d5616..5e4891164 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/microsoftazureactivedirectory/BaseMicrosoftAzureActiveDirectoryApi.java @@ -30,11 +30,6 @@ protected String getAuthorizationBaseUrl() { return MSFT_LOGIN_URL + tenant + OAUTH_2 + getEndpointVersionPath() + "/authorize"; } - @Override - public String getDeviceAuthorizationUrl() { - return MSFT_LOGIN_URL + tenant + OAUTH_2 + getEndpointVersionPath() + "/devicecode"; - } - @Override public ClientAuthentication getClientAuthentication() { return RequestBodyAuthenticationScheme.instance(); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20DeviceAuthorizationGrantExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20DeviceAuthorizationGrantExample.java new file mode 100644 index 000000000..fc361e13f --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20DeviceAuthorizationGrantExample.java @@ -0,0 +1,82 @@ +package com.github.scribejava.apis.examples; + +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.apis.GoogleApi20; +import com.github.scribejava.core.model.DeviceAuthorization; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import java.io.IOException; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; + +public class Google20DeviceAuthorizationGrantExample { + + private static final String NETWORK_NAME = "Google"; + private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/oauth2/v3/userinfo"; + + private Google20DeviceAuthorizationGrantExample() { + } + + @SuppressWarnings("PMD.SystemPrintln") + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "your client id"; + final String clientSecret = "your_client_secret"; + + final OAuth20Service service = new ServiceBuilder(clientId) + .debug() + .apiSecret(clientSecret) + .defaultScope("profile") // replace with desired scope + .build(GoogleApi20.instance()); + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + System.out.println("Requesting a set of verification codes..."); + + final DeviceAuthorization deviceAuthorization = service.getDeviceAuthorizationCodes(); + System.out.println("Got the Device Authorization Codes!"); + System.out.println(deviceAuthorization); + + System.out.println("Now go and authorize ScribeJava. Visit: " + deviceAuthorization.getVerificationUri() + + " and enter the code: " + deviceAuthorization.getUserCode()); + if (deviceAuthorization.getVerificationUriComplete() != null) { + System.out.println("Or visit " + deviceAuthorization.getVerificationUriComplete()); + } + + System.out.println("Polling for an Access Token..."); + final OAuth2AccessToken accessToken = service.pollAccessTokenDeviceAuthorizationGrant(deviceAuthorization); + + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + while (true) { + System.out.println("Paste fieldnames to fetch (leave empty to get profile, 'exit' to stop the example)"); + System.out.print(">>"); + final String query = in.nextLine(); + System.out.println(); + final String requestUrl; + if ("exit".equals(query)) { + break; + } else if (query == null || query.isEmpty()) { + requestUrl = PROTECTED_RESOURCE_URL; + } else { + requestUrl = PROTECTED_RESOURCE_URL + "?fields=" + query; + } + final OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl); + service.signRequest(accessToken, request); + System.out.println(); + try (Response response = service.execute(request)) { + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } + System.out.println(); + } + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java index 6631849bf..ca70409f4 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java @@ -25,8 +25,8 @@ private Google20Example() { @SuppressWarnings("PMD.SystemPrintln") public static void main(String... args) throws IOException, InterruptedException, ExecutionException { // Replace these with your client id and secret - final String clientId = "your client id"; - final String clientSecret = "your client secret"; + final String clientId = "your_client_id"; + final String clientSecret = "your_client_secret"; final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java index ad1afcc65..76ef6dbce 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/api/DefaultApi20.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.builder.api; +import com.github.scribejava.core.extractors.DeviceAuthorizationJsonExtractor; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.extractors.TokenExtractor; import com.github.scribejava.core.httpclient.HttpClient; @@ -122,7 +123,18 @@ public ClientAuthentication getClientAuthentication() { return HttpBasicAuthenticationScheme.instance(); } - public String getDeviceAuthorizationUrl() { - return null; + /** + * RFC 8628 OAuth 2.0 Device Authorization Grant + * + * @see RFC 8628 + * @return the device authorization endpoint + */ + public String getDeviceAuthorizationEndpoint() { + throw new UnsupportedOperationException( + "This API doesn't support Device Authorization Grant or we have no info about this"); + } + + public DeviceAuthorizationJsonExtractor getDeviceAuthorizationExtractor() { + return DeviceAuthorizationJsonExtractor.instance(); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractJsonExtractor.java new file mode 100644 index 000000000..4a592a706 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/AbstractJsonExtractor.java @@ -0,0 +1,22 @@ +package com.github.scribejava.core.extractors; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.scribejava.core.exceptions.OAuthException; + +public abstract class AbstractJsonExtractor { + + protected static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + protected static JsonNode extractRequiredParameter(JsonNode errorNode, String parameterName, String rawResponse) + throws OAuthException { + final JsonNode value = errorNode.get(parameterName); + + if (value == null) { + throw new OAuthException("Response body is incorrect. Can't extract a '" + parameterName + + "' from this: '" + rawResponse + "'", null); + } + + return value; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/DeviceAuthorizationJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/DeviceAuthorizationJsonExtractor.java new file mode 100644 index 000000000..14e09f28d --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/DeviceAuthorizationJsonExtractor.java @@ -0,0 +1,64 @@ +package com.github.scribejava.core.extractors; + +import static com.github.scribejava.core.extractors.AbstractJsonExtractor.OBJECT_MAPPER; +import static com.github.scribejava.core.extractors.AbstractJsonExtractor.extractRequiredParameter; +import com.fasterxml.jackson.databind.JsonNode; +import com.github.scribejava.core.model.DeviceAuthorization; +import java.io.IOException; +import com.github.scribejava.core.model.Response; + +public class DeviceAuthorizationJsonExtractor extends AbstractJsonExtractor { + + protected DeviceAuthorizationJsonExtractor() { + } + + private static class InstanceHolder { + + private static final DeviceAuthorizationJsonExtractor INSTANCE = new DeviceAuthorizationJsonExtractor(); + } + + public static DeviceAuthorizationJsonExtractor instance() { + return InstanceHolder.INSTANCE; + } + + public DeviceAuthorization extract(Response response) throws IOException { + + final String body = response.getBody(); + + if (response.getCode() != 200) { + generateError(body); + } + return createDeviceAuthorization(body); + } + + public void generateError(String rawResponse) throws IOException { + OAuth2AccessTokenJsonExtractor.instance().generateError(rawResponse); + } + + private DeviceAuthorization createDeviceAuthorization(String rawResponse) throws IOException { + + final JsonNode response = OBJECT_MAPPER.readTree(rawResponse); + + final DeviceAuthorization deviceAuthorization = new DeviceAuthorization( + extractRequiredParameter(response, "device_code", rawResponse).textValue(), + extractRequiredParameter(response, "user_code", rawResponse).textValue(), + extractRequiredParameter(response, getVerificationUriParamName(), rawResponse).textValue(), + extractRequiredParameter(response, "expires_in", rawResponse).intValue()); + + final JsonNode intervalSeconds = response.get("interval"); + if (intervalSeconds != null) { + deviceAuthorization.setIntervalSeconds(intervalSeconds.asInt(5)); + } + + final JsonNode verificationUriComplete = response.get("verification_uri_complete"); + if (verificationUriComplete != null) { + deviceAuthorization.setVerificationUriComplete(verificationUriComplete.asText()); + } + + return deviceAuthorization; + } + + protected String getVerificationUriParamName() { + return "verification_uri"; + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index c2f483e0e..96ff82de5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -1,10 +1,8 @@ package com.github.scribejava.core.extractors; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.net.URI; -import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; import com.github.scribejava.core.model.OAuthConstants; @@ -15,9 +13,7 @@ /** * JSON (default) implementation of {@link TokenExtractor} for OAuth 2.0 */ -public class OAuth2AccessTokenJsonExtractor implements TokenExtractor { - - protected static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); +public class OAuth2AccessTokenJsonExtractor extends AbstractJsonExtractor implements TokenExtractor { protected OAuth2AccessTokenJsonExtractor() { } @@ -92,16 +88,4 @@ protected OAuth2AccessToken createToken(String accessToken, String tokenType, In String refreshToken, String scope, JsonNode response, String rawResponse) { return new OAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); } - - public static JsonNode extractRequiredParameter(JsonNode errorNode, String parameterName, String rawResponse) - throws OAuthException { - final JsonNode value = errorNode.get(parameterName); - - if (value == null) { - throw new OAuthException("Response body is incorrect. Can't extract a '" + parameterName - + "' from this: '" + rawResponse + "'", null); - } - - return value; - } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceAuthorization.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceAuthorization.java new file mode 100644 index 000000000..dfdc42c36 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceAuthorization.java @@ -0,0 +1,105 @@ +package com.github.scribejava.core.model; + +/** + * Device Authorization Response + * + * @see rfc8628 + */ +public class DeviceAuthorization { + + /** + * device_code + * + * REQUIRED. The device verification code. + */ + private final String deviceCode; + + /** + * user_code + * + * REQUIRED. The end-user verification code. + */ + private final String userCode; + + /** + * verification_uri + * + * REQUIRED. The end-user verification URI on the authorization server. The URI should be short and easy to remember + * as end users will be asked to manually type it into their user agent. + */ + private final String verificationUri; + + /** + * verification_uri_complete + * + * OPTIONAL. A verification URI that includes the "user_code" (or other information with the same function as the + * "user_code"), which is designed for non-textual transmission. + */ + private String verificationUriComplete; + + /** + * expires_in + * + * REQUIRED. The lifetime in seconds of the "device_code" and "user_code". + */ + private final int expiresInSeconds; + + /** + * interval + * + * OPTIONAL. The minimum amount of time in seconds that the client SHOULD wait between polling requests to the token + * endpoint. If no value is provided, clients MUST use 5 as the default. + */ + private int intervalSeconds = 5; + + public DeviceAuthorization(String deviceCode, String userCode, String verificationUri, int expiresInSeconds) { + this.deviceCode = deviceCode; + this.userCode = userCode; + this.verificationUri = verificationUri; + this.expiresInSeconds = expiresInSeconds; + } + + public void setVerificationUriComplete(String verificationUriComplete) { + this.verificationUriComplete = verificationUriComplete; + } + + public void setIntervalSeconds(int intervalSeconds) { + this.intervalSeconds = intervalSeconds; + } + + public String getDeviceCode() { + return deviceCode; + } + + public String getUserCode() { + return userCode; + } + + public String getVerificationUri() { + return verificationUri; + } + + public String getVerificationUriComplete() { + return verificationUriComplete; + } + + public long getExpiresInSeconds() { + return expiresInSeconds; + } + + public int getIntervalSeconds() { + return intervalSeconds; + } + + @Override + public String toString() { + return "DeviceAuthorization{" + + "'deviceCode'='" + deviceCode + + "', 'userCode'='" + userCode + + "', 'verificationUri'='" + verificationUri + + "', 'verificationUriComplete'='" + verificationUriComplete + + "', 'expiresInSeconds'='" + expiresInSeconds + + "', 'intervalSeconds'='" + intervalSeconds + "'}"; + } + +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceCode.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceCode.java deleted file mode 100644 index 8e31fc8aa..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/DeviceCode.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.scribejava.core.model; - -public class DeviceCode { - private String deviceCode; - private String userCode; - private String verificationUri; - private int intervalSeconds; - private long expiresAtMillis; - - public DeviceCode(String deviceCode, String userCode, String verificationUri, - int intervalSeconds, int expiresInSeconds) { - this.deviceCode = deviceCode; - this.userCode = userCode; - this.verificationUri = verificationUri; - this.intervalSeconds = intervalSeconds; - expiresAtMillis = System.currentTimeMillis() + (expiresInSeconds * 1000); - } - - public String getDeviceCode() { - return deviceCode; - } - - public String getUserCode() { - return userCode; - } - - public String getVerificationUri() { - return verificationUri; - } - - public int getIntervalSeconds() { - return intervalSeconds; - } - - public long getExpiresAtMillis() { - return expiresAtMillis; - } -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 75e515f60..9b30fb9b5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -1,12 +1,10 @@ package com.github.scribejava.core.oauth; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; -import com.github.scribejava.core.model.DeviceCode; +import com.github.scribejava.core.model.DeviceAuthorization; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; import com.github.scribejava.core.model.OAuth2Authorization; @@ -26,13 +24,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import static com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor.extractRequiredParameter; -import static com.github.scribejava.core.oauth2.OAuth2Error.AUTHORIZATION_PENDING; -import static com.github.scribejava.core.oauth2.OAuth2Error.SLOW_DOWN; -import static java.lang.Thread.sleep; - public class OAuth20Service extends OAuthService { - protected static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); private static final String VERSION = "2.0"; private final DefaultApi20 api; @@ -57,8 +49,7 @@ protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) try (Response response = execute(request)) { if (isDebug()) { log("response status code: %s", response.getCode()); - final String body = response.getBody(); - log("response body: %s", body); + log("response body: %s", response.getBody()); } return api.getAccessTokenExtractor().extract(response); @@ -83,10 +74,9 @@ public OAuth2AccessToken convert(Response response) throws IOException { log("received response for access token"); if (isDebug()) { log("response status code: %s", response.getCode()); - final String body = response.getBody(); - log("response body: %s", body); + log("response body: %s", response.getBody()); } - final OAuth2AccessToken token = getApi().getAccessTokenExtractor().extract(response); + final OAuth2AccessToken token = api.getAccessTokenExtractor().extract(response); response.close(); return token; } @@ -150,11 +140,7 @@ protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) if (pkceCodeVerifier != null) { request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); } - if (isDebug()) { - log("created access token request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); - } + logRequestWithParams("access token", request); return request; } @@ -168,9 +154,7 @@ public Future refreshAccessTokenAsync(String refreshToken, St public OAuth2AccessToken refreshAccessToken(String refreshToken) throws IOException, InterruptedException, ExecutionException { - final OAuthRequest request = createRefreshTokenRequest(refreshToken, null); - - return sendAccessTokenRequestSync(request); + return refreshAccessToken(refreshToken, (String) null); } public OAuth2AccessToken refreshAccessToken(String refreshToken, String scope) @@ -210,11 +194,9 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken, String sco request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); - if (isDebug()) { - log("created refresh token request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); - } + + logRequestWithParams("refresh token", request); + return request; } @@ -278,11 +260,8 @@ protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, St api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); - if (isDebug()) { - log("created access token password grant request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); - } + logRequestWithParams("access token password grant", request); + return request; } @@ -341,11 +320,8 @@ protected OAuthRequest createAccessTokenClientCredentialsGrantRequest(String sco } request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.CLIENT_CREDENTIALS); - if (isDebug()) { - log("created access token client credentials grant request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); - } + logRequestWithParams("access token client credentials grant", request); + return request; } @@ -416,11 +392,7 @@ protected OAuthRequest createRevokeTokenRequest(String tokenToRevoke, TokenTypeH request.addParameter("token_type_hint", tokenTypeHint.getValue()); } - if (isDebug()) { - log("created revoke token request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); - } + logRequestWithParams("revoke token", request); return request; } @@ -505,82 +477,183 @@ public String getDefaultScope() { return defaultScope; } + protected OAuthRequest createDeviceAuthorizationCodesRequest(String scope) { + final OAuthRequest request = new OAuthRequest(Verb.POST, api.getDeviceAuthorizationEndpoint()); + request.addParameter(OAuthConstants.CLIENT_ID, getApiKey()); + if (scope != null) { + request.addParameter(OAuthConstants.SCOPE, scope); + } else if (defaultScope != null) { + request.addParameter(OAuthConstants.SCOPE, defaultScope); + } + + logRequestWithParams("Device Authorization Codes", request); + + return request; + } + + /** + * Requests a set of verification codes from the authorization server with the default scope + * + * @see RFC 8628 + * + * @return DeviceAuthorization + * @throws InterruptedException InterruptedException + * @throws ExecutionException ExecutionException + * @throws IOException IOException + */ + public DeviceAuthorization getDeviceAuthorizationCodes() + throws InterruptedException, ExecutionException, IOException { + return getDeviceAuthorizationCodes((String) null); + } + /** - * Requests a device code from a server. + * Requests a set of verification codes from the authorization server * - * @see rfc8628 - * @see - * azure v2-oauth2-device-code + * @see RFC 8628 + * + * @param scope scope + * @return DeviceAuthorization + * @throws InterruptedException InterruptedException + * @throws ExecutionException ExecutionException + * @throws IOException IOException */ - public DeviceCode getDeviceCode() throws InterruptedException, ExecutionException, IOException { - final OAuthRequest request = new OAuthRequest(Verb.POST, api.getDeviceAuthorizationUrl()); - request.addBodyParameter(OAuthConstants.CLIENT_ID, getApiKey()); - request.addBodyParameter(OAuthConstants.SCOPE, getDefaultScope()); + public DeviceAuthorization getDeviceAuthorizationCodes(String scope) + throws InterruptedException, ExecutionException, IOException { + final OAuthRequest request = createDeviceAuthorizationCodesRequest(scope); + try (Response response = execute(request)) { - final String body = response.getBody(); - if (response.getCode() == 200) { - final JsonNode n = OBJECT_MAPPER.readTree(body); - return new DeviceCode( - extractRequiredParameter(n, "device_code", body).textValue(), - extractRequiredParameter(n, "user_code", body).textValue(), - extractRequiredParameter(n, "verification_uri", body).textValue(), - n.path("interval").asInt(5), - extractRequiredParameter(n, "expires_in", body).intValue()); - } else { - OAuth2AccessTokenJsonExtractor.instance().generateError(body); - throw new IllegalStateException(); // generateError() always throws an exception + if (isDebug()) { + log("got DeviceAuthorizationCodes response"); + log("response status code: %s", response.getCode()); + log("response body: %s", response.getBody()); } + return api.getDeviceAuthorizationExtractor().extract(response); } } + public Future getDeviceAuthorizationCodes( + OAuthAsyncRequestCallback callback) { + return getDeviceAuthorizationCodes(null, callback); + } + + public Future getDeviceAuthorizationCodes(String scope, + OAuthAsyncRequestCallback callback) { + final OAuthRequest request = createDeviceAuthorizationCodesRequest(scope); + + return execute(request, callback, new OAuthRequest.ResponseConverter() { + @Override + public DeviceAuthorization convert(Response response) throws IOException { + final DeviceAuthorization deviceAuthorization = api.getDeviceAuthorizationExtractor().extract(response); + response.close(); + return deviceAuthorization; + } + }); + } + + public Future getDeviceAuthorizationCodesAsync() { + return getDeviceAuthorizationCodesAsync(null); + } + + public Future getDeviceAuthorizationCodesAsync(String scope) { + return getDeviceAuthorizationCodes(scope, null); + } + + protected OAuthRequest createAccessTokenDeviceAuthorizationGrantRequest(DeviceAuthorization deviceAuthorization) { + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); + request.addParameter(OAuthConstants.GRANT_TYPE, "urn:ietf:params:oauth:grant-type:device_code"); + request.addParameter("device_code", deviceAuthorization.getDeviceCode()); + api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); + return request; + } + /** * Attempts to get a token from a server. - * Function {@link #pollDeviceAccessToken(DeviceCode)} is usually used instead of this. * + * Function {@link #pollAccessTokenDeviceAuthorizationGrant(com.github.scribejava.core.model.DeviceAuthorization)} + * is usually used instead of this. + * + * @param deviceAuthorization deviceAuthorization * @return token - * @throws OAuth2AccessTokenErrorResponse - * If {@link OAuth2AccessTokenErrorResponse#getError()} is - * {@link OAuth2Error#AUTHORIZATION_PENDING} or {@link OAuth2Error#SLOW_DOWN}, - * another attempt should be made after a while. * - * @see #getDeviceCode() + * @throws java.lang.InterruptedException InterruptedException + * @throws java.util.concurrent.ExecutionException ExecutionException + * @throws java.io.IOException IOException + * @throws OAuth2AccessTokenErrorResponse If {@link OAuth2AccessTokenErrorResponse#getError()} is + * {@link com.github.scribejava.core.oauth2.OAuth2Error#AUTHORIZATION_PENDING} or + * {@link com.github.scribejava.core.oauth2.OAuth2Error#SLOW_DOWN}, another attempt should be made after a while. + * + * @see #getDeviceAuthorizationCodes() */ - public OAuth2AccessToken getAccessTokenDeviceCodeGrant(DeviceCode deviceCode) - throws IOException, InterruptedException, ExecutionException { - final OAuthRequest request = new OAuthRequest(Verb.POST, api.getAccessTokenEndpoint()); - request.addParameter(OAuthConstants.GRANT_TYPE, "urn:ietf:params:oauth:grant-type:device_code"); - request.addBodyParameter(OAuthConstants.CLIENT_ID, getApiKey()); - request.addParameter("device_code", deviceCode.getDeviceCode()); + public OAuth2AccessToken getAccessTokenDeviceAuthorizationGrant(DeviceAuthorization deviceAuthorization) + throws InterruptedException, ExecutionException, IOException { + final OAuthRequest request = createAccessTokenDeviceAuthorizationGrantRequest(deviceAuthorization); + try (Response response = execute(request)) { + if (isDebug()) { + log("got AccessTokenDeviceAuthorizationGrant response"); + log("response status code: %s", response.getCode()); + log("response body: %s", response.getBody()); + } return api.getAccessTokenExtractor().extract(response); } } + public Future getAccessTokenDeviceAuthorizationGrant(DeviceAuthorization deviceAuthorization, + OAuthAsyncRequestCallback callback) { + final OAuthRequest request = createAccessTokenDeviceAuthorizationGrantRequest(deviceAuthorization); + + return execute(request, callback, new OAuthRequest.ResponseConverter() { + @Override + public OAuth2AccessToken convert(Response response) throws IOException { + final OAuth2AccessToken accessToken = api.getAccessTokenExtractor().extract(response); + response.close(); + return accessToken; + } + }); + } + + public Future getAccessTokenDeviceAuthorizationGrantAsync( + DeviceAuthorization deviceAuthorization) { + return getAccessTokenDeviceAuthorizationGrant(deviceAuthorization, null); + } + /** - * Periodically tries to get a token from a server (waiting for the user to give consent). + * Periodically tries to get a token from a server (waiting for the user to give consent). Sync only version. No + * Async variants yet, one should implement async scenarios themselves. * + * @param deviceAuthorization deviceAuthorization * @return token - * @throws OAuth2AccessTokenErrorResponse - * Indicates OAuth error. + * @throws java.lang.InterruptedException InterruptedException + * @throws java.util.concurrent.ExecutionException ExecutionException + * @throws java.io.IOException IOException + * @throws OAuth2AccessTokenErrorResponse Indicates OAuth error. * - * @see #getDeviceCode() + * @see #getDeviceAuthorizationCodes() */ - public OAuth2AccessToken pollDeviceAccessToken(DeviceCode deviceCode) + public OAuth2AccessToken pollAccessTokenDeviceAuthorizationGrant(DeviceAuthorization deviceAuthorization) throws InterruptedException, ExecutionException, IOException { - long intervalMillis = deviceCode.getIntervalSeconds() * 1000; + long intervalMillis = deviceAuthorization.getIntervalSeconds() * 1000; while (true) { try { - return getAccessTokenDeviceCodeGrant(deviceCode); + return getAccessTokenDeviceAuthorizationGrant(deviceAuthorization); } catch (OAuth2AccessTokenErrorResponse e) { - if (e.getError() != AUTHORIZATION_PENDING) { - if (e.getError() == SLOW_DOWN) { + if (e.getError() != OAuth2Error.AUTHORIZATION_PENDING) { + if (e.getError() == OAuth2Error.SLOW_DOWN) { intervalMillis += 5000; } else { throw e; } } } - sleep(intervalMillis); + Thread.sleep(intervalMillis); + } + } + + private void logRequestWithParams(String requestDescription, OAuthRequest request) { + if (isDebug()) { + log("created " + requestDescription + " request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); } } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java index af8f540f8..b1422bcae 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/OAuth2Error.java @@ -3,8 +3,6 @@ import java.util.EnumSet; import java.util.Set; -import static java.util.Collections.unmodifiableSet; - public enum OAuth2Error { /** * @see RFC 6749, 4.1.2.1 Error Response @@ -23,6 +21,7 @@ public enum OAuth2Error { /** * @see RFC 6749, 4.1.2.1 Error Response * @see RFC 6749, 4.2.2.1 Error Response + * @see RFC 8628, 3.5. Device Access Token Response */ ACCESS_DENIED("access_denied"), /** @@ -73,28 +72,20 @@ public enum OAuth2Error { * Registration */ UNSUPPORTED_TOKEN_TYPE("unsupported_token_type"), - /** - * @see rfc8628#section-3.5 + * @see RFC 8628, 3.5. Device Access Token Response */ AUTHORIZATION_PENDING("authorization_pending"), - /** - * @see rfc8628#section-3.5 + * @see RFC 8628, 3.5. Device Access Token Response */ SLOW_DOWN("slow_down"), - /** - * @see rfc8628#section-3.5 + * @see RFC 8628, 3.5. Device Access Token Response */ - EXPIRED_TOKEN("expired_token"), - ; + EXPIRED_TOKEN("expired_token"); - /** - * Unlike {@link #values()} which creates a new array every time, this always - * returns the same immutable object. - */ - public static final Set VALUES = unmodifiableSet(EnumSet.allOf(OAuth2Error.class)); + private static final Set VALUES = EnumSet.allOf(OAuth2Error.class); private final String errorString; From 0d4d766a33bf0426cb8f7245684d6afbd94c2755 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Mon, 9 Nov 2020 12:19:26 +0300 Subject: [PATCH 411/481] update deps --- pom.xml | 10 +++++----- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 69c7cb46d..546dc3989 100644 --- a/pom.xml +++ b/pom.xml @@ -54,18 +54,18 @@ com.fasterxml.jackson.core jackson-databind - 2.11.2 + 2.11.3 junit junit - 4.13 + 4.13.1 test com.squareup.okhttp3 mockwebserver - 4.8.1 + 4.9.0 test @@ -104,7 +104,7 @@ com.puppycrawl.tools checkstyle - 8.36 + 8.37 @@ -269,7 +269,7 @@ 7 - 6.27.0 + 6.29.0 diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 393c4fc83..347d90675 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -23,7 +23,7 @@ org.apache.httpcomponents httpclient - 4.5.12 + 4.5.13 org.apache.httpcomponents diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 9c7325e58..89961e482 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -23,7 +23,7 @@ com.linecorp.armeria armeria - 1.0.0 + 1.2.0 com.github.scribejava diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 0ad7a7540..2c113d597 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 4.8.1 + 4.9.0 com.github.scribejava From 22b0ce7caef5663732e15d13fda5052f6e6a774c Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Mon, 9 Nov 2020 12:28:03 +0300 Subject: [PATCH 412/481] add Ian Strachan donation --- donate.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/donate.md b/donate.md index 50f782838..ee6a1a6e7 100644 --- a/donate.md +++ b/donate.md @@ -10,4 +10,5 @@ ps.If you can't for any reason use above methods, let me know, we will find the Hall of fame "Donors" (in alphabetical order, if you don't want to be here, just put a note along with the donation):
    1.Douglas Ross from USA
    -2.Your name can be here. +2.Ian Strachan
    +3.Your name can be here. From d3c3da84eec775b01acf6a5d94658ca6ec31dca3 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 10 Nov 2020 11:51:00 +0300 Subject: [PATCH 413/481] update changelog, add "update Google API URLs" entry --- changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog b/changelog index c029807e2..1b590452c 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ * add Kakao API (https://kakao.com/) (thanks to https://github.com/v0o0v) * support chunks in JDKHttpClient's Multipart (thanks to https://github.com/eos1d3) * add support for OAuth 2.0 Device Authorization Grant (RFC 8628) (thanks to https://github.com/rebarbora-mckvak) + * update Google API URLs [7.1.1] * add Proxy support (via config's option) to internal JDKHttpClient (thanks to https://github.com/bjournaud) From 7a35ddc1dea4df338857b02fc3f8fbff755e4c30 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 10 Nov 2020 12:12:05 +0300 Subject: [PATCH 414/481] prepare v8.0.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8c7f3a07a..02384b033 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 7.1.1 + 8.0.0 ``` @@ -144,7 +144,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 7.1.1 + 8.0.0 ``` diff --git a/changelog b/changelog index 1b590452c..f46c83239 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[8.0.0] * add Kakao API (https://kakao.com/) (thanks to https://github.com/v0o0v) * support chunks in JDKHttpClient's Multipart (thanks to https://github.com/eos1d3) * add support for OAuth 2.0 Device Authorization Grant (RFC 8628) (thanks to https://github.com/rebarbora-mckvak) From 4e76471398cf47143b56a6ba762363d5bb9a210c Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 10 Nov 2020 12:13:28 +0300 Subject: [PATCH 415/481] [maven-release-plugin] prepare release scribejava-8.0.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 546dc3989..a695b50c0 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 7.1.2-SNAPSHOT + 8.0.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -35,7 +35,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-8.0.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 24dbcaa1e..2acf02fb0 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.2-SNAPSHOT + 8.0.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 79a016cf2..f3c027aaa 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.2-SNAPSHOT + 8.0.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 6b6d8578b..358e8e73f 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.2-SNAPSHOT + 8.0.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 347d90675..fa367ff4a 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.2-SNAPSHOT + 8.0.0 ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 89961e482..074345d6a 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.2-SNAPSHOT + 8.0.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index cf992b25a..08971a209 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.2-SNAPSHOT + 8.0.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 2c113d597..6d038e039 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 7.1.2-SNAPSHOT + 8.0.0 ../pom.xml From 788389b8cb9addfce956f051f9f6d645cc03d329 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 10 Nov 2020 12:13:36 +0300 Subject: [PATCH 416/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index a695b50c0..cc22f550e 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 8.0.0 + 8.0.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -35,7 +35,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-8.0.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 2acf02fb0..272fa9d1f 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.0.0 + 8.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index f3c027aaa..7b0c9dcfb 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.0.0 + 8.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 358e8e73f..bb4c9c981 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.0.0 + 8.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index fa367ff4a..38ee0e614 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.0.0 + 8.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 074345d6a..a60f50a23 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.0.0 + 8.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 08971a209..1258d7563 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.0.0 + 8.0.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 6d038e039..580fea220 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.0.0 + 8.0.1-SNAPSHOT ../pom.xml From 1dbeabbaf2d7dc39114166e9eea510de4f694128 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Thu, 12 Nov 2020 11:08:58 +0300 Subject: [PATCH 417/481] cleanup deprecates methods --- .../multipart/MultipartPayload.java | 101 ------- .../scribejava/core/model/OAuthRequest.java | 254 ------------------ 2 files changed, 355 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java index 6f7a5b093..9d60e0caa 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/multipart/MultipartPayload.java @@ -72,75 +72,6 @@ private static String parseOrGenerateBoundary(Map headers) { return parsedBoundary == null ? MultipartUtils.generateDefaultBoundary() : parsedBoundary; } - /** - * - * @param fileContent fileContent - * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void addFileBodyPart(byte[] fileContent) { - addBodyPart(new FileByteArrayBodyPartPayload(fileContent)); - } - - /** - * - * @param fileContent fileContent - * @param name name - * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void addFileBodyPart(byte[] fileContent, String name) { - addBodyPart(new FileByteArrayBodyPartPayload(fileContent, name)); - } - - /** - * - * @param fileContent fileContent - * @param name name - * @param filename filename - * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void addFileBodyPart(byte[] fileContent, String name, String filename) { - addBodyPart(new FileByteArrayBodyPartPayload(fileContent, name, filename)); - } - - /** - * - * @param contentType contentType - * @param fileContent fileContent - * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void addFileBodyPart(String contentType, byte[] fileContent) { - addBodyPart(new FileByteArrayBodyPartPayload(contentType, fileContent)); - } - - /** - * - * @param contentType contentType - * @param fileContent fileContent - * @param name name - * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void addFileBodyPart(String contentType, byte[] fileContent, String name) { - addBodyPart(new FileByteArrayBodyPartPayload(contentType, fileContent, name)); - } - - /** - * - * @param contentType contentType - * @param fileContent fileContent - * @param name name - * @param filename filename - * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void addFileBodyPart(String contentType, byte[] fileContent, String name, String filename) { - addBodyPart(new FileByteArrayBodyPartPayload(contentType, fileContent, name, filename)); - } - public void addBodyPart(BodyPartPayload bodyPartPayload) { bodyParts.add(bodyPartPayload); } @@ -153,38 +84,6 @@ public void addBodyPart(MultipartPayload multipartPayload) { bodyParts.add(multipartPayload); } - /** - * - * @param bodyPartPayload bodyPartPayload - * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void addBodyPart(byte[] bodyPartPayload) { - addBodyPart(new ByteArrayBodyPartPayload(bodyPartPayload)); - } - - /** - * - * @param bodyPartPayload bodyPartPayload - * @param contentType contentType - * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void addBodyPart(byte[] bodyPartPayload, String contentType) { - addBodyPart(new ByteArrayBodyPartPayload(bodyPartPayload, contentType)); - } - - /** - * - * @param bodyPartPayload bodyPartPayload - * @param headers headers - * @deprecated use {@link #addBodyPart(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void addBodyPart(byte[] bodyPartPayload, Map headers) { - addBodyPart(new ByteArrayBodyPartPayload(bodyPartPayload, headers)); - } - public List getBodyParts() { return bodyParts; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java index 2194545fa..ccf26157c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java @@ -2,7 +2,6 @@ import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.httpclient.multipart.BodyPartPayload; -import com.github.scribejava.core.httpclient.multipart.FileByteArrayBodyPartPayload; import com.github.scribejava.core.httpclient.multipart.MultipartPayload; import java.io.File; import java.io.IOException; @@ -161,264 +160,11 @@ public void initMultipartPayload(String subtype, String boundary, Map headers) { - initMultipartPayload(); - addByteArrayBodyPartPayloadInMultipartPayload(bodyPartPayload, headers); - } - - /** - * - * @param bodyPartPayload bodyPartPayload - * @deprecated use - * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void addByteArrayBodyPartPayloadInMultipartPayload(byte[] bodyPartPayload) { - multipartPayload.addBodyPart(bodyPartPayload); - } - - /** - * - * @param bodyPartPayload bodyPartPayload - * @param contentType contentType - * @deprecated use - * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void addByteArrayBodyPartPayloadInMultipartPayload(byte[] bodyPartPayload, String contentType) { - multipartPayload.addBodyPart(bodyPartPayload, contentType); - } - - /** - * - * @param bodyPartPayload bodyPartPayload - * @param headers headers - * @deprecated use - * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void addByteArrayBodyPartPayloadInMultipartPayload(byte[] bodyPartPayload, Map headers) { - multipartPayload.addBodyPart(bodyPartPayload, headers); - } - - /** - * - * @param fileContent fileContent - * @deprecated use - * {@link #setBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void setFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent) { - initMultipartPayload(); - addFileByteArrayBodyPartPayloadInMultipartPayload(fileContent); - } - - /** - * - * @param contentType contentType - * @param fileContent fileContent - * @deprecated use - * {@link #setBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void setFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent) { - initMultipartPayload(); - addFileByteArrayBodyPartPayloadInMultipartPayload(contentType, fileContent); - } - - /** - * - * @param fileContent fileContent - * @param name name - * @deprecated use - * {@link #setBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void setFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent, String name) { - initMultipartPayload(); - addFileByteArrayBodyPartPayloadInMultipartPayload(fileContent, name); - } - - /** - * - * @param contentType contentType - * @param fileContent fileContent - * @param name name - * @deprecated use - * {@link #setBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void setFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent, String name) { - initMultipartPayload(); - addFileByteArrayBodyPartPayloadInMultipartPayload(contentType, fileContent, name); - } - - /** - * - * @param fileContent fileContent - * @param name name - * @param filename filename - * @deprecated use - * {@link #setBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void setFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent, String name, String filename) { - initMultipartPayload(); - addFileByteArrayBodyPartPayloadInMultipartPayload(fileContent, name, filename); - } - - /** - * - * @param contentType contentType - * @param fileContent fileContent - * @param name name - * @param filename filename - * @deprecated use - * {@link #setBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void setFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent, String name, - String filename) { - initMultipartPayload(); - addFileByteArrayBodyPartPayloadInMultipartPayload(contentType, fileContent, name, filename); - } - - /** - * - * @param fileByteArrayBodyPartPayload fileByteArrayBodyPartPayload - * @deprecated use - * {@link #setBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void setFileByteArrayBodyPartPayloadInMultipartPayload( - FileByteArrayBodyPartPayload fileByteArrayBodyPartPayload) { - setBodyPartPayloadInMultipartPayload(fileByteArrayBodyPartPayload); - } - public void setBodyPartPayloadInMultipartPayload(BodyPartPayload bodyPartPayload) { initMultipartPayload(); addBodyPartPayloadInMultipartPayload(bodyPartPayload); } - /** - * - * @param fileContent fileContent - * @deprecated use - * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void addFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent) { - multipartPayload.addFileBodyPart(fileContent); - } - - /** - * - * @param contentType contentType - * @param fileContent fileContent - * @deprecated use - * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void addFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent) { - multipartPayload.addFileBodyPart(contentType, fileContent); - } - - /** - * - * @param fileContent fileContent - * @param name name - * @deprecated use - * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void addFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent, String name) { - multipartPayload.addFileBodyPart(fileContent, name); - } - - /** - * @param contentType contentType - * @param fileContent fileContent - * @param name name - * @deprecated use - * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void addFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent, String name) { - multipartPayload.addFileBodyPart(contentType, fileContent, name); - } - - /** - * - * @param fileContent fileContent - * @param name name - * @param filename filename - * @deprecated use - * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void addFileByteArrayBodyPartPayloadInMultipartPayload(byte[] fileContent, String name, String filename) { - multipartPayload.addFileBodyPart(fileContent, name, filename); - } - - /** - * @param contentType contentType - * @param fileContent fileContent - * @param name name - * @param filename filename - * @deprecated use - * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void addFileByteArrayBodyPartPayloadInMultipartPayload(String contentType, byte[] fileContent, String name, - String filename) { - multipartPayload.addFileBodyPart(contentType, fileContent, name, filename); - } - - /** - * - * @param fileByteArrayBodyPartPayload fileByteArrayBodyPartPayload - * @deprecated use - * {@link #addBodyPartPayloadInMultipartPayload(com.github.scribejava.core.httpclient.multipart.BodyPartPayload)} - */ - @Deprecated - public void addFileByteArrayBodyPartPayloadInMultipartPayload( - FileByteArrayBodyPartPayload fileByteArrayBodyPartPayload) { - multipartPayload.addBodyPart(fileByteArrayBodyPartPayload); - } - public void addBodyPartPayloadInMultipartPayload(BodyPartPayload bodyPartPayload) { multipartPayload.addBodyPart(bodyPartPayload); } From fb240086b4a6c9560c9f30d61633c771b0cd3ed7 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Thu, 12 Nov 2020 15:07:34 +0300 Subject: [PATCH 418/481] add raw Response (with HTTP repsponse code and body) as member to the OAuth2AccessTokenErrorResponse --- changelog | 3 ++ .../FacebookAccessTokenErrorResponse.java | 46 +++++++++++++++---- .../FacebookAccessTokenJsonExtractor.java | 11 +++-- .../apis/fitbit/FitBitJsonTokenExtractor.java | 17 +++++-- .../apis/polar/PolarJsonTokenExtractor.java | 18 +++++--- .../FacebookAccessTokenJsonExtractorTest.java | 2 +- .../fitbit/FitBitJsonTokenExtractorTest.java | 3 +- .../DeviceAuthorizationJsonExtractor.java | 20 +++++--- .../OAuth2AccessTokenJsonExtractor.java | 38 +++++++++++---- .../model/OAuth2AccessTokenErrorResponse.java | 42 ++++++++++++++--- .../scribejava/core/oauth/OAuth20Service.java | 2 +- .../OAuth2RevokeTokenResponseConverter.java | 2 +- 12 files changed, 157 insertions(+), 47 deletions(-) diff --git a/changelog b/changelog index f46c83239..17187ad2f 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * add raw Response (with HTTP repsponse code and body) as member to the OAuth2AccessTokenErrorResponse + [8.0.0] * add Kakao API (https://kakao.com/) (thanks to https://github.com/v0o0v) * support chunks in JDKHttpClient's Multipart (thanks to https://github.com/eos1d3) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java index b792ad636..36cc4a504 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java @@ -1,6 +1,8 @@ package com.github.scribejava.apis.facebook; import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.model.Response; +import java.io.IOException; import java.util.Objects; /** @@ -21,15 +23,32 @@ public class FacebookAccessTokenErrorResponse extends OAuthException { private final String type; private final int codeInt; private final String fbtraceId; - private final String rawResponse; + private final Response response; public FacebookAccessTokenErrorResponse(String message, String type, int code, String fbtraceId, - String rawResponse) { + Response response) { super(message); this.type = type; this.codeInt = code; this.fbtraceId = fbtraceId; - this.rawResponse = rawResponse; + this.response = response; + } + + /** + * + * @param message message + * @param type type + * @param code code + * @param fbtraceId fbtraceId + * @param rawResponse rawResponse + * @deprecated use {@link #FacebookAccessTokenErrorResponse(java.lang.String, java.lang.String, + * int, java.lang.String, com.github.scribejava.core.model.Response) + * } + */ + @Deprecated + public FacebookAccessTokenErrorResponse(String message, String type, int code, String fbtraceId, + String rawResponse) { + this(message, type, code, fbtraceId, new Response(-1, null, null, rawResponse)); } public String getType() { @@ -44,14 +63,25 @@ public String getFbtraceId() { return fbtraceId; } - public String getRawResponse() { - return rawResponse; + /** + * + * @return body of response + * @throws IOException IOException + * @deprecated use {@link #getResponse()} and then {@link Response#getBody()} + */ + @Deprecated + public String getRawResponse() throws IOException { + return response.getBody(); + } + + public Response getResponse() { + return response; } @Override public int hashCode() { int hash = 5; - hash = 83 * hash + Objects.hashCode(rawResponse); + hash = 83 * hash + Objects.hashCode(response); hash = 83 * hash + Objects.hashCode(getMessage()); hash = 83 * hash + Objects.hashCode(type); hash = 83 * hash + Objects.hashCode(codeInt); @@ -71,7 +101,7 @@ public boolean equals(Object obj) { return false; } final FacebookAccessTokenErrorResponse other = (FacebookAccessTokenErrorResponse) obj; - if (!Objects.equals(rawResponse, other.getRawResponse())) { + if (!Objects.equals(response, other.getResponse())) { return false; } if (!Objects.equals(getMessage(), other.getMessage())) { @@ -89,7 +119,7 @@ public boolean equals(Object obj) { @Override public String toString() { return "FacebookAccessTokenErrorResponse{'type'='" + type + "', 'codeInt'='" + codeInt - + "', 'fbtraceId'='" + fbtraceId + "', 'rawResponse'='" + rawResponse + + "', 'fbtraceId'='" + fbtraceId + "', 'response'='" + response + "', 'message'='" + getMessage() + "'}"; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java index 7171c9fbd..f51935436 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractor.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.model.Response; import java.io.IOException; /** @@ -29,13 +30,17 @@ public static FacebookAccessTokenJsonExtractor instance() { * * '{"error":{"message":"Error validating application. Invalid application * ID.","type":"OAuthException","code":101,"fbtrace_id":"CvDR+X4WWIx"}}' + * + * @param response response */ @Override - public void generateError(String rawResponse) throws IOException { - final JsonNode errorNode = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER.readTree(rawResponse).get("error"); + public void generateError(Response response) throws IOException { + final JsonNode errorNode = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER + .readTree(response.getBody()) + .get("error"); throw new FacebookAccessTokenErrorResponse(errorNode.get("message").asText(), errorNode.get("type").asText(), - errorNode.get("code").asInt(), errorNode.get("fbtrace_id").asText(), rawResponse); + errorNode.get("code").asInt(), errorNode.get("fbtrace_id").asText(), response); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java index 3ec56f5be..24ed6025a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractor.java @@ -1,8 +1,10 @@ package com.github.scribejava.apis.fitbit; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; +import com.github.scribejava.core.model.Response; import com.github.scribejava.core.oauth2.OAuth2Error; import java.io.IOException; @@ -31,18 +33,23 @@ protected FitBitOAuth2AccessToken createToken(String accessToken, String tokenTy * Related documentation: https://dev.fitbit.com/build/reference/web-api/oauth2/ */ @Override - public void generateError(String rawResponse) throws IOException { - final JsonNode errorNode = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER.readTree(rawResponse) - .get("errors").get(0); + public void generateError(Response response) throws IOException { + final JsonNode errorNode; + try { + errorNode = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER.readTree(response.getBody()).get("errors").get(0); + } catch (JsonProcessingException ex) { + throw new OAuth2AccessTokenErrorResponse(null, null, null, response); + } OAuth2Error errorCode; try { - errorCode = OAuth2Error.parseFrom(extractRequiredParameter(errorNode, "errorType", rawResponse).asText()); + errorCode = OAuth2Error + .parseFrom(extractRequiredParameter(errorNode, "errorType", response.getBody()).asText()); } catch (IllegalArgumentException iaE) { //non oauth standard error code errorCode = null; } - throw new OAuth2AccessTokenErrorResponse(errorCode, errorNode.get("message").asText(), null, rawResponse); + throw new OAuth2AccessTokenErrorResponse(errorCode, errorNode.get("message").asText(), null, response); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java index efca61631..1258dfe59 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarJsonTokenExtractor.java @@ -1,10 +1,11 @@ package com.github.scribejava.apis.polar; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; +import com.github.scribejava.core.model.Response; import com.github.scribejava.core.oauth2.OAuth2Error; - import java.io.IOException; /** @@ -32,18 +33,23 @@ protected PolarOAuth2AccessToken createToken(String accessToken, String tokenTyp } @Override - public void generateError(String rawResponse) throws IOException { - final JsonNode errorNode = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER.readTree(rawResponse) - .get("errors").get(0); + public void generateError(Response response) throws IOException { + final JsonNode errorNode; + try { + errorNode = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER.readTree(response.getBody()).get("errors").get(0); + } catch (JsonProcessingException ex) { + throw new OAuth2AccessTokenErrorResponse(null, null, null, response); + } OAuth2Error errorCode; try { - errorCode = OAuth2Error.parseFrom(extractRequiredParameter(errorNode, "errorType", rawResponse).asText()); + errorCode = OAuth2Error + .parseFrom(extractRequiredParameter(errorNode, "errorType", response.getBody()).asText()); } catch (IllegalArgumentException iaE) { //non oauth standard error code errorCode = null; } - throw new OAuth2AccessTokenErrorResponse(errorCode, errorNode.get("message").asText(), null, rawResponse); + throw new OAuth2AccessTokenErrorResponse(errorCode, errorNode.get("message").asText(), null, response); } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java index cb9620e68..f62401bf6 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java @@ -26,7 +26,7 @@ public void shouldThrowExceptionIfResponseIsError() throws IOException { assertEquals("OAuthException", fateR.getType()); assertEquals(100, fateR.getCodeInt()); assertEquals("DtxvtGRaxbB", fateR.getFbtraceId()); - assertEquals(body, fateR.getRawResponse()); + assertEquals(body, fateR.getResponse().getBody()); } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java index 396377294..836a0d6ba 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/fitbit/FitBitJsonTokenExtractorTest.java @@ -1,6 +1,7 @@ package com.github.scribejava.apis.fitbit; import com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse; +import com.github.scribejava.core.model.Response; import com.github.scribejava.core.oauth2.OAuth2Error; import java.io.IOException; @@ -28,7 +29,7 @@ public void testErrorExtraction() throws IOException { new ThrowingRunnable() { @Override public void run() throws Throwable { - extractor.generateError(ERROR_JSON); + extractor.generateError(new Response(403, null, null, ERROR_JSON)); } }); assertSame(OAuth2Error.INVALID_GRANT, thrown.getError()); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/DeviceAuthorizationJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/DeviceAuthorizationJsonExtractor.java index 14e09f28d..0dc0ce931 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/DeviceAuthorizationJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/DeviceAuthorizationJsonExtractor.java @@ -22,17 +22,25 @@ public static DeviceAuthorizationJsonExtractor instance() { } public DeviceAuthorization extract(Response response) throws IOException { - - final String body = response.getBody(); - if (response.getCode() != 200) { - generateError(body); + generateError(response); } - return createDeviceAuthorization(body); + return createDeviceAuthorization(response.getBody()); } + /** + * + * @param rawResponse rawResponse + * @throws java.io.IOException IOException + * @deprecated use {@link #generateError(com.github.scribejava.core.model.Response) } + */ + @Deprecated public void generateError(String rawResponse) throws IOException { - OAuth2AccessTokenJsonExtractor.instance().generateError(rawResponse); + generateError(new Response(-1, null, null, rawResponse)); + } + + public void generateError(Response response) throws IOException { + OAuth2AccessTokenJsonExtractor.instance().generateError(response); } private DeviceAuthorization createDeviceAuthorization(String rawResponse) throws IOException { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index 96ff82de5..982c7e499 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.extractors; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import java.io.IOException; import java.net.URI; @@ -33,21 +34,39 @@ public OAuth2AccessToken extract(Response response) throws IOException { Preconditions.checkEmptyString(body, "Response body is incorrect. Can't extract a token from an empty string"); if (response.getCode() != 200) { - generateError(body); + generateError(response); } return createToken(body); } /** - * Related documentation: https://tools.ietf.org/html/rfc6749#section-5.2 * - * @param rawResponse response - * @throws IOException IOException + * @param rawResponse rawResponse + * @throws java.io.IOException IOException + * @deprecated use {@link #generateError(com.github.scribejava.core.model.Response) } */ + @Deprecated public void generateError(String rawResponse) throws IOException { - final JsonNode response = OBJECT_MAPPER.readTree(rawResponse); + generateError(new Response(-1, null, null, rawResponse)); + } + + /** + * Related documentation: https://tools.ietf.org/html/rfc6749#section-5.2 + * + * @param response response + * @throws java.io.IOException IOException + * + */ + public void generateError(Response response) throws IOException { + final String responseBody = response.getBody(); + final JsonNode responseBodyJson; + try { + responseBodyJson = OBJECT_MAPPER.readTree(responseBody); + } catch (JsonProcessingException ex) { + throw new OAuth2AccessTokenErrorResponse(null, null, null, response); + } - final JsonNode errorUriInString = response.get("error_uri"); + final JsonNode errorUriInString = responseBodyJson.get("error_uri"); URI errorUri; try { errorUri = errorUriInString == null ? null : URI.create(errorUriInString.asText()); @@ -57,16 +76,17 @@ public void generateError(String rawResponse) throws IOException { OAuth2Error errorCode; try { - errorCode = OAuth2Error.parseFrom(extractRequiredParameter(response, "error", rawResponse).asText()); + errorCode = OAuth2Error + .parseFrom(extractRequiredParameter(responseBodyJson, "error", responseBody).asText()); } catch (IllegalArgumentException iaE) { //non oauth standard error code errorCode = null; } - final JsonNode errorDescription = response.get("error_description"); + final JsonNode errorDescription = responseBodyJson.get("error_description"); throw new OAuth2AccessTokenErrorResponse(errorCode, errorDescription == null ? null : errorDescription.asText(), - errorUri, rawResponse); + errorUri, response); } private OAuth2AccessToken createToken(String rawResponse) throws IOException { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java index f36572e0a..c64a3d005 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java @@ -2,6 +2,7 @@ import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.oauth2.OAuth2Error; +import java.io.IOException; import java.net.URI; @@ -15,15 +16,32 @@ public class OAuth2AccessTokenErrorResponse extends OAuthException { private final OAuth2Error error; private final String errorDescription; private final URI errorUri; - private final String rawResponse; + private final Response response; public OAuth2AccessTokenErrorResponse(OAuth2Error error, String errorDescription, URI errorUri, - String rawResponse) { - super(rawResponse); + Response rawResponse) throws IOException { + super(rawResponse.getBody()); this.error = error; this.errorDescription = errorDescription; this.errorUri = errorUri; - this.rawResponse = rawResponse; + this.response = rawResponse; + } + + /** + * + * @param error error + * @param errorDescription errorDescription + * @param errorUri errorUri + * @param rawResponse rawResponse + * @throws java.io.IOException IOException + * @deprecated use {@link #OAuth2AccessTokenErrorResponse(com.github.scribejava.core.oauth2.OAuth2Error, + * java.lang.String, java.net.URI, com.github.scribejava.core.model.Response) + * } + */ + @Deprecated + public OAuth2AccessTokenErrorResponse(OAuth2Error error, String errorDescription, URI errorUri, + String rawResponse) throws IOException { + this(error, errorDescription, errorUri, new Response(-1, null, null, rawResponse)); } public OAuth2Error getError() { @@ -38,7 +56,19 @@ public URI getErrorUri() { return errorUri; } - public String getRawResponse() { - return rawResponse; + /** + * + * @return body of response + * @throws IOException IOException + * @deprecated use {@link #getResponse()} and then {@link Response#getBody()} + */ + @Deprecated + public String getRawResponse() throws IOException { + return response.getBody(); } + + public Response getResponse() { + return response; + } + } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 9b30fb9b5..0e028fb3c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -438,7 +438,7 @@ public Void convert(Response response) throws IOException { private void checkForErrorRevokeToken(Response response) throws IOException { if (response.getCode() != 200) { - OAuth2AccessTokenJsonExtractor.instance().generateError(response.getBody()); + OAuth2AccessTokenJsonExtractor.instance().generateError(response); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/revoke/OAuth2RevokeTokenResponseConverter.java b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/OAuth2RevokeTokenResponseConverter.java index b287d7868..dc595a410 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/revoke/OAuth2RevokeTokenResponseConverter.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/revoke/OAuth2RevokeTokenResponseConverter.java @@ -8,7 +8,7 @@ public class OAuth2RevokeTokenResponseConverter { public Void convert(Response response) throws IOException { if (response.getCode() != 200) { - OAuth2AccessTokenJsonExtractor.instance().generateError(response.getBody()); + OAuth2AccessTokenJsonExtractor.instance().generateError(response); } return null; } From 8bae0a458dc3b6f70ef8dc251df8927903d0682a Mon Sep 17 00:00:00 2001 From: Stas Gromov Date: Sat, 21 Nov 2020 23:00:36 +0300 Subject: [PATCH 419/481] Update README.md add "## Paid consulting" paragraph --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 02384b033..a5de23588 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,10 @@ First of all, Pull Requests are welcome, the second option is [donations](https: When you will send the pull request. That's the way for a majority of changes here. Or you can ask someone to make the paid job for you. -In some cases, when I'm interested in changes (technicaly or financialey), I can implement the request myself. +In some cases, when I'm interested in changes (technically or financially), I can implement the request myself. + +## Paid consulting +If you or your business depends on the Scribejava and you need any specific improvement or new feature not currently implemented in the Scribejava, consider contacting me about a paid job. ## Getting started in less than 2 minutes From 8f4891554e5edd4a52d019126d852bda503f0af9 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Thu, 3 Dec 2020 12:19:44 +0300 Subject: [PATCH 420/481] add possibility to set "" (empty string) as apiSecret --- changelog | 1 + .../github/scribejava/core/builder/ServiceBuilder.java | 6 ++++++ .../scribejava/core/builder/ServiceBuilderCommon.java | 10 ++++++++++ .../core/builder/ServiceBuilderOAuth10a.java | 3 +++ .../scribejava/core/builder/ServiceBuilderOAuth20.java | 3 +++ .../core/services/HMACSha1SignatureService.java | 7 +++---- .../core/services/PlaintextSignatureService.java | 2 +- .../core/services/HMACSha1SignatureServiceTest.java | 3 +-- 8 files changed, 28 insertions(+), 7 deletions(-) diff --git a/changelog b/changelog index 17187ad2f..0fbd04741 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,6 @@ [SNAPSHOT] * add raw Response (with HTTP repsponse code and body) as member to the OAuth2AccessTokenErrorResponse + * add possibility to set "" (empty string) as apiSecret [8.0.0] * add Kakao API (https://kakao.com/) (thanks to https://github.com/v0o0v) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index c35e0429d..eb568e930 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -51,6 +51,12 @@ public ServiceBuilder apiSecret(String apiSecret) { return this; } + @Override + public ServiceBuilder apiSecretIsEmptyStringUnsafe() { + apiSecret = ""; + return this; + } + private ServiceBuilder setScope(String scope) { Preconditions.checkEmptyString(scope, "Invalid OAuth scope"); this.scope = scope; diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderCommon.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderCommon.java index ba36cdef0..fd71c49d8 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderCommon.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderCommon.java @@ -35,6 +35,16 @@ public interface ServiceBuilderCommon { */ ServiceBuilderCommon apiSecret(String apiSecret); + /** + * Configures the api secret as "" (empty string). + * + * Used usually for a test environments or another strange cases. Not all providers support empty string as api key + * and will throw an Exception in such cases. + * + * @return the {@link ServiceBuilder} instance for method chaining + */ + ServiceBuilderCommon apiSecretIsEmptyStringUnsafe(); + ServiceBuilderCommon httpClientConfig(HttpClientConfig httpClientConfig); /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java index d51f81f4b..8c7027cca 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth10a.java @@ -17,6 +17,9 @@ public interface ServiceBuilderOAuth10a extends ServiceBuilderCommon { @Override ServiceBuilderOAuth10a apiSecret(String apiSecret); + @Override + ServiceBuilderOAuth10a apiSecretIsEmptyStringUnsafe(); + @Override ServiceBuilderOAuth10a httpClientConfig(HttpClientConfig httpClientConfig); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java index 47a9cf3f6..9150f7428 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java @@ -17,6 +17,9 @@ public interface ServiceBuilderOAuth20 extends ServiceBuilderCommon { @Override ServiceBuilderOAuth20 apiSecret(String apiSecret); + @Override + ServiceBuilderOAuth20 apiSecretIsEmptyStringUnsafe(); + @Override ServiceBuilderOAuth20 httpClientConfig(HttpClientConfig httpClientConfig); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java index 82d1135be..0217c8e23 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java @@ -10,8 +10,7 @@ import com.github.scribejava.core.utils.Preconditions; /** - * HMAC-SHA1 implementation of {@link SignatureService} - * https://tools.ietf.org/html/rfc5849#section-3.4.2 + * HMAC-SHA1 implementation of {@link SignatureService} https://tools.ietf.org/html/rfc5849#section-3.4.2 */ public class HMACSha1SignatureService implements SignatureService { @@ -27,8 +26,8 @@ public class HMACSha1SignatureService implements SignatureService { @Override public String getSignature(String baseString, String apiSecret, String tokenSecret) { try { - Preconditions.checkEmptyString(baseString, "Base string cant be null or empty string"); - Preconditions.checkEmptyString(apiSecret, "Api secret cant be null or empty string"); + Preconditions.checkEmptyString(baseString, "Base string can't be null or empty string"); + Preconditions.checkNotNull(apiSecret, "Api secret can't be null"); return doSign(baseString, OAuthEncoder.encode(apiSecret) + '&' + OAuthEncoder.encode(tokenSecret)); } catch (UnsupportedEncodingException | NoSuchAlgorithmException | InvalidKeyException | RuntimeException e) { throw new OAuthSignatureException(baseString, e); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/PlaintextSignatureService.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/PlaintextSignatureService.java index 33661f10a..143348484 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/PlaintextSignatureService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/PlaintextSignatureService.java @@ -17,7 +17,7 @@ public class PlaintextSignatureService implements SignatureService { @Override public String getSignature(String baseString, String apiSecret, String tokenSecret) { try { - Preconditions.checkEmptyString(apiSecret, "Api secret cant be null or empty string"); + Preconditions.checkNotNull(apiSecret, "Api secret can't be null"); return OAuthEncoder.encode(apiSecret) + '&' + OAuthEncoder.encode(tokenSecret); } catch (Exception e) { throw new OAuthSignatureException(baseString, e); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/services/HMACSha1SignatureServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/services/HMACSha1SignatureServiceTest.java index d3fba9ae2..f690cae1d 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/services/HMACSha1SignatureServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/services/HMACSha1SignatureServiceTest.java @@ -44,8 +44,7 @@ public void shouldThrowExceptionIfApiSecretIsNull() { service.getSignature("base string", null, "tokenSecret"); } - @Test(expected = OAuthException.class) - public void shouldThrowExceptionIfApiSecretIsEmpty() { + public void shouldNotThrowExceptionIfApiSecretIsEmpty() { service.getSignature("base string", " ", "tokenSecret"); } } From bcbcca145d53a30afeb32cf5a566b89d7a3bccee Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Mon, 14 Dec 2020 19:43:03 +0300 Subject: [PATCH 421/481] add Slack API (https://slack.com/) (thanks to https://github.com/petrkopotev) --- README.md | 1 + changelog | 1 + .../java/com/github/scribejava/apis/SlackApi.java | 4 +--- .../apis/slack/SlackJsonTokenExtractor.java | 14 ++++++++------ .../apis/slack/SlackOAuth2AccessToken.java | 6 ++++-- .../scribejava/apis/examples/SlackExample.java | 5 ++--- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index a5de23588..8711df897 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ ScribeJava support out-of-box several HTTP clients: * Salesforce (https://www.salesforce.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java), [example with Async Ning HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java) * Sina (http://www.sina.com.cn/ http://weibo.com/login.php) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java) * Skyrock (http://skyrock.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java) +* Slack (https://slack.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SlackExample.java) * StackExchange (http://stackexchange.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java) * The Things Network (v1-staging and v2-preview) (https://www.thethingsnetwork.org/) [example v1](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java), [example v2 preview](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java) * Trello (https://trello.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java) diff --git a/changelog b/changelog index 0fbd04741..3e9215b58 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ [SNAPSHOT] * add raw Response (with HTTP repsponse code and body) as member to the OAuth2AccessTokenErrorResponse * add possibility to set "" (empty string) as apiSecret + * add Slack API (https://slack.com/) (thanks to https://github.com/petrkopotev) [8.0.0] * add Kakao API (https://kakao.com/) (thanks to https://github.com/v0o0v) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/SlackApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/SlackApi.java index 1cfd4436b..4d834fff1 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/SlackApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/SlackApi.java @@ -1,12 +1,10 @@ package com.github.scribejava.apis; -import com.github.scribejava.apis.fitbit.FitBitJsonTokenExtractor; import com.github.scribejava.apis.slack.SlackJsonTokenExtractor; -import com.github.scribejava.apis.slack.SlackOAuth2AccessToken; import com.github.scribejava.core.builder.api.DefaultApi20; /** - * Slack.com api + * Slack.com API */ public class SlackApi extends DefaultApi20 { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackJsonTokenExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackJsonTokenExtractor.java index 985cec908..ca0be7587 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackJsonTokenExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackJsonTokenExtractor.java @@ -19,14 +19,16 @@ public static SlackJsonTokenExtractor instance() { @Override protected SlackOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, - String refreshToken, String scope, JsonNode response, String rawResponse) { - String userAccessToken = ""; + String refreshToken, String scope, JsonNode response, String rawResponse) { + final String userAccessToken; final JsonNode userAccessTokenNode = response.get("authed_user").get("access_token"); - if (userAccessTokenNode != null) { - userAccessToken = userAccessTokenNode.asText(); + if (userAccessTokenNode == null) { + userAccessToken = ""; + } else { + userAccessToken = userAccessTokenNode.asText(); } - return new SlackOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, - userAccessToken, rawResponse); + return new SlackOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, userAccessToken, + rawResponse); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackOAuth2AccessToken.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackOAuth2AccessToken.java index cc0d7b120..d1d28ad7b 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackOAuth2AccessToken.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackOAuth2AccessToken.java @@ -6,9 +6,12 @@ public class SlackOAuth2AccessToken extends OAuth2AccessToken { + private static final long serialVersionUID = 1L; + private final String userAccessToken; - public SlackOAuth2AccessToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, String userAccessToken, String rawResponse) { + public SlackOAuth2AccessToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, + String scope, String userAccessToken, String rawResponse) { super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); this.userAccessToken = userAccessToken; } @@ -41,5 +44,4 @@ public boolean equals(Object obj) { return Objects.equals(userAccessToken, ((SlackOAuth2AccessToken) obj).getUserAccessToken()); } - } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SlackExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SlackExample.java index eb4be91d9..44a952d16 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SlackExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SlackExample.java @@ -19,7 +19,7 @@ public class SlackExample { private static final String NETWORK_NAME = "Slack.com"; private static final String BOT_RESOURCE_URL = "https://slack.com/api/channels.list"; - private static final String BOT_SCOPE = "channels:read" + private static final String BOT_SCOPE = "channels:read"; private static final String USER_RESOURCE_URL = "https://slack.com/api/users.list"; private static final String USER_SCOPE = "users:read"; private static final String PAYLOAD = "null"; @@ -86,7 +86,7 @@ public static void main(String... args) throws IOException, InterruptedException final OAuthRequest userRequest = new OAuthRequest(Verb.GET, USER_RESOURCE_URL); userRequest.addHeader(CONTENT_TYPE_NAME, CONTENT_TYPE_VALUE); userRequest.setPayload(PAYLOAD); - SlackOAuth2AccessToken token = (SlackOAuth2AccessToken)accessToken; + final SlackOAuth2AccessToken token = (SlackOAuth2AccessToken) accessToken; service.signRequest(token.getUserAccessToken(), userRequest); try (Response response = service.execute(userRequest)) { @@ -96,7 +96,6 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(response.getBody()); } - System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); } From 86a48546b083c724a82f7502d805b9cb55353bdd Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 30 Dec 2020 11:13:10 +0300 Subject: [PATCH 422/481] update dependencies --- pom.xml | 8 ++++---- scribejava-httpclient-armeria/pom.xml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index cc22f550e..8055ee43b 100644 --- a/pom.xml +++ b/pom.xml @@ -54,7 +54,7 @@ com.fasterxml.jackson.core jackson-databind - 2.11.3 + 2.12.0 junit @@ -104,7 +104,7 @@ com.puppycrawl.tools checkstyle - 8.37 + 8.38
    @@ -223,7 +223,7 @@ org.apache.maven.plugins maven-pmd-plugin - 3.13.0 + 3.14.0 net.sourceforge.pmd @@ -269,7 +269,7 @@ 7 - 6.29.0 + 6.30.0 diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index a60f50a23..bd2e126ab 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -23,7 +23,7 @@ com.linecorp.armeria armeria - 1.2.0 + 1.3.0 com.github.scribejava From 48f8cf0aefa80709b48f858e7cf6cc833204e84d Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 30 Dec 2020 11:42:44 +0300 Subject: [PATCH 423/481] prepare v8.1.0 --- README.md | 4 ++-- changelog | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8711df897..83180de24 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 8.0.0 + 8.1.0 ``` @@ -145,7 +145,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 8.0.0 + 8.1.0 ``` diff --git a/changelog b/changelog index 3e9215b58..85003feec 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,5 @@ -[SNAPSHOT] - * add raw Response (with HTTP repsponse code and body) as member to the OAuth2AccessTokenErrorResponse +[8.1.0] + * add raw Response (with HTTP response code and body) as member to the OAuth2AccessTokenErrorResponse * add possibility to set "" (empty string) as apiSecret * add Slack API (https://slack.com/) (thanks to https://github.com/petrkopotev) From 459432f84799b27279ffe56e98a4a0ac4a3f7dc3 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 30 Dec 2020 11:55:13 +0300 Subject: [PATCH 424/481] [maven-release-plugin] prepare release scribejava-8.1.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 8055ee43b..11f68b399 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 8.0.1-SNAPSHOT + 8.1.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -35,7 +35,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-8.1.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 272fa9d1f..34f642bae 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.0.1-SNAPSHOT + 8.1.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 7b0c9dcfb..03201a1da 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.0.1-SNAPSHOT + 8.1.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index bb4c9c981..ec6f5b1c8 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.0.1-SNAPSHOT + 8.1.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 38ee0e614..278f47c19 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.0.1-SNAPSHOT + 8.1.0 ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index bd2e126ab..f68547a14 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.0.1-SNAPSHOT + 8.1.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 1258d7563..413e729d0 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.0.1-SNAPSHOT + 8.1.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 580fea220..b752f4333 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.0.1-SNAPSHOT + 8.1.0 ../pom.xml From 0b3c0b72ceceea90276746db7dc6b50ebd58eb5b Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 30 Dec 2020 11:55:21 +0300 Subject: [PATCH 425/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 11f68b399..95716b662 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 8.1.0 + 8.1.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -35,7 +35,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-8.1.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 34f642bae..ecfeead2c 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.1.0 + 8.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 03201a1da..3a53aa72f 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.1.0 + 8.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index ec6f5b1c8..555a04ad7 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.1.0 + 8.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 278f47c19..006579c1d 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.1.0 + 8.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index f68547a14..31eb57e39 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.1.0 + 8.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 413e729d0..1507674fe 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.1.0 + 8.1.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index b752f4333..50bf431bf 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.1.0 + 8.1.1-SNAPSHOT ../pom.xml From 54407f0e6103cc0df5e27a85a78d94ca2ef75ee3 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 12 Jan 2021 11:21:32 +0300 Subject: [PATCH 426/481] add ScopeBuilder to easily specify multiple scopes while requesting OAuth2.0 Access Tokens --- changelog | 3 + pom.xml | 5 +- .../apis/examples/LinkedIn20Example.java | 3 +- .../scribejava/core/builder/ScopeBuilder.java | 56 +++++++++++++++++++ .../core/builder/ServiceBuilder.java | 5 ++ .../core/builder/ServiceBuilderOAuth20.java | 2 + .../core/oauth/AccessTokenRequestParams.java | 8 +++ scribejava-httpclient-ahc/pom.xml | 2 +- 8 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/builder/ScopeBuilder.java diff --git a/changelog b/changelog index 85003feec..bd36d6166 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * add ScopeBuilder to easily specify multiple scopes while requesting OAuth2.0 Access Tokens + [8.1.0] * add raw Response (with HTTP response code and body) as member to the OAuth2AccessTokenErrorResponse * add possibility to set "" (empty string) as apiSecret diff --git a/pom.xml b/pom.xml index 95716b662..b7f6a836f 100644 --- a/pom.xml +++ b/pom.xml @@ -54,7 +54,7 @@ com.fasterxml.jackson.core jackson-databind - 2.12.0 + 2.12.1 junit @@ -104,7 +104,7 @@ com.puppycrawl.tools checkstyle - 8.38 + 8.39 @@ -188,6 +188,7 @@ ${java.home}/bin/javadoc UTF-8 -html5 + all,-missing diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java index 9c5083386..05e6733df 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/LinkedIn20Example.java @@ -3,6 +3,7 @@ import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.apis.LinkedInApi20; +import com.github.scribejava.core.builder.ScopeBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; @@ -29,7 +30,7 @@ public static void main(String... args) throws IOException, InterruptedException final String clientSecret = "your client secret"; final OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) - .defaultScope("r_liteprofile r_emailaddress") // replace with desired scope + .defaultScope(new ScopeBuilder("r_liteprofile", "r_emailaddress")) // replace with desired scope .callback("http://example.com/callback") .build(LinkedInApi20.instance()); final Scanner in = new Scanner(System.in); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ScopeBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ScopeBuilder.java new file mode 100644 index 000000000..8bd22e1a4 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ScopeBuilder.java @@ -0,0 +1,56 @@ +package com.github.scribejava.core.builder; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +/** + * OAuth2.0 Scope Builder. It allows specifying multiple scopes one by one. It will combine them in the single + * space-delimited string. OAuth 2.0 standard specifies space as a delimiter for scopes + * (https://tools.ietf.org/html/rfc6749#section-3.3). If you found API, that do not support spaces, but support + * something else, let ScribeJava know (submit the issue here https://github.com/scribejava/scribejava/issues) and use + * your own concatenated string as a temporary workaround. + */ +public class ScopeBuilder { + + private final Set scopes = new HashSet<>(); + + public ScopeBuilder() { + } + + public ScopeBuilder(String scope) { + withScope(scope); + } + + public ScopeBuilder(String... scopes) { + withScopes(scopes); + } + + public ScopeBuilder(Collection scopes) { + withScopes(scopes); + } + + public final ScopeBuilder withScope(String scope) { + scopes.add(scope); + return this; + } + + public final ScopeBuilder withScopes(String... scopes) { + this.scopes.addAll(Arrays.asList(scopes)); + return this; + } + + public final ScopeBuilder withScopes(Collection scopes) { + this.scopes.addAll(scopes); + return this; + } + + public String build() { + final StringBuilder scopeBuilder = new StringBuilder(); + for (String scope : scopes) { + scopeBuilder.append(' ').append(scope); + } + return scopeBuilder.substring(1); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java index eb568e930..eade1ede5 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilder.java @@ -68,6 +68,11 @@ public ServiceBuilderOAuth20 defaultScope(String defaultScope) { return setScope(defaultScope); } + @Override + public ServiceBuilderOAuth20 defaultScope(ScopeBuilder scopeBuilder) { + return setScope(scopeBuilder.build()); + } + @Override public ServiceBuilderOAuth10a withScope(String scope) { return setScope(scope); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java index 9150f7428..bcf119db9 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/builder/ServiceBuilderOAuth20.java @@ -51,5 +51,7 @@ public interface ServiceBuilderOAuth20 extends ServiceBuilderCommon { */ ServiceBuilderOAuth20 defaultScope(String defaultScope); + ServiceBuilderOAuth20 defaultScope(ScopeBuilder scopeBuilder); + OAuth20Service build(DefaultApi20 api); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/AccessTokenRequestParams.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/AccessTokenRequestParams.java index 787ead8a7..5ee5d42ef 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/AccessTokenRequestParams.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/AccessTokenRequestParams.java @@ -1,6 +1,9 @@ package com.github.scribejava.core.oauth; +import com.github.scribejava.core.builder.ScopeBuilder; + public class AccessTokenRequestParams { + private final String code; private String pkceCodeVerifier; private String scope; @@ -23,6 +26,11 @@ public AccessTokenRequestParams scope(String scope) { return this; } + public AccessTokenRequestParams scope(ScopeBuilder scope) { + this.scope = scope.build(); + return this; + } + public String getCode() { return code; } diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 555a04ad7..218401fe4 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.12.1 + 2.12.2 com.github.scribejava From cd20f57ff1554a6d23a85c3bd5abadb4032956a6 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Thu, 14 Jan 2021 12:05:22 +0300 Subject: [PATCH 427/481] refactor unit tests (exception handling) --- .../FacebookAccessTokenJsonExtractorTest.java | 15 +++-- .../OAuth2AccessTokenJsonExtractorTest.java | 13 ++-- .../OAuthAsyncCompletionHandlerTest.java | 59 ++++++++++--------- .../OAuthAsyncCompletionHandlerTest.java | 59 ++++++++++--------- 4 files changed, 80 insertions(+), 66 deletions(-) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java index f62401bf6..45b68353b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java @@ -4,8 +4,9 @@ import java.io.IOException; import java.util.Collections; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import org.junit.Test; +import org.junit.function.ThrowingRunnable; public class FacebookAccessTokenJsonExtractorTest { @@ -19,9 +20,15 @@ public void shouldThrowExceptionIfResponseIsError() throws IOException { + "\"code\":100," + "\"fbtrace_id\":\"DtxvtGRaxbB\"}}"; try (Response response = error(body)) { - extractor.extract(response); - fail(); - } catch (FacebookAccessTokenErrorResponse fateR) { + + final FacebookAccessTokenErrorResponse fateR = assertThrows(FacebookAccessTokenErrorResponse.class, + new ThrowingRunnable() { + @Override + public void run() throws Throwable { + extractor.extract(response); + } + }); + assertEquals("This authorization code has been used.", fateR.getMessage()); assertEquals("OAuthException", fateR.getType()); assertEquals(100, fateR.getCodeInt()); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java index c39b265a8..66d5a4a72 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java @@ -10,7 +10,8 @@ import java.util.Collections; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; +import org.junit.function.ThrowingRunnable; public class OAuth2AccessTokenJsonExtractorTest { @@ -84,9 +85,13 @@ public void shouldThrowExceptionIfResponseIsError() throws IOException { + "\"error\":\"invalid_grant\"" + "}"; try (Response response = error(responseBody)) { - extractor.extract(response); - fail(); - } catch (OAuth2AccessTokenErrorResponse oaer) { + final OAuth2AccessTokenErrorResponse oaer = assertThrows(OAuth2AccessTokenErrorResponse.class, + new ThrowingRunnable() { + @Override + public void run() throws Throwable { + extractor.extract(response); + } + }); assertEquals(OAuth2Error.INVALID_GRANT, oaer.getError()); assertEquals("unknown, invalid, or expired refresh token", oaer.getErrorDescription()); } diff --git a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandlerTest.java b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandlerTest.java index e1a4ddc9c..684ac5c62 100644 --- a/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-apache/src/test/java/com/github/scribejava/httpclient/apache/OAuthAsyncCompletionHandlerTest.java @@ -4,7 +4,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -23,6 +22,8 @@ import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Response; +import static org.junit.Assert.assertThrows; +import org.junit.function.ThrowingRunnable; public class OAuthAsyncCompletionHandlerTest { @@ -80,7 +81,7 @@ public void shouldReleaseLatchOnSuccess() throws Exception { } @Test - public void shouldReleaseLatchOnIOException() throws Exception { + public void shouldReleaseLatchOnIOException() { handler = new OAuthAsyncCompletionHandler<>(callback, EXCEPTION_RESPONSE_CONVERTER); final HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); @@ -92,16 +93,16 @@ public void shouldReleaseLatchOnIOException() throws Exception { assertNotNull(callback.getThrowable()); assertTrue(callback.getThrowable() instanceof IOException); // verify latch is released - try { - handler.getResult(); - fail(); - } catch (ExecutionException expected) { - // expected - } + assertThrows(ExecutionException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + handler.getResult(); + } + }); } @Test - public void shouldReportOAuthException() throws Exception { + public void shouldReportOAuthException() { handler = new OAuthAsyncCompletionHandler<>(callback, OAUTH_EXCEPTION_RESPONSE_CONVERTER); final HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); @@ -113,16 +114,16 @@ public void shouldReportOAuthException() throws Exception { assertNotNull(callback.getThrowable()); assertTrue(callback.getThrowable() instanceof OAuthException); // verify latch is released - try { - handler.getResult(); - fail(); - } catch (ExecutionException expected) { - // expected - } + assertThrows(ExecutionException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + handler.getResult(); + } + }); } @Test - public void shouldReleaseLatchOnCancel() throws Exception { + public void shouldReleaseLatchOnCancel() { handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER); final HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); @@ -134,16 +135,16 @@ public void shouldReleaseLatchOnCancel() throws Exception { assertNotNull(callback.getThrowable()); assertTrue(callback.getThrowable() instanceof CancellationException); // verify latch is released - try { - handler.getResult(); - fail(); - } catch (ExecutionException expected) { - // expected - } + assertThrows(ExecutionException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + handler.getResult(); + } + }); } @Test - public void shouldReleaseLatchOnFailure() throws Exception { + public void shouldReleaseLatchOnFailure() { handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER); final HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok")); @@ -155,12 +156,12 @@ public void shouldReleaseLatchOnFailure() throws Exception { assertNotNull(callback.getThrowable()); assertTrue(callback.getThrowable() instanceof RuntimeException); // verify latch is released - try { - handler.getResult(); - fail(); - } catch (ExecutionException expected) { - // expected - } + assertThrows(ExecutionException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + handler.getResult(); + } + }); } private static class AllGoodResponseConverter implements OAuthRequest.ResponseConverter { diff --git a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java index 6e9f88fe5..b58e8df93 100644 --- a/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java +++ b/scribejava-httpclient-okhttp/src/test/java/com/github/scribejava/httpclient/okhttp/OAuthAsyncCompletionHandlerTest.java @@ -4,7 +4,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import java.io.IOException; import java.util.concurrent.ExecutionException; @@ -22,6 +22,7 @@ import okhttp3.Protocol; import okhttp3.Request; import okhttp3.ResponseBody; +import org.junit.function.ThrowingRunnable; public class OAuthAsyncCompletionHandlerTest { @@ -88,7 +89,7 @@ public void shouldReleaseLatchOnSuccess() throws Exception { } @Test - public void shouldReleaseLatchOnIOException() throws Exception { + public void shouldReleaseLatchOnIOException() { handler = new OAuthAsyncCompletionHandler<>(callback, EXCEPTION_RESPONSE_CONVERTER, future); call.enqueue(handler); @@ -105,16 +106,16 @@ public void shouldReleaseLatchOnIOException() throws Exception { assertNotNull(callback.getThrowable()); assertTrue(callback.getThrowable() instanceof IOException); // verify latch is released - try { - future.get(); - fail(); - } catch (ExecutionException expected) { - // expected - } + assertThrows(ExecutionException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + future.get(); + } + }); } @Test - public void shouldReportOAuthException() throws Exception { + public void shouldReportOAuthException() { handler = new OAuthAsyncCompletionHandler<>(callback, OAUTH_EXCEPTION_RESPONSE_CONVERTER, future); call.enqueue(handler); @@ -131,16 +132,16 @@ public void shouldReportOAuthException() throws Exception { assertNotNull(callback.getThrowable()); assertTrue(callback.getThrowable() instanceof OAuthException); // verify latch is released - try { - future.get(); - fail(); - } catch (ExecutionException expected) { - // expected - } + assertThrows(ExecutionException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + future.get(); + } + }); } @Test - public void shouldReleaseLatchOnCancel() throws Exception { + public void shouldReleaseLatchOnCancel() { handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER, future); call.enqueue(handler); @@ -149,16 +150,16 @@ public void shouldReleaseLatchOnCancel() throws Exception { assertNotNull(callback.getThrowable()); assertTrue(callback.getThrowable() instanceof IOException); // verify latch is released - try { - future.get(); - fail(); - } catch (ExecutionException expected) { - // expected - } + assertThrows(ExecutionException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + future.get(); + } + }); } @Test - public void shouldReleaseLatchOnFailure() throws Exception { + public void shouldReleaseLatchOnFailure() { handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER, future); call.enqueue(handler); @@ -167,12 +168,12 @@ public void shouldReleaseLatchOnFailure() throws Exception { assertNotNull(callback.getThrowable()); assertTrue(callback.getThrowable() instanceof IOException); // verify latch is released - try { - future.get(); - fail(); - } catch (ExecutionException expected) { - // expected - } + assertThrows(ExecutionException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + future.get(); + } + }); } private static class AllGoodResponseConverter implements OAuthRequest.ResponseConverter { From 450977a417476f5747276f6f3711eea07ba5c4e4 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 27 Jan 2021 13:04:07 +0300 Subject: [PATCH 428/481] remove Consumer interface and its usages (thanks to https://github.com/CodingFabian) --- .../scribejava/core/java8/Consumer.java | 47 ------------ .../httpclient/ahc/AhcHttpClient.java | 70 ++++++----------- .../httpclient/ning/NingHttpClient.java | 76 ++++++++----------- 3 files changed, 55 insertions(+), 138 deletions(-) delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/java8/Consumer.java diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Consumer.java b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Consumer.java deleted file mode 100644 index 83306b7be..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Consumer.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.github.scribejava.core.java8; - -/** - * Represents an operation that accepts a single input argument and returns no result. Unlike most other functional - * interfaces, {@code Consumer} is expected to operate via side-effects. - * - *

    - * This is a functional interface - * whose functional method is {@link #accept(Object)}. - * - * @param the type of the input to the operation - * - * @since 1.8 - */ -public interface Consumer { - - /** - * Performs this operation on the given argument. - * - * @param t the input argument - */ - void accept(T t); -} diff --git a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java index 4da925590..5c9b87249 100644 --- a/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java +++ b/scribejava-httpclient-ahc/src/main/java/com/github/scribejava/httpclient/ahc/AhcHttpClient.java @@ -2,7 +2,6 @@ import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; import com.github.scribejava.core.httpclient.multipart.MultipartPayload; -import com.github.scribejava.core.java8.Consumer; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; @@ -43,7 +42,7 @@ public void close() throws IOException { @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new ByteArrayConsumer(bodyContents), callback, + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.BYTE_ARRAY, bodyContents, callback, converter); } @@ -58,19 +57,19 @@ public Future executeAsync(String userAgent, Map headers, @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new StringConsumer(bodyContents), callback, + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.STRING, bodyContents, callback, converter); } @Override public Future executeAsync(String userAgent, Map headers, Verb httpVerb, String completeUrl, File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new FileConsumer(bodyContents), callback, + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.FILE, bodyContents, callback, converter); } private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, Consumer bodySetter, OAuthAsyncRequestCallback callback, + String completeUrl, BodySetter bodySetter, Object bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { final BoundRequestBuilder boundRequestBuilder; switch (httpVerb) { @@ -94,7 +93,7 @@ private Future doExecuteAsync(String userAgent, Map heade if (!headers.containsKey(CONTENT_TYPE)) { boundRequestBuilder.addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } - bodySetter.accept(boundRequestBuilder); + bodySetter.setBody(boundRequestBuilder, bodyContents); } for (Map.Entry header : headers.entrySet()) { @@ -108,45 +107,26 @@ private Future doExecuteAsync(String userAgent, Map heade return boundRequestBuilder.execute(new OAuthAsyncCompletionHandler<>(callback, converter)); } - private static class ByteArrayConsumer implements Consumer { - - private final byte[] bodyContents; - - private ByteArrayConsumer(byte[] bodyContents) { - this.bodyContents = bodyContents; - } - - @Override - public void accept(BoundRequestBuilder requestBuilder) { - requestBuilder.setBody(bodyContents); - } - } - - private static class StringConsumer implements Consumer { - - private final String bodyContents; - - private StringConsumer(String bodyContents) { - this.bodyContents = bodyContents; - } - - @Override - public void accept(BoundRequestBuilder requestBuilder) { - requestBuilder.setBody(bodyContents); - } - } - - private static class FileConsumer implements Consumer { - - private final File bodyContents; - - private FileConsumer(File bodyContents) { - this.bodyContents = bodyContents; - } + private enum BodySetter { + BYTE_ARRAY { + @Override + BoundRequestBuilder setBody(BoundRequestBuilder requestBuilder, Object bodyContents) { + return requestBuilder.setBody((byte[]) bodyContents); + } + }, + STRING { + @Override + BoundRequestBuilder setBody(BoundRequestBuilder requestBuilder, Object bodyContents) { + return requestBuilder.setBody((String) bodyContents); + } + }, + FILE { + @Override + BoundRequestBuilder setBody(BoundRequestBuilder requestBuilder, Object bodyContents) { + return requestBuilder.setBody((File) bodyContents); + } + }; - @Override - public void accept(BoundRequestBuilder requestBuilder) { - requestBuilder.setBody(bodyContents); - } + abstract BoundRequestBuilder setBody(BoundRequestBuilder requestBuilder, Object bodyContents); } } diff --git a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java index cc8c6fcda..52250f698 100644 --- a/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java +++ b/scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClient.java @@ -2,7 +2,6 @@ import com.github.scribejava.core.httpclient.AbstractAsyncOnlyHttpClient; import com.github.scribejava.core.httpclient.multipart.MultipartPayload; -import com.github.scribejava.core.java8.Consumer; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; @@ -50,7 +49,7 @@ public Future executeAsync(String userAgent, Map headers, final byte[] bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new ByteArrayConsumer(bodyContents), callback, + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.BYTE_ARRAY, bodyContents, callback, converter); } @@ -67,7 +66,7 @@ public Future executeAsync(String userAgent, Map headers, final String bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new StringConsumer(bodyContents), callback, + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.STRING, bodyContents, callback, converter); } @@ -76,13 +75,13 @@ public Future executeAsync(String userAgent, Map headers, final File bodyContents, OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { - return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, new FileConsumer(bodyContents), callback, + return doExecuteAsync(userAgent, headers, httpVerb, completeUrl, BodySetter.FILE, bodyContents, callback, converter); } private Future doExecuteAsync(String userAgent, Map headers, Verb httpVerb, - String completeUrl, Consumer bodySetter, - OAuthAsyncRequestCallback callback, OAuthRequest.ResponseConverter converter) { + String completeUrl, BodySetter bodySetter, Object bodyContents, OAuthAsyncRequestCallback callback, + OAuthRequest.ResponseConverter converter) { final AsyncHttpClient.BoundRequestBuilder boundRequestBuilder; switch (httpVerb) { case GET: @@ -105,7 +104,7 @@ private Future doExecuteAsync(String userAgent, Map heade if (!headers.containsKey(CONTENT_TYPE)) { boundRequestBuilder.addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } - bodySetter.accept(boundRequestBuilder); + bodySetter.setBody(boundRequestBuilder, bodyContents); } for (Map.Entry header : headers.entrySet()) { @@ -119,45 +118,30 @@ private Future doExecuteAsync(String userAgent, Map heade return boundRequestBuilder.execute(new OAuthAsyncCompletionHandler<>(callback, converter)); } - private static class ByteArrayConsumer implements Consumer { - - private final byte[] bodyContents; - - private ByteArrayConsumer(byte[] bodyContents) { - this.bodyContents = bodyContents; - } - - @Override - public void accept(AsyncHttpClient.BoundRequestBuilder requestBuilder) { - requestBuilder.setBody(bodyContents); - } - } - - private static class StringConsumer implements Consumer { - - private final String bodyContents; - - private StringConsumer(String bodyContents) { - this.bodyContents = bodyContents; - } - - @Override - public void accept(AsyncHttpClient.BoundRequestBuilder requestBuilder) { - requestBuilder.setBody(bodyContents); - } - } - - private static class FileConsumer implements Consumer { - - private final File bodyContents; - - private FileConsumer(File bodyContents) { - this.bodyContents = bodyContents; - } + private enum BodySetter { + BYTE_ARRAY { + @Override + AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder, + Object bodyContents) { + return requestBuilder.setBody((byte[]) bodyContents); + } + }, + STRING { + @Override + AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder, + Object bodyContents) { + return requestBuilder.setBody((String) bodyContents); + } + }, + FILE { + @Override + AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder, + Object bodyContents) { + return requestBuilder.setBody((File) bodyContents); + } + }; - @Override - public void accept(AsyncHttpClient.BoundRequestBuilder requestBuilder) { - requestBuilder.setBody(bodyContents); - } + abstract AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder, + Object bodyContents); } } From ba12ff648d0d3d1d119db5de9a8dedf80dac002d Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Fri, 5 Feb 2021 11:50:29 +0300 Subject: [PATCH 429/481] Uncapsulate base64 implementation details. (only java8 Base64 implementation is still available at the moment) --- changelog | 74 +- pom.xml | 1 + scribejava-core/pom.xml | 10 +- .../github/scribejava/core/base64/Base64.java | 48 + .../scribejava/core/base64/Java8Base64.java | 23 + .../github/scribejava/core/java8/Base64.java | 990 ------------------ .../HttpBasicAuthenticationScheme.java | 7 +- .../core/pkce/PKCECodeChallengeMethod.java | 6 +- .../scribejava/core/pkce/PKCEService.java | 5 +- .../services/HMACSha1SignatureService.java | 3 +- .../services/RSASha1SignatureService.java | 7 +- .../core/services/SignatureService.java | 6 +- .../core/oauth/OAuth20ServiceTest.java | 7 +- .../services/RSASha1SignatureServiceTest.java | 4 +- scribejava-java8/pom.xml | 33 + .../scribejava/java8/base64/Java8Base64.java | 20 + 16 files changed, 202 insertions(+), 1042 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/base64/Java8Base64.java delete mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java create mode 100644 scribejava-java8/pom.xml create mode 100644 scribejava-java8/src/main/java/com/github/scribejava/java8/base64/Java8Base64.java diff --git a/changelog b/changelog index bd36d6166..bf5216de7 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,7 @@ [SNAPSHOT] * add ScopeBuilder to easily specify multiple scopes while requesting OAuth2.0 Access Tokens + * make Base64 en/de-coding not dependent from java8 implementation (use three optional implementation + (internal java 8+, Apache Commons Codec, JAXB) detected in runtime) (thanks to https://github.com/CodingFabian) [8.1.0] * add raw Response (with HTTP response code and body) as member to the OAuth2AccessTokenErrorResponse @@ -61,7 +63,8 @@ [6.4.1] * support TLS 1.3 in JDK 11 for Salesforce - * fix NPE in Apache HTTP client in case of empty body in HTTP response (e.g. with 204 response code) (thanks to https://github.com/SainagNeelamPatnaik) + * fix NPE in Apache HTTP client in case of empty body in HTTP response (e.g. with 204 response code) + (thanks to https://github.com/SainagNeelamPatnaik) * separate OAuth1.0a and OAuth2.0 classes [6.3.0] @@ -73,7 +76,8 @@ and it should be set per request, not per created OAuthService [6.2.0] - * add new API Microsoft Azure Active Directory (Azure AD) 2.0 (thanks to https://github.com/rzukow and https://github.com/dgrudenic) + * add new API Microsoft Azure Active Directory (Azure AD) 2.0 + (thanks to https://github.com/rzukow and https://github.com/dgrudenic) [6.1.0] * add new API Keycloak (https://www.keycloak.org/) (thanks to https://github.com/JureZelic) @@ -81,18 +85,22 @@ [6.0.0] * make redirect_uri optional while Access Token requesting on OAuth 2.0 (thanks to https://github.com/computerlove) - * switch to java 9+ (from java 7 only) for compilation. Runtime is still java 7+. Complement README with links and RFC descriptions. + * switch to java 9+ (from java 7 only) for compilation. Runtime is still java 7+. + Complement README with links and RFC descriptions. * switch OAuth2 Bearer Token Usage from enum OAuth2SignatureType to interface BearerSignature to be extensible * add new API Wunderlist (https://www.wunderlist.com/) (thanks to https://github.com/M-F-K) [5.6.0] - * remove support for obsolete NetEase (http://www.163.com/) and sohu 搜狐 (http://www.sohu.com/) (thanks to https://github.com/zawn) + * remove support for obsolete NetEase (http://www.163.com/) and sohu 搜狐 (http://www.sohu.com/) + (thanks to https://github.com/zawn) * add Multipart functionality to JDK Http Client (thanks to https://github.com/eos1d3) * switch OAuth2 ClientAuthenticationType from enum to interface ClientAuthentication to be extensible according to https://tools.ietf.org/html/rfc6749#section-2.3.2 (thanks to https://github.com/zawn) - * add RuntimeException processing in async http clients (delivered to onError callbacks) (thanks to https://github.com/jochen314) + * add RuntimeException processing in async http clients (delivered to onError callbacks) + (thanks to https://github.com/jochen314) * check 200 status code from response in OAuth2AccessTokenExtractor (thanks to https://github.com/jochen314) - * fix case sensitive Http Headers comparison and sending Content-Type header along with content-type (thanks to https://github.com/marnix) + * fix case sensitive Http Headers comparison and sending Content-Type header along with content-type + (thanks to https://github.com/marnix) * add HiOrg-Server (https://www.hiorg-server.de/) API (thanks to https://github.com/MartinBoehmer) [5.5.0] @@ -105,7 +113,8 @@ * fix missing support for scope for refresh_token grant_type (thanks to https://github.com/tlxtellef) * add email field to VKOAuth2AccessToken (thanks to https://github.com/grouzen) * add new API - Automatic (https://www.automatic.com/) (thanks to https://github.com/ramsrib) - * add new API - Fitbit (https://www.fitbit.com/) (thanks to https://github.com/JustinLawler and https://github.com/alexthered) + * add new API - Fitbit (https://www.fitbit.com/) + (thanks to https://github.com/JustinLawler and https://github.com/alexthered) * deprecate OAuthConfig * OAuth1.0: send "oob" instead of null callback while requesting RequestToken (thanks to https://github.com/Rafaelsk) @@ -119,7 +128,8 @@ * add required param version to VK ВКонтакте (http://vk.com/) urls [5.2.0-java7again] - * allow 'null' as callback. It's an optional parameter. Remove "oob" as default (thanks to https://github.com/massongit) + * allow 'null' as callback. It's an optional parameter. Remove "oob" as default + (thanks to https://github.com/massongit) * java7 compatible again! [5.1.0] @@ -132,17 +142,20 @@ * drop Java 7 backward compatibility support, become Java 8 only (was reverted in v5.2.0-java7again) * add JSON token extractor for OAuth 1.0a (thanks to https://github.com/evstropovv) * add new API - uCoz (https://www.ucoz.com/) (thanks to https://github.com/evstropovv) - * add PKCE (RFC 7636) support (Proof Key for Code Exchange by OAuth Public Clients) (thanks for suggesting to https://github.com/dieseldjango) + * add PKCE (RFC 7636) support (Proof Key for Code Exchange by OAuth Public Clients) + (thanks for suggesting to https://github.com/dieseldjango) * switch to use HTTP Basic Authorization by default in requests with need of (2.3. Client Authentication) https://tools.ietf.org/html/rfc6749#section-2.3 Can be overrided in API class * add support for client_credentials grant type (thanks to https://github.com/vivin) * add support for RFC 7009 OAuth 2.0 Token Revocation (thanks to https://github.com/vivin) * add OAuth2Service signRequest method accepting just String, not OAuth2 Access Token Object. Remove signRequest from abstract OAuthService. 2.0 and 1.0a will be a bit more different now. - * drop toString method from *Tokens to prevent leak of sensible data (token ans secrets) (thanks to https://github.com/rcaa) + * drop toString method from *Tokens to prevent leak of sensible data (token ans secrets) + (thanks to https://github.com/rcaa) * add Apache HttpComponents HttpClient support in separate module (thanks to https://github.com/sschwieb) * add support for appsecret_proof in Facebook - * update Facebook v2.8 -> v2.11 (version can be configured while constructing OAuthService - use FacebookApi.customVersion("2.11")) + * update Facebook v2.8 -> v2.11 + (version can be configured while constructing OAuthService - use FacebookApi.customVersion("2.11")) [4.2.0] * DELETE in JdkClient permits, but not requires payload (thanks to https://github.com/miguelD73) @@ -155,21 +168,27 @@ * update Live API (thanks to https://github.com/typhoon17) [4.1.1] - * omit the client_secret parameter if it is an empty string while refreshing token (thanks to https://github.com/KungfuPancake) + * omit the client_secret parameter if it is an empty string while refreshing token + (thanks to https://github.com/KungfuPancake) * allow perms to be specified in Flickr Api (read, write, or delete) (thanks to https://github.com/rogerhu) - * OdnoklassnikiService should consider params in a body while signing the request (thanks to https://github.com/MrNeuronix) + * OdnoklassnikiService should consider params in a body while signing the request + (thanks to https://github.com/MrNeuronix) * do not open OutputStream for output while sending empty body in HTTP requests in the default JDK Http client [4.1.0] - * make client_secret optional in OAuth2 while requesting AccessToken (if set to null, it's not required by OAuth2 specs) + * make client_secret optional in OAuth2 while requesting AccessToken + (if set to null, it's not required by OAuth2 specs) * move OAuth1 SignatureType from ServiceBuilder to API * add body for PATCH HTTP method - * make addOAuthParams appendSignature methods protected in OAuth10aService (to override them in case of need) (thanks to https://github.com/vivin) + * make addOAuthParams appendSignature methods protected in OAuth10aService (to override them in case of need) + (thanks to https://github.com/vivin) [4.0.0] - * Remove OAuthRequestAsync, just OAuthRequest. Request should know about sync vs async. Move default Http engine to JDKHttpClient. + * Remove OAuthRequestAsync, just OAuthRequest. Request should know about sync vs async. + Move default Http engine to JDKHttpClient. * introduce SignatureType for OAuth2.0 to implement Bearer signing for the requests - * switch Google, GitHub, Facebook OAuth2.0 oauth requests signing to more secured recommended variant (GET-param -> header Bearer) + * switch Google, GitHub, Facebook OAuth2.0 oauth requests signing to more secured recommended variant + (GET-param -> header Bearer) * introduce custom nonstandard Facebook AccessTokenErrorResponse [3.4.1] @@ -182,14 +201,16 @@ * add support for byte[] and File (async only) payload in OAuth Requests (thanks to https://github.com/keijohyttinen) * add support for HTTP verbs (thanks to https://github.com/keijohyttinen) * add OkHttp http client support (thanks to https://github.com/arcao) - * add default HTTP client configs (to use like 'new ServiceBuilder().httpClientConfig(OkHttpHttpClientConfig.defaultConfig())') + * add default HTTP client configs + (to use like 'new ServiceBuilder().httpClientConfig(OkHttpHttpClientConfig.defaultConfig())') * you can use your own impl of AsyncHttpClient [3.3.0] * update Facebook v2.6 -> v2.8 * add The Things Network API (v1-staging and v2-preview) (thanks to https://github.com/jpmeijers) * add Box (thanks to https://github.com/MclaughlinSteve) - * fix: OAuth20Service::refreshAccessToken should use RefreshTokenEndpoint, not AccessTokenEndpoint (thanks to https://github.com/vivin) + * fix: OAuth20Service::refreshAccessToken should use RefreshTokenEndpoint, not AccessTokenEndpoint + (thanks to https://github.com/vivin) * move signRequest method to OAuthService (common for OAuth1 and OAuth2) (thanks to https://github.com/apomelov) * drop deprecated setConnectionKeepAlive method @@ -198,14 +219,17 @@ * handle OAuth2 error response for Issuing an Access Token (thanks to juherr) [3.1.0] - * fix OdnoklassnikiServiceImpl signature, params for hash must be sorted in lexicographic order, see http://new.apiok.ru/dev/methods/ + * fix OdnoklassnikiServiceImpl signature, params for hash must be sorted in lexicographic order, + see http://new.apiok.ru/dev/methods/ * add posibility to use externally created http client * make ScribeJava compilable under jdk7 (checkstyle downgraded for jdk 1.7) * add travis CI (check [oracle|open]jdk7 oraclejdk8) [3.0.0] - * create abstract HTTP Client layer to support different HTTP clients as plugins (AHC and Ning support becames maven submodules) - * remove changing global JVM property http.keepAlive, deprecate controlling this property inside of ScribeJava (thanks to wldaunfr and rockihack) + * create abstract HTTP Client layer to support different HTTP clients as plugins + (AHC and Ning support becames maven submodules) + * remove changing global JVM property http.keepAlive, deprecate controlling this property inside of ScribeJava + (thanks to wldaunfr and rockihack) [2.8.1] * add Salesforce sandbox API support @@ -246,8 +270,10 @@ [2.5.2] * add Google Async Exmaple (with bugfix for it to work) * add OSGI manifest metadata - * apiSecret is not mandatory parameter in config (to use on client sides and other flows without need of the API secret) - * implement OAuth2 Authorization Response parsing in the OAuth20Service (to extract code and state from url, useful for Android) + * apiSecret is not mandatory parameter in config + (to use on client sides and other flows without need of the API secret) + * implement OAuth2 Authorization Response parsing in the OAuth20Service + (to extract code and state from url, useful for Android) * update ok.ru API urls, add 'state' support, add refresh token to the example [2.4.0] diff --git a/pom.xml b/pom.xml index b7f6a836f..4863ccee6 100644 --- a/pom.xml +++ b/pom.xml @@ -16,6 +16,7 @@ scribejava-core + scribejava-java8 scribejava-apis scribejava-httpclient-ahc scribejava-httpclient-ning diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 3a53aa72f..47315ff9d 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -8,12 +8,20 @@ 8.1.1-SNAPSHOT ../pom.xml - + com.github.scribejava scribejava-core ScribeJava Core jar + + + com.github.scribejava + scribejava-java8 + ${project.version} + + + diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java new file mode 100644 index 000000000..95d15c6b8 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java @@ -0,0 +1,48 @@ +package com.github.scribejava.core.base64; + +public abstract class Base64 { + + private static volatile Base64 instance; + + public static Base64 getInstance() { + Base64 localInstance = instance; + if (localInstance == null) { + synchronized (Base64.class) { + localInstance = instance; + if (localInstance == null) { + localInstance = createInstance(); + instance = localInstance; + } + } + } + return localInstance; + } + + private static Base64 createInstance() { + return new Java8Base64(); + } + + public static void init(Base64 base64) { + synchronized (Base64.class) { + instance = base64; + } + } + + public static String encode(byte[] bytes) { + return getInstance().internalEncode(bytes); + } + + public static String encodeUrlWithoutPadding(byte[] bytes) { + return getInstance().internalEncodeUrlWithoutPadding(bytes); + } + + public static byte[] decodeMime(String string) { + return getInstance().internalDecodeMime(string); + } + + protected abstract String internalEncode(byte[] bytes); + + protected abstract String internalEncodeUrlWithoutPadding(byte[] bytes); + + protected abstract byte[] internalDecodeMime(String string); +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/base64/Java8Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Java8Base64.java new file mode 100644 index 000000000..5e92be625 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Java8Base64.java @@ -0,0 +1,23 @@ +package com.github.scribejava.core.base64; + +public class Java8Base64 extends Base64 { + + private static final com.github.scribejava.java8.base64.Java8Base64 JAVA8_BASE64 + = new com.github.scribejava.java8.base64.Java8Base64(); + + @Override + protected String internalEncode(byte[] bytes) { + return JAVA8_BASE64.internalEncode(bytes); + } + + @Override + protected String internalEncodeUrlWithoutPadding(byte[] bytes) { + return JAVA8_BASE64.internalEncodeUrlWithoutPadding(bytes); + } + + @Override + protected byte[] internalDecodeMime(String string) { + return JAVA8_BASE64.internalDecodeMime(string); + } + +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java deleted file mode 100644 index 221e7f24d..000000000 --- a/scribejava-core/src/main/java/com/github/scribejava/core/java8/Base64.java +++ /dev/null @@ -1,990 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.github.scribejava.core.java8; - -import java.io.FilterOutputStream; -import java.io.InputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.Objects; - -/** - * This class consists exclusively of static methods for obtaining encoders and decoders for the Base64 encoding scheme. - * The implementation of this class supports the following types of Base64 as specified in - * RFC 4648 and - * RFC 2045. - * - *

      - *
    • Basic - *

      - * Uses "The Base64 Alphabet" as specified in Table 1 of RFC 4648 and RFC 2045 for encoding and decoding operation. The - * encoder does not add any line feed (line separator) character. The decoder rejects data that contains characters - * outside the base64 alphabet.

    • - * - *
    • URL and Filename safe - *

      - * Uses the "URL and Filename safe Base64 Alphabet" as specified in Table 2 of RFC 4648 for encoding and decoding. The - * encoder does not add any line feed (line separator) character. The decoder rejects data that contains characters - * outside the base64 alphabet.

    • - * - *
    • MIME - *

      - * Uses the "The Base64 Alphabet" as specified in Table 1 of RFC 2045 for encoding and decoding operation. The encoded - * output must be represented in lines of no more than 76 characters each and uses a carriage return {@code '\r'} - * followed immediately by a linefeed {@code '\n'} as the line separator. No line separator is added to the end of the - * encoded output. All line separators or other characters not found in the base64 alphabet table are ignored in - * decoding operation.

    • - *
    - * - *

    - * Unless otherwise noted, passing a {@code null} argument to a method of this class will cause a {@link java.lang.NullPointerException - * NullPointerException} to be thrown. - * - * @author Xueming Shen - * @since 1.8 - */ -public class Base64 { - - private Base64() { - } - - /** - * Returns a {@link Encoder} that encodes using the - * Basic type base64 encoding scheme. - * - * @return A Base64 encoder. - */ - public static Encoder getEncoder() { - return Encoder.RFC4648; - } - - /** - * Returns a {@link Encoder} that encodes using the - * URL and Filename safe type base64 encoding scheme. - * - * @return A Base64 encoder. - */ - public static Encoder getUrlEncoder() { - return Encoder.RFC4648_URLSAFE; - } - - /** - * Returns a {@link Encoder} that encodes using the - * MIME type base64 encoding scheme. - * - * @return A Base64 encoder. - */ - public static Encoder getMimeEncoder() { - return Encoder.RFC2045; - } - - /** - * Returns a {@link Encoder} that encodes using the - * MIME type base64 encoding scheme with specified line length and line separators. - * - * @param lineLength the length of each output line (rounded down to nearest multiple of 4). If - * {@code lineLength <= 0} the output will not be separated in lines - * @param lineSeparator the line separator for each output line - * - * @return A Base64 encoder. - * - * @throws IllegalArgumentException if {@code lineSeparator} includes any character of "The Base64 Alphabet" as - * specified in Table 1 of RFC 2045. - */ - public static Encoder getMimeEncoder(int lineLength, byte[] lineSeparator) { - Objects.requireNonNull(lineSeparator); - int[] base64 = Decoder.FROM_BASE_64; - for (byte b : lineSeparator) { - if (base64[b & 0xff] != -1) { - throw new IllegalArgumentException( - "Illegal base64 line separator character 0x" + Integer.toString(b, 16)); - } - } - if (lineLength <= 0) { - return Encoder.RFC4648; - } - return new Encoder(false, lineSeparator, lineLength >> 2 << 2, true); - } - - /** - * Returns a {@link Decoder} that decodes using the - * Basic type base64 encoding scheme. - * - * @return A Base64 decoder. - */ - public static Decoder getDecoder() { - return Decoder.RFC4648; - } - - /** - * Returns a {@link Decoder} that decodes using the - * URL and Filename safe type base64 encoding scheme. - * - * @return A Base64 decoder. - */ - public static Decoder getUrlDecoder() { - return Decoder.RFC4648_URLSAFE; - } - - /** - * Returns a {@link Decoder} that decodes using the - * MIME type base64 decoding scheme. - * - * @return A Base64 decoder. - */ - public static Decoder getMimeDecoder() { - return Decoder.RFC2045; - } - - /** - * This class implements an encoder for encoding byte data using the Base64 encoding scheme as specified in RFC 4648 - * and RFC 2045. - * - *

    - * Instances of {@link Encoder} class are safe for use by multiple concurrent threads. - * - *

    - * Unless otherwise noted, passing a {@code null} argument to a method of this class will cause a - * {@link java.lang.NullPointerException NullPointerException} to be thrown. - * - * @see Decoder - * @since 1.8 - */ - public static class Encoder { - - private final byte[] newline; - private final int linemax; - private final boolean isURL; - private final boolean doPadding; - - /** - * This array is a lookup table that translates 6-bit positive integer index values into their "Base64 Alphabet" - * equivalents as specified in "Table 1: The Base64 Alphabet" of RFC 2045 (and RFC 4648). - */ - private static final char[] TO_BASE_64 = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' - }; - - /** - * It's the lookup table for "URL and Filename safe Base64" as specified in Table 2 of the RFC 4648, with the - * '+' and '/' changed to '-' and '_'. This table is used when BASE64_URL is specified. - */ - private static final char[] TO_BASE_64_URL = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_' - }; - - private static final int MIMELINEMAX = 76; - private static final byte[] CRLF = new byte[]{'\r', '\n'}; - - static final Encoder RFC4648 = new Encoder(false, null, -1, true); - static final Encoder RFC4648_URLSAFE = new Encoder(true, null, -1, true); - static final Encoder RFC2045 = new Encoder(false, CRLF, MIMELINEMAX, true); - - private Encoder(boolean isURL, byte[] newline, int linemax, boolean doPadding) { - this.isURL = isURL; - this.newline = newline; - this.linemax = linemax; - this.doPadding = doPadding; - } - - private int outLength(int srclen) { - int len; - if (doPadding) { - len = 4 * ((srclen + 2) / 3); - } else { - int n = srclen % 3; - len = 4 * (srclen / 3) + (n == 0 ? 0 : n + 1); - } - if (linemax > 0) // line separators - { - len += (len - 1) / linemax * newline.length; - } - return len; - } - - /** - * Encodes all bytes from the specified byte array into a newly-allocated byte array using the {@link Base64} - * encoding scheme. The returned byte array is of the length of the resulting bytes. - * - * @param src the byte array to encode - * @return A newly-allocated byte array containing the resulting encoded bytes. - */ - public byte[] encode(byte[] src) { - int len = outLength(src.length); // dst array size - byte[] dst = new byte[len]; - int ret = encode0(src, 0, src.length, dst); - if (ret != dst.length) { - return Arrays.copyOf(dst, ret); - } - return dst; - } - - /** - * Encodes all bytes from the specified byte array using the {@link Base64} encoding scheme, writing the - * resulting bytes to the given output byte array, starting at offset 0. - * - *

    - * It is the responsibility of the invoker of this method to make sure the output byte array {@code dst} has - * enough space for encoding all bytes from the input byte array. No bytes will be written to the output byte - * array if the output byte array is not big enough. - * - * @param src the byte array to encode - * @param dst the output byte array - * @return The number of bytes written to the output byte array - * - * @throws IllegalArgumentException if {@code dst} does not have enough space for encoding all input bytes. - */ - public int encode(byte[] src, byte[] dst) { - int len = outLength(src.length); // dst array size - if (dst.length < len) { - throw new IllegalArgumentException( - "Output byte array is too small for encoding all input bytes"); - } - return encode0(src, 0, src.length, dst); - } - - /** - * Encodes the specified byte array into a String using the {@link Base64} encoding scheme. - * - *

    - * This method first encodes all input bytes into a base64 encoded byte array and then constructs a new String - * by using the encoded byte array and the {@link java.nio.charset.StandardCharsets#ISO_8859_1 - * ISO-8859-1} charset. - * - *

    - * In other words, an invocation of this method has exactly the same effect as invoking - * {@code new String(encode(src), StandardCharsets.ISO_8859_1)}. - * - * @param src the byte array to encode - * @return A String containing the resulting Base64 encoded characters - */ - @SuppressWarnings("deprecation") - public String encodeToString(byte[] src) { - byte[] encoded = encode(src); - return new String(encoded, 0, 0, encoded.length); - } - - /** - * Encodes all remaining bytes from the specified byte buffer into a newly-allocated ByteBuffer using the - * {@link Base64} encoding scheme. - * - * Upon return, the source buffer's position will be updated to its limit; its limit will not have been changed. - * The returned output buffer's position will be zero and its limit will be the number of resulting encoded - * bytes. - * - * @param buffer the source ByteBuffer to encode - * @return A newly-allocated byte buffer containing the encoded bytes. - */ - public ByteBuffer encode(ByteBuffer buffer) { - int len = outLength(buffer.remaining()); - byte[] dst = new byte[len]; - int ret; - if (buffer.hasArray()) { - ret = encode0(buffer.array(), - buffer.arrayOffset() + buffer.position(), - buffer.arrayOffset() + buffer.limit(), - dst); - buffer.position(buffer.limit()); - } else { - byte[] src = new byte[buffer.remaining()]; - buffer.get(src); - ret = encode0(src, 0, src.length, dst); - } - if (ret != dst.length) { - dst = Arrays.copyOf(dst, ret); - } - return ByteBuffer.wrap(dst); - } - - /** - * Wraps an output stream for encoding byte data using the {@link Base64} encoding scheme. - * - *

    - * It is recommended to promptly close the returned output stream after use, during which it will flush all - * possible leftover bytes to the underlying output stream. Closing the returned output stream will close the - * underlying output stream. - * - * @param os the output stream. - * @return the output stream for encoding the byte data into the specified Base64 encoded format - */ - public OutputStream wrap(OutputStream os) { - Objects.requireNonNull(os); - return new EncOutputStream(os, isURL ? TO_BASE_64_URL : TO_BASE_64, - newline, linemax, doPadding); - } - - /** - * Returns an encoder instance that encodes equivalently to this one, but without adding any padding character - * at the end of the encoded byte data. - * - *

    - * The encoding scheme of this encoder instance is unaffected by this invocation. The returned encoder instance - * should be used for non-padding encoding operation. - * - * @return an equivalent encoder that encodes without adding any padding character at the end - */ - public Encoder withoutPadding() { - if (!doPadding) { - return this; - } - return new Encoder(isURL, newline, linemax, false); - } - - private int encode0(byte[] src, int off, int end, byte[] dst) { - char[] base64 = isURL ? TO_BASE_64_URL : TO_BASE_64; - int sp = off; - int slen = (end - off) / 3 * 3; - int sl = off + slen; - if (linemax > 0 && slen > linemax / 4 * 3) { - slen = linemax / 4 * 3; - } - int dp = 0; - while (sp < sl) { - int sl0 = Math.min(sp + slen, sl); - for (int sp0 = sp, dp0 = dp; sp0 < sl0;) { - int bits = (src[sp0++] & 0xff) << 16 - | (src[sp0++] & 0xff) << 8 - | (src[sp0++] & 0xff); - dst[dp0++] = (byte) base64[(bits >>> 18) & 0x3f]; - dst[dp0++] = (byte) base64[(bits >>> 12) & 0x3f]; - dst[dp0++] = (byte) base64[(bits >>> 6) & 0x3f]; - dst[dp0++] = (byte) base64[bits & 0x3f]; - } - int dlen = (sl0 - sp) / 3 * 4; - dp += dlen; - sp = sl0; - if (dlen == linemax && sp < end) { - for (byte b : newline) { - dst[dp++] = b; - } - } - } - if (sp < end) { // 1 or 2 leftover bytes - int b0 = src[sp++] & 0xff; - dst[dp++] = (byte) base64[b0 >> 2]; - if (sp == end) { - dst[dp++] = (byte) base64[(b0 << 4) & 0x3f]; - if (doPadding) { - dst[dp++] = '='; - dst[dp++] = '='; - } - } else { - int b1 = src[sp++] & 0xff; - dst[dp++] = (byte) base64[(b0 << 4) & 0x3f | (b1 >> 4)]; - dst[dp++] = (byte) base64[(b1 << 2) & 0x3f]; - if (doPadding) { - dst[dp++] = '='; - } - } - } - return dp; - } - } - - /** - * This class implements a decoder for decoding byte data using the Base64 encoding scheme as specified in RFC 4648 - * and RFC 2045. - * - *

    - * The Base64 padding character {@code '='} is accepted and interpreted as the end of the encoded byte data, but is - * not required. So if the final unit of the encoded byte data only has two or three Base64 characters (without the - * corresponding padding character(s) padded), they are decoded as if followed by padding character(s). If there is - * a padding character present in the final unit, the correct number of padding character(s) must be present, - * otherwise {@code IllegalArgumentException} ( {@code IOException} when reading from a Base64 stream) is thrown - * during decoding. - * - *

    - * Instances of {@link Decoder} class are safe for use by multiple concurrent threads. - * - *

    - * Unless otherwise noted, passing a {@code null} argument to a method of this class will cause a - * {@link java.lang.NullPointerException NullPointerException} to be thrown. - * - * @see Encoder - * @since 1.8 - */ - public static class Decoder { - - private final boolean isURL; - private final boolean isMIME; - - /** - * Lookup table for decoding unicode characters drawn from the "Base64 Alphabet" (as specified in Table 1 of RFC - * 2045) into their 6-bit positive integer equivalents. Characters that are not in the Base64 alphabet but fall - * within the bounds of the array are encoded to -1. - * - */ - private static final int[] FROM_BASE_64 = new int[256]; - - static { - Arrays.fill(FROM_BASE_64, -1); - for (int i = 0; i < Encoder.TO_BASE_64.length; i++) { - FROM_BASE_64[Encoder.TO_BASE_64[i]] = i; - } - FROM_BASE_64['='] = -2; - } - - /** - * Lookup table for decoding "URL and Filename safe Base64 Alphabet" as specified in Table2 of the RFC 4648. - */ - private static final int[] FROM_BASE_64_URL = new int[256]; - - static { - Arrays.fill(FROM_BASE_64_URL, -1); - for (int i = 0; i < Encoder.TO_BASE_64_URL.length; i++) { - FROM_BASE_64_URL[Encoder.TO_BASE_64_URL[i]] = i; - } - FROM_BASE_64_URL['='] = -2; - } - - static final Decoder RFC4648 = new Decoder(false, false); - static final Decoder RFC4648_URLSAFE = new Decoder(true, false); - static final Decoder RFC2045 = new Decoder(false, true); - - private Decoder(boolean isURL, boolean isMIME) { - this.isURL = isURL; - this.isMIME = isMIME; - } - - /** - * Decodes all bytes from the input byte array using the {@link Base64} encoding scheme, writing the results - * into a newly-allocated output byte array. The returned byte array is of the length of the resulting bytes. - * - * @param src the byte array to decode - * - * @return A newly-allocated byte array containing the decoded bytes. - * - * @throws IllegalArgumentException if {@code src} is not in valid Base64 scheme - */ - public byte[] decode(byte[] src) { - byte[] dst = new byte[outLength(src, 0, src.length)]; - int ret = decode0(src, 0, src.length, dst); - if (ret != dst.length) { - dst = Arrays.copyOf(dst, ret); - } - return dst; - } - - /** - * Decodes a Base64 encoded String into a newly-allocated byte array using the {@link Base64} encoding scheme. - * - *

    - * An invocation of this method has exactly the same effect as invoking - * {@code decode(src.getBytes(StandardCharsets.ISO_8859_1))} - * - * @param src the string to decode - * - * @return A newly-allocated byte array containing the decoded bytes. - * - * @throws IllegalArgumentException if {@code src} is not in valid Base64 scheme - */ - public byte[] decode(String src) { - return decode(src.getBytes(StandardCharsets.ISO_8859_1)); - } - - /** - * Decodes all bytes from the input byte array using the {@link Base64} encoding scheme, writing the results - * into the given output byte array, starting at offset 0. - * - *

    - * It is the responsibility of the invoker of this method to make sure the output byte array {@code dst} has - * enough space for decoding all bytes from the input byte array. No bytes will be be written to the output byte - * array if the output byte array is not big enough. - * - *

    - * If the input byte array is not in valid Base64 encoding scheme then some bytes may have been written to the - * output byte array before IllegalargumentException is thrown. - * - * @param src the byte array to decode - * @param dst the output byte array - * - * @return The number of bytes written to the output byte array - * - * @throws IllegalArgumentException if {@code src} is not in valid Base64 scheme, or {@code dst} does not have - * enough space for decoding all input bytes. - */ - public int decode(byte[] src, byte[] dst) { - int len = outLength(src, 0, src.length); - if (dst.length < len) { - throw new IllegalArgumentException( - "Output byte array is too small for decoding all input bytes"); - } - return decode0(src, 0, src.length, dst); - } - - /** - * Decodes all bytes from the input byte buffer using the {@link Base64} encoding scheme, writing the results - * into a newly-allocated ByteBuffer. - * - *

    - * Upon return, the source buffer's position will be updated to its limit; its limit will not have been changed. - * The returned output buffer's position will be zero and its limit will be the number of resulting decoded - * bytes - * - *

    - * {@code IllegalArgumentException} is thrown if the input buffer is not in valid Base64 encoding scheme. The - * position of the input buffer will not be advanced in this case. - * - * @param buffer the ByteBuffer to decode - * - * @return A newly-allocated byte buffer containing the decoded bytes - * - * @throws IllegalArgumentException if {@code src} is not in valid Base64 scheme. - */ - public ByteBuffer decode(ByteBuffer buffer) { - int pos0 = buffer.position(); - try { - byte[] src; - int sp; - int sl; - if (buffer.hasArray()) { - src = buffer.array(); - sp = buffer.arrayOffset() + buffer.position(); - sl = buffer.arrayOffset() + buffer.limit(); - buffer.position(buffer.limit()); - } else { - src = new byte[buffer.remaining()]; - buffer.get(src); - sp = 0; - sl = src.length; - } - byte[] dst = new byte[outLength(src, sp, sl)]; - return ByteBuffer.wrap(dst, 0, decode0(src, sp, sl, dst)); - } catch (IllegalArgumentException iae) { - buffer.position(pos0); - throw iae; - } - } - - /** - * Returns an input stream for decoding {@link Base64} encoded byte stream. - * - *

    - * The {@code read} methods of the returned {@code InputStream} will throw {@code IOException} when reading - * bytes that cannot be decoded. - * - *

    - * Closing the returned input stream will close the underlying input stream. - * - * @param is the input stream - * - * @return the input stream for decoding the specified Base64 encoded byte stream - */ - public InputStream wrap(InputStream is) { - Objects.requireNonNull(is); - return new DecInputStream(is, isURL ? FROM_BASE_64_URL : FROM_BASE_64, isMIME); - } - - private int outLength(byte[] src, int sp, int sl) { - int[] base64 = isURL ? FROM_BASE_64_URL : FROM_BASE_64; - int paddings = 0; - int len = sl - sp; - if (len == 0) { - return 0; - } - if (len < 2) { - if (isMIME && base64[0] == -1) { - return 0; - } - throw new IllegalArgumentException( - "Input byte[] should at least have 2 bytes for base64 bytes"); - } - if (isMIME) { - // scan all bytes to fill out all non-alphabet. a performance - // trade-off of pre-scan or Arrays.copyOf - int n = 0; - while (sp < sl) { - int b = src[sp++] & 0xff; - if (b == '=') { - len -= sl - sp + 1; - break; - } - b = base64[b]; - if (b == -1) { - n++; - } - } - len -= n; - } else { - if (src[sl - 1] == '=') { - paddings++; - if (src[sl - 2] == '=') { - paddings++; - } - } - } - if (paddings == 0 && (len & 0x3) != 0) { - paddings = 4 - (len & 0x3); - } - return 3 * ((len + 3) / 4) - paddings; - } - - private int decode0(byte[] src, int sp, int sl, byte[] dst) { - int[] base64 = isURL ? FROM_BASE_64_URL : FROM_BASE_64; - int dp = 0; - int bits = 0; - int shiftto = 18; // pos of first byte of 4-byte atom - while (sp < sl) { - int b = src[sp++] & 0xff; - b = base64[b]; - if (b < 0) { - if (b == -2) { // padding byte '=' - // = shiftto==18 unnecessary padding - // x= shiftto==12 a dangling single x - // x to be handled together with non-padding case - // xx= shiftto==6&&sp==sl missing last = - // xx=y shiftto==6 last is not = - if (shiftto == 6 && (sp == sl || src[sp++] != '=') - || shiftto == 18) { - throw new IllegalArgumentException( - "Input byte array has wrong 4-byte ending unit"); - } - break; - } - if (isMIME) // skip if for rfc2045 - { - continue; - } else { - throw new IllegalArgumentException( - "Illegal base64 character " - + Integer.toString(src[sp - 1], 16)); - } - } - bits |= b << shiftto; - shiftto -= 6; - if (shiftto < 0) { - dst[dp++] = (byte) (bits >> 16); - dst[dp++] = (byte) (bits >> 8); - dst[dp++] = (byte) (bits); - shiftto = 18; - bits = 0; - } - } - // reached end of byte array or hit padding '=' characters. - switch (shiftto) { - case 6: - dst[dp++] = (byte) (bits >> 16); - break; - case 0: - dst[dp++] = (byte) (bits >> 16); - dst[dp++] = (byte) (bits >> 8); - break; - case 12: - // dangling single "x", incorrectly encoded. - throw new IllegalArgumentException( - "Last unit does not have enough valid bits"); - default: - break; - } - // anything left is invalid, if is not MIME. - // if MIME, ignore all non-base64 character - while (sp < sl) { - if (isMIME && base64[src[sp++]] < 0) { - continue; - } - throw new IllegalArgumentException( - "Input byte array has incorrect ending byte at " + sp); - } - return dp; - } - } - - /* - * An output stream for encoding bytes into the Base64. - */ - private static class EncOutputStream extends FilterOutputStream { - - private int leftover; - private int b0; - private int b1; - private int b2; - private boolean closed; - - private final char[] base64; // byte->base64 mapping - private final byte[] newline; // line separator, if needed - private final int linemax; - private final boolean doPadding;// whether or not to pad - private int linepos; - - EncOutputStream(OutputStream os, char[] base64, - byte[] newline, int linemax, boolean doPadding) { - super(os); - this.base64 = base64; - this.newline = newline; - this.linemax = linemax; - this.doPadding = doPadding; - } - - @Override - public void write(int b) throws IOException { - byte[] buf = new byte[1]; - buf[0] = (byte) (b & 0xff); - write(buf, 0, 1); - } - - private void checkNewline() throws IOException { - if (linepos == linemax) { - out.write(newline); - linepos = 0; - } - } - - @Override - public void write(byte[] b, int off, int len) throws IOException { - if (closed) { - throw new IOException("Stream is closed"); - } - if (off < 0 || len < 0 || off + len > b.length) { - throw new ArrayIndexOutOfBoundsException(); - } - if (len == 0) { - return; - } - if (leftover != 0) { - if (leftover == 1) { - b1 = b[off++] & 0xff; - len--; - if (len == 0) { - leftover++; - return; - } - } - b2 = b[off++] & 0xff; - len--; - checkNewline(); - out.write(base64[b0 >> 2]); - out.write(base64[(b0 << 4) & 0x3f | (b1 >> 4)]); - out.write(base64[(b1 << 2) & 0x3f | (b2 >> 6)]); - out.write(base64[b2 & 0x3f]); - linepos += 4; - } - int nBits24 = len / 3; - leftover = len - (nBits24 * 3); - while (nBits24-- > 0) { - checkNewline(); - int bits = (b[off++] & 0xff) << 16 - | (b[off++] & 0xff) << 8 - | (b[off++] & 0xff); - out.write(base64[(bits >>> 18) & 0x3f]); - out.write(base64[(bits >>> 12) & 0x3f]); - out.write(base64[(bits >>> 6) & 0x3f]); - out.write(base64[bits & 0x3f]); - linepos += 4; - } - if (leftover == 1) { - b0 = b[off++] & 0xff; - } else if (leftover == 2) { - b0 = b[off++] & 0xff; - b1 = b[off++] & 0xff; - } - } - - @Override - public void close() throws IOException { - if (!closed) { - closed = true; - if (leftover == 1) { - checkNewline(); - out.write(base64[b0 >> 2]); - out.write(base64[(b0 << 4) & 0x3f]); - if (doPadding) { - out.write('='); - out.write('='); - } - } else if (leftover == 2) { - checkNewline(); - out.write(base64[b0 >> 2]); - out.write(base64[(b0 << 4) & 0x3f | (b1 >> 4)]); - out.write(base64[(b1 << 2) & 0x3f]); - if (doPadding) { - out.write('='); - } - } - leftover = 0; - out.close(); - } - } - } - - /* - * An input stream for decoding Base64 bytes - */ - private static class DecInputStream extends InputStream { - - private final InputStream is; - private final boolean isMIME; - private final int[] base64; // base64 -> byte mapping - private int bits; // 24-bit buffer for decoding - private int nextin = 18; // next available "off" in "bits" for input; - // -> 18, 12, 6, 0 - private int nextout = -8; // next available "off" in "bits" for output; - // -> 8, 0, -8 (no byte for output) - private boolean eof; - private boolean closed; - - private final byte[] sbBuf = new byte[1]; - - DecInputStream(InputStream is, int[] base64, boolean isMIME) { - this.is = is; - this.base64 = base64; - this.isMIME = isMIME; - } - - @Override - public int read() throws IOException { - return read(sbBuf, 0, 1) == -1 ? -1 : sbBuf[0] & 0xff; - } - - @Override - public int read(byte[] b, int off, int len) throws IOException { - if (closed) { - throw new IOException("Stream is closed"); - } - if (eof && nextout < 0) // eof and no leftover - { - return -1; - } - if (off < 0 || len < 0 || len > b.length - off) { - throw new IndexOutOfBoundsException(); - } - int oldOff = off; - if (nextout >= 0) { // leftover output byte(s) in bits buf - do { - if (len == 0) { - return off - oldOff; - } - b[off++] = (byte) (bits >> nextout); - len--; - nextout -= 8; - } while (nextout >= 0); - bits = 0; - } - while (len > 0) { - int v = is.read(); - if (v == -1) { - eof = true; - if (nextin != 18) { - if (nextin == 12) { - throw new IOException("Base64 stream has one un-decoded dangling byte."); - } - // treat ending xx/xxx without padding character legal. - // same logic as v == '=' below - b[off++] = (byte) (bits >> (16)); - len--; - if (nextin == 0) { // only one padding byte - if (len == 0) { // no enough output space - bits >>= 8; // shift to lowest byte - nextout = 0; - } else { - b[off++] = (byte) (bits >> 8); - } - } - } - if (off == oldOff) { - return -1; - } else { - return off - oldOff; - } - } - if (v == '=') { // padding byte(s) - // = shiftto==18 unnecessary padding - // x= shiftto==12 dangling x, invalid unit - // xx= shiftto==6 && missing last '=' - // xx=y or last is not '=' - if (nextin == 18 || nextin == 12 - || nextin == 6 && is.read() != '=') { - throw new IOException("Illegal base64 ending sequence:" + nextin); - } - b[off++] = (byte) (bits >> (16)); - len--; - if (nextin == 0) { // only one padding byte - if (len == 0) { // no enough output space - bits >>= 8; // shift to lowest byte - nextout = 0; - } else { - b[off++] = (byte) (bits >> 8); - } - } - eof = true; - break; - } - v = base64[v]; - if (v == -1) { - if (isMIME) // skip if for rfc2045 - { - continue; - } else { - throw new IOException("Illegal base64 character " - + Integer.toString(v, 16)); - } - } - bits |= v << nextin; - if (nextin == 0) { - nextin = 18; // clear for next - nextout = 16; - while (nextout >= 0) { - b[off++] = (byte) (bits >> nextout); - len--; - nextout -= 8; - if (len == 0 && nextout >= 0) { // don't clean "bits" - return off - oldOff; - } - } - bits = 0; - } else { - nextin -= 6; - } - } - return off - oldOff; - } - - @Override - public int available() throws IOException { - if (closed) { - throw new IOException("Stream is closed"); - } - return is.available(); // TBD: - } - - @Override - public void close() throws IOException { - if (!closed) { - closed = true; - is.close(); - } - } - } -} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/HttpBasicAuthenticationScheme.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/HttpBasicAuthenticationScheme.java index 509869d51..3931f6f7b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/HttpBasicAuthenticationScheme.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth2/clientauthentication/HttpBasicAuthenticationScheme.java @@ -1,6 +1,6 @@ package com.github.scribejava.core.oauth2.clientauthentication; -import com.github.scribejava.core.java8.Base64; +import com.github.scribejava.core.base64.Base64; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import java.nio.charset.Charset; @@ -14,8 +14,6 @@ */ public class HttpBasicAuthenticationScheme implements ClientAuthentication { - private final Base64.Encoder base64Encoder = Base64.getEncoder(); - protected HttpBasicAuthenticationScheme() { } @@ -32,8 +30,7 @@ public static HttpBasicAuthenticationScheme instance() { public void addClientAuthentication(OAuthRequest request, String apiKey, String apiSecret) { if (apiKey != null && apiSecret != null) { request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + ' ' - + base64Encoder.encodeToString( - String.format("%s:%s", apiKey, apiSecret).getBytes(Charset.forName("UTF-8")))); + + Base64.encode(String.format("%s:%s", apiKey, apiSecret).getBytes(Charset.forName("UTF-8")))); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java index 08bb60c5b..374f80336 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCECodeChallengeMethod.java @@ -1,17 +1,15 @@ package com.github.scribejava.core.pkce; -import com.github.scribejava.core.java8.Base64; +import com.github.scribejava.core.base64.Base64; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public enum PKCECodeChallengeMethod { S256 { - private final Base64.Encoder base64Encoder = Base64.getUrlEncoder().withoutPadding(); - @Override public String transform2CodeChallenge(String codeVerifier) throws NoSuchAlgorithmException { - return base64Encoder.encodeToString( + return Base64.encodeUrlWithoutPadding( MessageDigest.getInstance("SHA-256").digest(codeVerifier.getBytes(StandardCharsets.US_ASCII))); } }, diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java index eea3e7b94..23a5347ec 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/pkce/PKCEService.java @@ -1,6 +1,6 @@ package com.github.scribejava.core.pkce; -import com.github.scribejava.core.java8.Base64; +import com.github.scribejava.core.base64.Base64; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; @@ -11,7 +11,6 @@ public class PKCEService { private static final SecureRandom RANDOM = new SecureRandom(); - private static final Base64.Encoder BASE_64_ENCODER = Base64.getUrlEncoder().withoutPadding(); /** * number of octets to randomly generate. */ @@ -44,7 +43,7 @@ public PKCE generatePKCE() { } public PKCE generatePKCE(byte[] randomBytes) { - final String codeVerifier = BASE_64_ENCODER.encodeToString(randomBytes); + final String codeVerifier = Base64.encodeUrlWithoutPadding(randomBytes); final PKCE pkce = new PKCE(); pkce.setCodeVerifier(codeVerifier); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java index 0217c8e23..363011a13 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/HMACSha1SignatureService.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.services; +import com.github.scribejava.core.base64.Base64; import java.io.UnsupportedEncodingException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; @@ -40,7 +41,7 @@ private String doSign(String toSign, String keyString) throws UnsupportedEncodin final Mac mac = Mac.getInstance(HMAC_SHA1); mac.init(key); final byte[] bytes = mac.doFinal(toSign.getBytes(UTF8)); - return BASE_64_ENCODER.encodeToString(bytes).replace(CARRIAGE_RETURN, EMPTY_STRING); + return Base64.encode(bytes).replace(CARRIAGE_RETURN, EMPTY_STRING); } /** diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/RSASha1SignatureService.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/RSASha1SignatureService.java index 9cb460e7b..dc16eace4 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/RSASha1SignatureService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/RSASha1SignatureService.java @@ -1,5 +1,6 @@ package com.github.scribejava.core.services; +import com.github.scribejava.core.base64.Base64; import java.security.PrivateKey; import java.security.Signature; import java.security.SignatureException; @@ -32,9 +33,9 @@ public String getSignature(String baseString, String apiSecret, String tokenSecr final Signature signature = Signature.getInstance(RSA_SHA1); signature.initSign(privateKey); signature.update(baseString.getBytes(UTF8)); - return BASE_64_ENCODER.encodeToString(signature.sign()); - } catch (NoSuchAlgorithmException | InvalidKeyException | SignatureException | UnsupportedEncodingException | - RuntimeException e) { + return Base64.encode(signature.sign()); + } catch (NoSuchAlgorithmException | InvalidKeyException | SignatureException | UnsupportedEncodingException + | RuntimeException e) { throw new OAuthSignatureException(baseString, e); } } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java b/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java index 8cd4f2372..10c50f3ae 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/services/SignatureService.java @@ -1,13 +1,9 @@ package com.github.scribejava.core.services; -import com.github.scribejava.core.java8.Base64; - /** - * Signs a base string, returning the OAuth signature - * https://tools.ietf.org/html/rfc5849#section-3.4 + * Signs a base string, returning the OAuth signature https://tools.ietf.org/html/rfc5849#section-3.4 */ public interface SignatureService { - Base64.Encoder BASE_64_ENCODER = Base64.getEncoder(); /** * Returns the signature diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java index 7dfe361f0..3e0024c6c 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/oauth/OAuth20ServiceTest.java @@ -2,8 +2,8 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.scribejava.core.base64.Base64; import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.core.java8.Base64; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuth2Authorization; import com.github.scribejava.core.model.OAuthConstants; @@ -18,7 +18,6 @@ public class OAuth20ServiceTest { private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - private final Base64.Encoder base64Encoder = Base64.getEncoder(); @Test public void shouldProduceCorrectRequestSync() throws IOException, InterruptedException, ExecutionException { @@ -34,7 +33,7 @@ public void shouldProduceCorrectRequestSync() throws IOException, InterruptedExc assertEquals(OAuth20ServiceUnit.TOKEN, response.get(OAuthConstants.ACCESS_TOKEN).asText()); assertEquals(OAuth20ServiceUnit.EXPIRES, response.get("expires_in").asInt()); - final String authorize = base64Encoder.encodeToString( + final String authorize = Base64.encode( String.format("%s:%s", service.getApiKey(), service.getApiSecret()).getBytes(Charset.forName("UTF-8"))); assertEquals(OAuthConstants.BASIC + ' ' + authorize, response.get(OAuthConstants.HEADER).asText()); @@ -59,7 +58,7 @@ public void shouldProduceCorrectRequestAsync() throws ExecutionException, Interr assertEquals(OAuth20ServiceUnit.TOKEN, response.get(OAuthConstants.ACCESS_TOKEN).asText()); assertEquals(OAuth20ServiceUnit.EXPIRES, response.get("expires_in").asInt()); - final String authorize = base64Encoder.encodeToString( + final String authorize = Base64.encode( String.format("%s:%s", service.getApiKey(), service.getApiSecret()).getBytes(Charset.forName("UTF-8"))); assertEquals(OAuthConstants.BASIC + ' ' + authorize, response.get(OAuthConstants.HEADER).asText()); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/services/RSASha1SignatureServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/services/RSASha1SignatureServiceTest.java index adf93c68f..6808d7cfd 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/services/RSASha1SignatureServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/services/RSASha1SignatureServiceTest.java @@ -1,6 +1,6 @@ package com.github.scribejava.core.services; -import com.github.scribejava.core.java8.Base64; +import com.github.scribejava.core.base64.Base64; import java.security.KeyFactory; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; @@ -53,7 +53,7 @@ private static PrivateKey getPrivateKey() { try { final KeyFactory fac = KeyFactory.getInstance("RSA"); - final PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(Base64.getMimeDecoder().decode(str)); + final PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(Base64.decodeMime(str)); return fac.generatePrivate(privKeySpec); } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { throw new RuntimeException(e); diff --git a/scribejava-java8/pom.xml b/scribejava-java8/pom.xml new file mode 100644 index 000000000..b27d8c98e --- /dev/null +++ b/scribejava-java8/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + + com.github.scribejava + scribejava + 8.1.1-SNAPSHOT + ../pom.xml + + + com.github.scribejava + scribejava-java8 + ScribeJava Java 8+ compatibility stuff + jar + + + + + org.apache.felix + maven-bundle-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + + + + 8 + + diff --git a/scribejava-java8/src/main/java/com/github/scribejava/java8/base64/Java8Base64.java b/scribejava-java8/src/main/java/com/github/scribejava/java8/base64/Java8Base64.java new file mode 100644 index 000000000..d7f1832fb --- /dev/null +++ b/scribejava-java8/src/main/java/com/github/scribejava/java8/base64/Java8Base64.java @@ -0,0 +1,20 @@ +package com.github.scribejava.java8.base64; + +public class Java8Base64 { + + private static final java.util.Base64.Encoder BASE64_ENCODER = java.util.Base64.getEncoder(); + private static final java.util.Base64.Encoder BASE64_URL_ENCODER_WITHOUT_PADDING + = java.util.Base64.getUrlEncoder().withoutPadding(); + + public String internalEncode(byte[] bytes) { + return BASE64_ENCODER.encodeToString(bytes); + } + + public String internalEncodeUrlWithoutPadding(byte[] bytes) { + return BASE64_URL_ENCODER_WITHOUT_PADDING.encodeToString(bytes); + } + + public byte[] internalDecodeMime(String string) { + return java.util.Base64.getMimeDecoder().decode(string); + } +} From cd5e3af9ebe8605a131b5257996971caf716eefe Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Mon, 8 Feb 2021 11:06:44 +0300 Subject: [PATCH 430/481] check for java.util.Base64 presence --- .../java/com/github/scribejava/core/base64/Base64.java | 6 +++++- .../com/github/scribejava/core/base64/Java8Base64.java | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java index 95d15c6b8..6d7f78fed 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java @@ -19,7 +19,11 @@ public static Base64 getInstance() { } private static Base64 createInstance() { - return new Java8Base64(); + if (Java8Base64.isAvailable()) { + return new Java8Base64(); + } + throw new IllegalStateException( + "No Base64 implementation was provided. Java 8 Base64, Apache commons codec or JAXB is needed"); } public static void init(Base64 base64) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/base64/Java8Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Java8Base64.java index 5e92be625..62b8428bc 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/base64/Java8Base64.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Java8Base64.java @@ -20,4 +20,12 @@ protected byte[] internalDecodeMime(String string) { return JAVA8_BASE64.internalDecodeMime(string); } + static boolean isAvailable() { + try { + Class.forName("java.util.Base64", false, Java8Base64.class.getClassLoader()); + return true; + } catch (ClassNotFoundException cnfE) { + return false; + } + } } From 5a0df766f6f6678c274c2251fe6b066d4b76fe10 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 10 Feb 2021 10:00:35 +0300 Subject: [PATCH 431/481] add base64 en/de-coding unit tests --- .../github/scribejava/core/base64/Base64.java | 2 +- .../scribejava/core/base64/Base64Test.java | 87 +++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 scribejava-core/src/test/java/com/github/scribejava/core/base64/Base64Test.java diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java index 6d7f78fed..4cd4cc75b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java @@ -23,7 +23,7 @@ private static Base64 createInstance() { return new Java8Base64(); } throw new IllegalStateException( - "No Base64 implementation was provided. Java 8 Base64, Apache commons codec or JAXB is needed"); + "No Base64 implementation was provided. Java 8 Base64, Apache Commons Codec or JAXB is needed"); } public static void init(Base64 base64) { diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/base64/Base64Test.java b/scribejava-core/src/test/java/com/github/scribejava/core/base64/Base64Test.java new file mode 100644 index 000000000..92e2579bb --- /dev/null +++ b/scribejava-core/src/test/java/com/github/scribejava/core/base64/Base64Test.java @@ -0,0 +1,87 @@ +package com.github.scribejava.core.base64; + +import java.io.UnsupportedEncodingException; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; + +public class Base64Test { + + private Base64 java8Base64; + private byte[] helloWorldBytes; + private byte[] helloWorldTwoLinesBytes; + private byte[] helloWorldTwoLinesAndNewLineBytes; + private byte[] helloWorldDifferentCharsBytes; + + @Before + public void setUp() throws UnsupportedEncodingException { + helloWorldBytes = "Hello World".getBytes("UTF-8"); + helloWorldTwoLinesBytes = "Hello World\r\nNew Line2".getBytes("UTF-8"); + helloWorldTwoLinesAndNewLineBytes = "Hello World\r\nSecond Line\r\n".getBytes("UTF-8"); + helloWorldDifferentCharsBytes = ("`1234567890-=~!@#$%^&*()_+ёЁ\"№;:?qwertyuiop[]asdfghjkl;'zxcvbnm,./QWERTYUIOP" + + "{}|ASDFGHJKL:ZXCVBNM<>?йфяцычувскамепинртгоьшлбщдюзж.хэъ\\ЙФЯЦЫЧУВСКАМЕПИНРТГОЬШЛБЩДЮЗЖ,ХЭЪ/\r\t\f\'" + + "\b\n").getBytes("UTF-8"); + java8Base64 = new Java8Base64(); + } + + @Test + public void allImplementationsAreAvailable() { + assertTrue(Java8Base64.isAvailable()); + } + + @Test + public void testEncode() { + final String helloWorldEncoded = "SGVsbG8gV29ybGQ="; + final String helloWorldTwoLinesEncoded = "SGVsbG8gV29ybGQNCk5ldyBMaW5lMg=="; + final String helloWorldTwoLinesAndNewLineEncoded = "SGVsbG8gV29ybGQNClNlY29uZCBMaW5lDQo="; + final String helloWorldDifferentCharsEncoded = "YDEyMzQ1Njc4OTAtPX4hQCMkJV4mKigpXyvRkdCBIuKEljs6P3F3ZXJ0eXVpb3B" + + "bXWFzZGZnaGprbDsnenhjdmJubSwuL1FXRVJUWVVJT1B7fXxBU0RGR0hKS0w6WlhDVkJOTTw+P9C50YTRj9GG0YvRh9GD0LLRgdC" + + "60LDQvNC10L/QuNC90YDRgtCz0L7RjNGI0LvQsdGJ0LTRjtC30LYu0YXRjdGKXNCZ0KTQr9Cm0KvQp9Cj0JLQodCa0JDQnNCV0J/" + + "QmNCd0KDQotCT0J7QrNCo0JvQkdCp0JTQrtCX0JYs0KXQrdCqLw0JDCcICg=="; + + assertEquals(helloWorldEncoded, java8Base64.internalEncode(helloWorldBytes)); + assertEquals(helloWorldTwoLinesEncoded, java8Base64.internalEncode(helloWorldTwoLinesBytes)); + assertEquals(helloWorldTwoLinesAndNewLineEncoded, + java8Base64.internalEncode(helloWorldTwoLinesAndNewLineBytes)); + assertEquals(helloWorldDifferentCharsEncoded, java8Base64.internalEncode(helloWorldDifferentCharsBytes)); + } + + @Test + public void testEncodeUrlWithoutPadding() { + final String helloWorldEncoded = "SGVsbG8gV29ybGQ"; + final String helloWorldTwoLinesEncoded = "SGVsbG8gV29ybGQNCk5ldyBMaW5lMg"; + final String helloWorldTwoLinesAndNewLineEncoded = "SGVsbG8gV29ybGQNClNlY29uZCBMaW5lDQo"; + final String helloWorldDifferentCharsEncoded = "YDEyMzQ1Njc4OTAtPX4hQCMkJV4mKigpXyvRkdCBIuKEljs6P3F3ZXJ0eXVpb3B" + + "bXWFzZGZnaGprbDsnenhjdmJubSwuL1FXRVJUWVVJT1B7fXxBU0RGR0hKS0w6WlhDVkJOTTw-P9C50YTRj9GG0YvRh9GD0LLRgdC" + + "60LDQvNC10L_QuNC90YDRgtCz0L7RjNGI0LvQsdGJ0LTRjtC30LYu0YXRjdGKXNCZ0KTQr9Cm0KvQp9Cj0JLQodCa0JDQnNCV0J_" + + "QmNCd0KDQotCT0J7QrNCo0JvQkdCp0JTQrtCX0JYs0KXQrdCqLw0JDCcICg"; + + assertEquals(helloWorldEncoded, java8Base64.internalEncodeUrlWithoutPadding(helloWorldBytes)); + assertEquals(helloWorldTwoLinesEncoded, java8Base64.internalEncodeUrlWithoutPadding(helloWorldTwoLinesBytes)); + assertEquals(helloWorldTwoLinesAndNewLineEncoded, + java8Base64.internalEncodeUrlWithoutPadding(helloWorldTwoLinesAndNewLineBytes)); + assertEquals(helloWorldDifferentCharsEncoded, + java8Base64.internalEncodeUrlWithoutPadding(helloWorldDifferentCharsBytes)); + } + + @Test + public void testDecodeMime() { + final String helloWorldEncoded = "SGVsbG8gV29ybGQ="; + final String helloWorldTwoLinesEncoded = "SGVsbG8gV29ybGQNCk5ldyBMaW5lMg=="; + final String helloWorldTwoLinesAndNewLineEncoded = "SGVsbG8gV29ybGQNClNlY29uZCBMaW5lDQo="; + final String helloWorldDifferentCharsEncoded = "YDEyMzQ1Njc4OTAtPX4hQCMkJV4mKigpXyvRkdCBIuKEljs6P3F3ZXJ0eXVpb3B" + + "bXWFzZGZnaGprbDsnenhjdmJubSwuL1FXRVJUWVVJT1B7fXxBU0RGR0hKS0w6WlhDVkJOTTw+P9C50YTRj9GG0YvRh9GD0LLRgdC" + + "60LDQvNC10L/QuNC90YDRgtCz0L7RjNGI0LvQsdGJ0LTRjtC30LYu0YXRjdGKXNCZ0KTQr9Cm0KvQp9Cj0JLQodCa0JDQnNCV0J/" + + "QmNCd0KDQotCT0J7QrNCo0JvQkdCp0JTQrtCX0JYs0KXQrdCqLw0JDCcICg=="; + + assertArrayEquals(helloWorldBytes, java8Base64.internalDecodeMime(helloWorldEncoded)); + assertArrayEquals(helloWorldTwoLinesBytes, java8Base64.internalDecodeMime(helloWorldTwoLinesEncoded)); + assertArrayEquals(helloWorldTwoLinesAndNewLineBytes, + java8Base64.internalDecodeMime(helloWorldTwoLinesAndNewLineEncoded)); + assertArrayEquals(helloWorldDifferentCharsBytes, + java8Base64.internalDecodeMime(helloWorldDifferentCharsEncoded)); + } + +} From fe3e14a58f2a98f03756ec2f23bc104544afab6d Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 10 Feb 2021 10:16:32 +0300 Subject: [PATCH 432/481] switch to assertThrows from @Test(expected = ...) in unit tests --- .../extractors/BaseStringExtractorTest.java | 18 +++++++--- .../core/extractors/HeaderExtractorTest.java | 28 ++++++++++----- .../OAuth1AccessTokenExtractorTest.java | 34 +++++++++++++----- .../OAuth2AccessTokenExtractorTest.java | 34 +++++++++++++----- .../OAuth2AccessTokenJsonExtractorTest.java | 16 ++++++--- .../core/model/OAuthRequestTest.java | 10 ++++-- .../core/model/ParameterListTest.java | 10 ++++-- .../HMACSha1SignatureServiceTest.java | 26 ++++++++++---- .../core/utils/OAuthEncoderTest.java | 18 +++++++--- .../core/utils/PreconditionsTest.java | 35 ++++++++++++++----- .../core/utils/StreamUtilsTest.java | 23 +++++++----- 11 files changed, 188 insertions(+), 64 deletions(-) diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/BaseStringExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/BaseStringExtractorTest.java index bc833db08..89865a637 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/BaseStringExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/BaseStringExtractorTest.java @@ -7,6 +7,8 @@ import com.github.scribejava.core.exceptions.OAuthParametersMissingException; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Verb; +import static org.junit.Assert.assertThrows; +import org.junit.function.ThrowingRunnable; public class BaseStringExtractorTest { @@ -83,15 +85,23 @@ public void shouldExcludePort443v2() { assertEquals(expected, baseString); } - @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfRquestIsNull() { - extractor.extract(null); + assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + extractor.extract(null); + } + }); } - @Test(expected = OAuthParametersMissingException.class) public void shouldThrowExceptionIfRquestHasNoOAuthParameters() { final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com"); - extractor.extract(request); + assertThrows(OAuthParametersMissingException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + extractor.extract(request); + } + }); } @Test diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/HeaderExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/HeaderExtractorTest.java index c1658fc7e..b515908c8 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/HeaderExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/HeaderExtractorTest.java @@ -2,12 +2,14 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertThrows; import org.junit.Before; import org.junit.Test; import com.github.scribejava.core.exceptions.OAuthParametersMissingException; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.ObjectMother; +import org.junit.function.ThrowingRunnable; public class HeaderExtractorTest { @@ -36,21 +38,29 @@ public void shouldExtractStandardHeader() { assertTrue(header.contains(timestamp)); // Assert that header only contains the checked elements above and nothing else assertEquals(", , , ", - header.replaceFirst(oauth, "") - .replaceFirst(callback, "") - .replaceFirst(signature, "") - .replaceFirst(key, "") - .replaceFirst(timestamp, "")); + header.replaceFirst(oauth, "") + .replaceFirst(callback, "") + .replaceFirst(signature, "") + .replaceFirst(key, "") + .replaceFirst(timestamp, "")); } - @Test(expected = IllegalArgumentException.class) public void shouldExceptionIfRequestIsNull() { - extractor.extract(null); + assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + extractor.extract(null); + } + }); } - @Test(expected = OAuthParametersMissingException.class) public void shouldExceptionIfRequestHasNoOAuthParams() { final OAuthRequest emptyRequest = new OAuthRequest(Verb.GET, "http://example.com"); - extractor.extract(emptyRequest); + assertThrows(OAuthParametersMissingException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + extractor.extract(emptyRequest); + } + }); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth1AccessTokenExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth1AccessTokenExtractorTest.java index 58ed0e93d..b62d9bf1e 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth1AccessTokenExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth1AccessTokenExtractorTest.java @@ -10,6 +10,8 @@ import java.util.Collections; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; +import org.junit.function.ThrowingRunnable; public class OAuth1AccessTokenExtractorTest { @@ -65,34 +67,50 @@ public void shouldExtractTokenWithEmptySecret() throws IOException { assertEquals("", extracted.getTokenSecret()); } - @Test(expected = OAuthException.class) public void shouldThrowExceptionIfTokenIsAbsent() throws IOException { final String responseBody = "oauth_secret=hh5s93j4hdidpola&callback_confirmed=true"; try (Response response = ok(responseBody)) { - extractor.extract(response); + assertThrows(OAuthException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + extractor.extract(response); + } + }); } } - @Test(expected = OAuthException.class) public void shouldThrowExceptionIfSecretIsAbsent() throws IOException { final String responseBody = "oauth_token=hh5s93j4hdidpola&callback_confirmed=true"; try (Response response = ok(responseBody)) { - extractor.extract(response); + assertThrows(OAuthException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + extractor.extract(response); + } + }); } } - @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfResponseIsNull() throws IOException { try (Response response = ok(null)) { - extractor.extract(response); + assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + extractor.extract(response); + } + }); } } - @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfResponseIsEmptyString() throws IOException { final String responseBody = ""; try (Response response = ok(responseBody)) { - extractor.extract(response); + assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + extractor.extract(response); + } + }); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java index 28d9a569b..4f71c011d 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java @@ -10,6 +10,8 @@ import java.util.Collections; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; +import org.junit.function.ThrowingRunnable; public class OAuth2AccessTokenExtractorTest { @@ -70,34 +72,50 @@ public void shouldExtractTokenFromResponseWithManyParameters() throws IOExceptio assertEquals("foo1234", extracted.getAccessToken()); } - @Test(expected = OAuthException.class) public void shouldThrowExceptionIfErrorResponse() throws IOException { final String responseBody = ""; try (Response response = error(responseBody)) { - extractor.extract(response); + assertThrows(OAuthException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + extractor.extract(response); + } + }); } } - @Test(expected = OAuthException.class) public void shouldThrowExceptionIfTokenIsAbsent() throws IOException { final String responseBody = "&expires=5108"; try (Response response = ok(responseBody)) { - extractor.extract(response); + assertThrows(OAuthException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + extractor.extract(response); + } + }); } } - @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfResponseIsNull() throws IOException { try (Response response = ok(null)) { - extractor.extract(response); + assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + extractor.extract(response); + } + }); } } - @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfResponseIsEmptyString() throws IOException { final String responseBody = ""; try (Response response = ok(responseBody)) { - extractor.extract(response); + assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + extractor.extract(response); + } + }); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java index 66d5a4a72..6628d1d9b 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java @@ -63,18 +63,26 @@ public void shouldParseScopeFromResponse() throws IOException { assertEquals("refresh_token1", token3.getRefreshToken()); } - @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfForNullParameters() throws IOException { try (Response response = ok(null)) { - extractor.extract(response); + assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + extractor.extract(response); + } + }); } } - @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfForEmptyStrings() throws IOException { final String responseBody = ""; try (Response response = ok(responseBody)) { - extractor.extract(response); + assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + extractor.extract(response); + } + }); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/OAuthRequestTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/OAuthRequestTest.java index 03688ce16..32d5d6731 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/OAuthRequestTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/OAuthRequestTest.java @@ -1,9 +1,11 @@ package com.github.scribejava.core.model; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; +import org.junit.function.ThrowingRunnable; public class OAuthRequestTest { @@ -25,9 +27,13 @@ public void shouldAddOAuthParamters() { assertEquals(5, request.getOauthParameters().size()); } - @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfParameterIsNotOAuth() { - request.addOAuthParameter("otherParam", "value"); + assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + request.addOAuthParameter("otherParam", "value"); + } + }); } @Test diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/model/ParameterListTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/model/ParameterListTest.java index 78a22c9f9..702c66395 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/model/ParameterListTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/model/ParameterListTest.java @@ -5,6 +5,8 @@ import org.junit.Test; import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertThrows; +import org.junit.function.ThrowingRunnable; public class ParameterListTest { @@ -15,9 +17,13 @@ public void setUp() { this.params = new ParameterList(); } - @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenAppendingNullMapToQuerystring() { - params.appendTo(null); + assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + params.appendTo(null); + } + }); } @Test diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/services/HMACSha1SignatureServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/services/HMACSha1SignatureServiceTest.java index f690cae1d..d824d2112 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/services/HMACSha1SignatureServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/services/HMACSha1SignatureServiceTest.java @@ -4,6 +4,8 @@ import org.junit.Before; import org.junit.Test; import com.github.scribejava.core.exceptions.OAuthException; +import static org.junit.Assert.assertThrows; +import org.junit.function.ThrowingRunnable; public class HMACSha1SignatureServiceTest { @@ -29,19 +31,31 @@ public void shouldReturnSignature() { assertEquals(signature, service.getSignature(baseString, apiSecret, tokenSecret)); } - @Test(expected = OAuthException.class) public void shouldThrowExceptionIfBaseStringIsNull() { - service.getSignature(null, "apiSecret", "tokenSecret"); + assertThrows(OAuthException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + service.getSignature(null, "apiSecret", "tokenSecret"); + } + }); } - @Test(expected = OAuthException.class) public void shouldThrowExceptionIfBaseStringIsEmpty() { - service.getSignature(" ", "apiSecret", "tokenSecret"); + assertThrows(OAuthException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + service.getSignature(" ", "apiSecret", "tokenSecret"); + } + }); } - @Test(expected = OAuthException.class) public void shouldThrowExceptionIfApiSecretIsNull() { - service.getSignature("base string", null, "tokenSecret"); + assertThrows(OAuthException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + service.getSignature("base string", null, "tokenSecret"); + } + }); } public void shouldNotThrowExceptionIfApiSecretIsEmpty() { diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/utils/OAuthEncoderTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/utils/OAuthEncoderTest.java index 1a1489b41..9a27d238d 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/utils/OAuthEncoderTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/utils/OAuthEncoderTest.java @@ -1,7 +1,9 @@ package com.github.scribejava.core.utils; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; import org.junit.Test; +import org.junit.function.ThrowingRunnable; public class OAuthEncoderTest { @@ -34,14 +36,22 @@ public void shouldNotPercentEncodeReservedCharacters() { assertEquals(encoded, OAuthEncoder.encode(plain)); } - @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfStringToEncodeIsNull() { - OAuthEncoder.encode(null); + assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + OAuthEncoder.encode(null); + } + }); } - @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfStringToDecodeIsNull() { - OAuthEncoder.decode(null); + assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + OAuthEncoder.decode(null); + } + }); } @Test diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/utils/PreconditionsTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/utils/PreconditionsTest.java index ec6722c5a..1e3bd71e2 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/utils/PreconditionsTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/utils/PreconditionsTest.java @@ -1,28 +1,45 @@ package com.github.scribejava.core.utils; -import org.junit.Test; +import static org.junit.Assert.assertThrows; +import org.junit.function.ThrowingRunnable; public class PreconditionsTest { private static final String ERROR_MSG = ""; - @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionForNullObjects() { - Preconditions.checkNotNull(null, ERROR_MSG); + assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + Preconditions.checkNotNull(null, ERROR_MSG); + } + }); } - @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionForNullStrings() { - Preconditions.checkEmptyString(null, ERROR_MSG); + assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + Preconditions.checkEmptyString(null, ERROR_MSG); + } + }); } - @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionForEmptyStrings() { - Preconditions.checkEmptyString("", ERROR_MSG); + assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + Preconditions.checkEmptyString("", ERROR_MSG); + } + }); } - @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionForSpacesOnlyStrings() { - Preconditions.checkEmptyString(" ", ERROR_MSG); + assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + Preconditions.checkEmptyString(" ", ERROR_MSG); + } + }); } } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/utils/StreamUtilsTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/utils/StreamUtilsTest.java index cb5c6c7c9..61937bac6 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/utils/StreamUtilsTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/utils/StreamUtilsTest.java @@ -4,8 +4,9 @@ import java.io.IOException; import java.io.InputStream; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import org.junit.Test; +import org.junit.function.ThrowingRunnable; public class StreamUtilsTest { @@ -27,16 +28,22 @@ public void shouldCorrectlyDecodeAStream() throws IOException { assertEquals("expected", decoded); } - @Test(expected = IllegalArgumentException.class) public void shouldFailForNullParameter() throws IOException { - StreamUtils.getStreamContents(null); - fail("Must throw exception before getting here"); + assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + StreamUtils.getStreamContents(null); + } + }); } - @Test(expected = IOException.class) public void shouldFailWithBrokenStream() throws IOException { - // This object simulates problems with input stream. - StreamUtils.getStreamContents(ALLWAYS_ERROR_INPUT_STREAM); - fail("Must throw exception before getting here"); + assertThrows(IOException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + // This object simulates problems with input stream. + StreamUtils.getStreamContents(ALLWAYS_ERROR_INPUT_STREAM); + } + }); } } From 12297f702d5e511704f5c069578dc83691c56197 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 10 Feb 2021 11:13:58 +0300 Subject: [PATCH 433/481] add Apache Commons Codec Base64 provider as alternative to java 8+ (and remove decoding from main code, it was used only in unit tests) --- .../github/scribejava/apis/MediaWikiApi.java | 2 +- scribejava-core/pom.xml | 6 ++ .../github/scribejava/core/base64/Base64.java | 9 +- .../core/base64/CommonsCodecBase64.java | 28 ++++++ .../scribejava/core/base64/Java8Base64.java | 5 - .../scribejava/core/base64/Base64Test.java | 97 +++++++++++++++---- .../services/RSASha1SignatureServiceTest.java | 4 +- .../scribejava/java8/base64/Java8Base64.java | 3 - 8 files changed, 118 insertions(+), 36 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/base64/CommonsCodecBase64.java diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java index d3c078f9b..3bb18001d 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/MediaWikiApi.java @@ -36,7 +36,7 @@ public MediaWikiApi(String indexUrl, String niceUrlBase) { } /** - * The instance for wikis hosted by the Wikimedia Foundation.Consumers are requested on + * The instance for wikis hosted by the Wikimedia Foundation. Consumers are requested on * * Special:OAuthConsumerRegistration/propose * . diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 47315ff9d..570bccc02 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -20,6 +20,12 @@ scribejava-java8 ${project.version} + + commons-codec + commons-codec + 1.15 + true + diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java index 4cd4cc75b..06fc0e155 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java @@ -22,6 +22,9 @@ private static Base64 createInstance() { if (Java8Base64.isAvailable()) { return new Java8Base64(); } + if (CommonsCodecBase64.isAvailable()) { + return new CommonsCodecBase64(); + } throw new IllegalStateException( "No Base64 implementation was provided. Java 8 Base64, Apache Commons Codec or JAXB is needed"); } @@ -40,13 +43,7 @@ public static String encodeUrlWithoutPadding(byte[] bytes) { return getInstance().internalEncodeUrlWithoutPadding(bytes); } - public static byte[] decodeMime(String string) { - return getInstance().internalDecodeMime(string); - } - protected abstract String internalEncode(byte[] bytes); protected abstract String internalEncodeUrlWithoutPadding(byte[] bytes); - - protected abstract byte[] internalDecodeMime(String string); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/base64/CommonsCodecBase64.java b/scribejava-core/src/main/java/com/github/scribejava/core/base64/CommonsCodecBase64.java new file mode 100644 index 000000000..196a6c4f0 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/base64/CommonsCodecBase64.java @@ -0,0 +1,28 @@ +package com.github.scribejava.core.base64; + +public class CommonsCodecBase64 extends Base64 { + + private static final org.apache.commons.codec.binary.Base64 BASE64_ENCODER + = new org.apache.commons.codec.binary.Base64(); + private static final org.apache.commons.codec.binary.Base64 BASE64_URL_ENCODER_WITHOUT_PADDING + = new org.apache.commons.codec.binary.Base64(0, null, true); + + @Override + protected String internalEncode(byte[] bytes) { + return BASE64_ENCODER.encodeToString(bytes); + } + + @Override + protected String internalEncodeUrlWithoutPadding(byte[] bytes) { + return BASE64_URL_ENCODER_WITHOUT_PADDING.encodeToString(bytes); + } + + static boolean isAvailable() { + try { + Class.forName("org.apache.commons.codec.binary.Base64", false, CommonsCodecBase64.class.getClassLoader()); + return true; + } catch (ClassNotFoundException cnfE) { + return false; + } + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/base64/Java8Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Java8Base64.java index 62b8428bc..a5cea8755 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/base64/Java8Base64.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Java8Base64.java @@ -15,11 +15,6 @@ protected String internalEncodeUrlWithoutPadding(byte[] bytes) { return JAVA8_BASE64.internalEncodeUrlWithoutPadding(bytes); } - @Override - protected byte[] internalDecodeMime(String string) { - return JAVA8_BASE64.internalDecodeMime(string); - } - static boolean isAvailable() { try { Class.forName("java.util.Base64", false, Java8Base64.class.getClassLoader()); diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/base64/Base64Test.java b/scribejava-core/src/test/java/com/github/scribejava/core/base64/Base64Test.java index 92e2579bb..4a6dd4102 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/base64/Base64Test.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/base64/Base64Test.java @@ -5,15 +5,16 @@ import org.junit.Test; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertArrayEquals; public class Base64Test { private Base64 java8Base64; + private Base64 commonsCodecBase64; private byte[] helloWorldBytes; private byte[] helloWorldTwoLinesBytes; private byte[] helloWorldTwoLinesAndNewLineBytes; private byte[] helloWorldDifferentCharsBytes; + private byte[] bytes; @Before public void setUp() throws UnsupportedEncodingException { @@ -23,12 +24,43 @@ public void setUp() throws UnsupportedEncodingException { helloWorldDifferentCharsBytes = ("`1234567890-=~!@#$%^&*()_+ёЁ\"№;:?qwertyuiop[]asdfghjkl;'zxcvbnm,./QWERTYUIOP" + "{}|ASDFGHJKL:ZXCVBNM<>?йфяцычувскамепинртгоьшлбщдюзж.хэъ\\ЙФЯЦЫЧУВСКАМЕПИНРТГОЬШЛБЩДЮЗЖ,ХЭЪ/\r\t\f\'" + "\b\n").getBytes("UTF-8"); + bytes = new byte[]{48, -126, 2, 118, 2, 1, 0, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 1, 5, 0, 4, -126, + 2, 96, 48, -126, 2, 92, 2, 1, 0, 2, -127, -127, 0, -61, -48, -28, 16, -116, -58, 85, 42, -39, 54, 50, -119, + 18, 40, 17, 75, 51, -24, 113, -109, 38, 17, -18, 106, -60, -74, -97, 29, 82, 123, -128, -88, -34, 92, 112, + -57, 43, -101, 85, -47, 99, -16, 11, -95, 28, -46, 82, -104, -101, -29, -106, -106, -45, -80, 99, -93, 45, + -102, 107, 31, 32, -60, 13, -46, 102, 127, 81, 94, -98, -56, 117, 50, 21, 39, 5, -98, 26, -18, -30, -21, + 102, -78, -77, 20, 113, -55, 117, -87, -105, -10, -100, 90, -92, 31, 61, -68, -73, -121, -108, 42, 45, -10, + 21, 87, 118, -74, 71, -100, -37, 96, -24, 87, 102, 68, -95, -1, -14, 6, -20, -14, 32, -14, 33, -84, -123, + -65, 54, 3, 2, 3, 1, 0, 1, 2, -127, -128, 62, 115, -45, 41, 76, 28, -67, 113, 11, 17, -12, 16, 47, -112, 67, + -29, -66, 76, 118, 92, -66, 25, -99, -10, -61, -126, -109, 64, -32, -37, -82, -17, 44, -20, 66, -77, -29, + 62, -119, -94, 92, -61, 100, -110, 32, 5, 28, 126, -69, -55, 92, 112, 2, 88, 17, -113, 43, -82, 66, 88, 13, + 53, 58, 74, -65, 36, 45, 93, -63, -15, 125, -7, -44, -45, -51, -76, 86, 97, 54, -36, -49, -117, -18, 56, 54, + 78, 80, 119, -6, -75, 39, 16, 57, -125, -68, 42, 50, -114, 92, 6, 13, 30, -91, 53, -66, -19, -20, 88, 32, + -38, 36, 126, -119, -86, 47, -46, 37, 115, -49, -23, 125, -61, 75, 37, 70, 92, -122, -79, 2, 65, 0, -11, + -105, 91, 105, -73, 54, 97, 96, -87, -16, -15, -73, 15, 31, -80, -96, -74, -53, -54, 53, -17, -9, 39, 62, + 58, 51, 68, 107, 86, 111, -62, -48, -125, 117, 66, 111, -55, 27, 56, 81, -50, 96, -47, -102, -50, -83, -52, + -17, -20, 3, -42, -94, 11, 23, 104, 127, 29, -25, 32, 43, -41, -112, -83, -99, 2, 65, 0, -52, 29, 122, 9, + 49, -14, -118, 110, -79, 107, 76, -88, 4, -49, 40, 32, 59, 88, 45, -71, 62, 78, 93, -121, -123, 123, 3, 4, + 111, -112, 27, 12, -115, -123, 125, 39, 54, 96, -2, -46, 30, 40, -4, -119, 13, -121, 118, -23, 1, -83, -76, + -26, -117, -86, -79, -121, 113, -26, 33, 30, 124, 35, -16, 31, 2, 65, 0, -47, -113, 111, -81, 75, 104, -103, + -69, 20, 7, -57, 25, -65, 75, -7, 57, -118, 1, 102, -16, -109, 108, -64, 13, -73, 55, -37, -32, 3, -121, + -90, 34, -86, -87, -70, 33, 12, -25, -81, 45, 14, -1, 74, -101, -32, 84, 41, -107, 104, 60, -10, 62, -101, + 92, 68, 12, -124, 5, -98, 76, 10, -53, 39, 121, 2, 64, 7, 106, 102, -67, -96, -57, -20, 9, -101, 126, -121, + 121, 111, 59, 75, 124, -24, 75, 10, -42, 57, 18, 69, -55, -97, -86, -39, 112, 54, -47, 104, 122, 43, 70, 23, + 70, -18, 109, -43, -76, 50, -114, 80, -90, 118, 12, 94, -32, -106, 68, 6, 87, 125, -23, -124, -85, -92, 18, + -75, 79, 83, 57, 71, 7, 2, 64, 73, -64, -3, 78, -90, -122, -64, -99, -29, -71, 75, 21, -74, -24, -43, -37, + 116, -89, 31, -115, -30, 50, 8, 23, 79, -71, -68, -39, 36, -23, 60, 102, -90, -42, 19, -33, -102, -85, -74, + 103, 73, -30, 120, -15, 104, -9, 110, -24, -127, 14, -57, -44, 67, 9, 80, 120, 42, 94, 107, -81, -109, 101, + -1, 91}; + java8Base64 = new Java8Base64(); + commonsCodecBase64 = new CommonsCodecBase64(); } @Test public void allImplementationsAreAvailable() { assertTrue(Java8Base64.isAvailable()); + assertTrue(CommonsCodecBase64.isAvailable()); } @Test @@ -40,12 +72,34 @@ public void testEncode() { + "bXWFzZGZnaGprbDsnenhjdmJubSwuL1FXRVJUWVVJT1B7fXxBU0RGR0hKS0w6WlhDVkJOTTw+P9C50YTRj9GG0YvRh9GD0LLRgdC" + "60LDQvNC10L/QuNC90YDRgtCz0L7RjNGI0LvQsdGJ0LTRjtC30LYu0YXRjdGKXNCZ0KTQr9Cm0KvQp9Cj0JLQodCa0JDQnNCV0J/" + "QmNCd0KDQotCT0J7QrNCo0JvQkdCp0JTQrtCX0JYs0KXQrdCqLw0JDCcICg=="; + final String str = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMPQ5BCMxlUq2TYy" + + "iRIoEUsz6HGTJhHuasS2nx1Se4Co3lxwxyubVdFj8AuhHNJSmJvjlpbTsGOjLZpr" + + "HyDEDdJmf1Fensh1MhUnBZ4a7uLrZrKzFHHJdamX9pxapB89vLeHlCot9hVXdrZH" + + "nNtg6FdmRKH/8gbs8iDyIayFvzYDAgMBAAECgYA+c9MpTBy9cQsR9BAvkEPjvkx2" + + "XL4ZnfbDgpNA4Nuu7yzsQrPjPomiXMNkkiAFHH67yVxwAlgRjyuuQlgNNTpKvyQt" + + "XcHxffnU0820VmE23M+L7jg2TlB3+rUnEDmDvCoyjlwGDR6lNb7t7Fgg2iR+iaov" + + "0iVzz+l9w0slRlyGsQJBAPWXW2m3NmFgqfDxtw8fsKC2y8o17/cnPjozRGtWb8LQ" + + "g3VCb8kbOFHOYNGazq3M7+wD1qILF2h/HecgK9eQrZ0CQQDMHXoJMfKKbrFrTKgE" + + "zyggO1gtuT5OXYeFewMEb5AbDI2FfSc2YP7SHij8iQ2HdukBrbTmi6qxh3HmIR58" + + "I/AfAkEA0Y9vr0tombsUB8cZv0v5OYoBZvCTbMANtzfb4AOHpiKqqbohDOevLQ7/" + + "SpvgVCmVaDz2PptcRAyEBZ5MCssneQJAB2pmvaDH7Ambfod5bztLfOhLCtY5EkXJ" + + "n6rZcDbRaHorRhdG7m3VtDKOUKZ2DF7glkQGV33phKukErVPUzlHBwJAScD9TqaG" + + "wJ3juUsVtujV23SnH43iMggXT7m82STpPGam1hPfmqu2Z0niePFo927ogQ7H1EMJ" + + "UHgqXmuvk2X/Ww=="; assertEquals(helloWorldEncoded, java8Base64.internalEncode(helloWorldBytes)); assertEquals(helloWorldTwoLinesEncoded, java8Base64.internalEncode(helloWorldTwoLinesBytes)); assertEquals(helloWorldTwoLinesAndNewLineEncoded, java8Base64.internalEncode(helloWorldTwoLinesAndNewLineBytes)); assertEquals(helloWorldDifferentCharsEncoded, java8Base64.internalEncode(helloWorldDifferentCharsBytes)); + assertEquals(str, java8Base64.internalEncode(bytes)); + + assertEquals(helloWorldEncoded, commonsCodecBase64.internalEncode(helloWorldBytes)); + assertEquals(helloWorldTwoLinesEncoded, commonsCodecBase64.internalEncode(helloWorldTwoLinesBytes)); + assertEquals(helloWorldTwoLinesAndNewLineEncoded, + commonsCodecBase64.internalEncode(helloWorldTwoLinesAndNewLineBytes)); + assertEquals(helloWorldDifferentCharsEncoded, commonsCodecBase64.internalEncode(helloWorldDifferentCharsBytes)); + assertEquals(str, commonsCodecBase64.internalEncode(bytes)); } @Test @@ -57,6 +111,20 @@ public void testEncodeUrlWithoutPadding() { + "bXWFzZGZnaGprbDsnenhjdmJubSwuL1FXRVJUWVVJT1B7fXxBU0RGR0hKS0w6WlhDVkJOTTw-P9C50YTRj9GG0YvRh9GD0LLRgdC" + "60LDQvNC10L_QuNC90YDRgtCz0L7RjNGI0LvQsdGJ0LTRjtC30LYu0YXRjdGKXNCZ0KTQr9Cm0KvQp9Cj0JLQodCa0JDQnNCV0J_" + "QmNCd0KDQotCT0J7QrNCo0JvQkdCp0JTQrtCX0JYs0KXQrdCqLw0JDCcICg"; + final String str = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMPQ5BCMxlUq2TYy" + + "iRIoEUsz6HGTJhHuasS2nx1Se4Co3lxwxyubVdFj8AuhHNJSmJvjlpbTsGOjLZpr" + + "HyDEDdJmf1Fensh1MhUnBZ4a7uLrZrKzFHHJdamX9pxapB89vLeHlCot9hVXdrZH" + + "nNtg6FdmRKH_8gbs8iDyIayFvzYDAgMBAAECgYA-c9MpTBy9cQsR9BAvkEPjvkx2" + + "XL4ZnfbDgpNA4Nuu7yzsQrPjPomiXMNkkiAFHH67yVxwAlgRjyuuQlgNNTpKvyQt" + + "XcHxffnU0820VmE23M-L7jg2TlB3-rUnEDmDvCoyjlwGDR6lNb7t7Fgg2iR-iaov" + + "0iVzz-l9w0slRlyGsQJBAPWXW2m3NmFgqfDxtw8fsKC2y8o17_cnPjozRGtWb8LQ" + + "g3VCb8kbOFHOYNGazq3M7-wD1qILF2h_HecgK9eQrZ0CQQDMHXoJMfKKbrFrTKgE" + + "zyggO1gtuT5OXYeFewMEb5AbDI2FfSc2YP7SHij8iQ2HdukBrbTmi6qxh3HmIR58" + + "I_AfAkEA0Y9vr0tombsUB8cZv0v5OYoBZvCTbMANtzfb4AOHpiKqqbohDOevLQ7_" + + "SpvgVCmVaDz2PptcRAyEBZ5MCssneQJAB2pmvaDH7Ambfod5bztLfOhLCtY5EkXJ" + + "n6rZcDbRaHorRhdG7m3VtDKOUKZ2DF7glkQGV33phKukErVPUzlHBwJAScD9TqaG" + + "wJ3juUsVtujV23SnH43iMggXT7m82STpPGam1hPfmqu2Z0niePFo927ogQ7H1EMJ" + + "UHgqXmuvk2X_Ww"; assertEquals(helloWorldEncoded, java8Base64.internalEncodeUrlWithoutPadding(helloWorldBytes)); assertEquals(helloWorldTwoLinesEncoded, java8Base64.internalEncodeUrlWithoutPadding(helloWorldTwoLinesBytes)); @@ -64,24 +132,15 @@ public void testEncodeUrlWithoutPadding() { java8Base64.internalEncodeUrlWithoutPadding(helloWorldTwoLinesAndNewLineBytes)); assertEquals(helloWorldDifferentCharsEncoded, java8Base64.internalEncodeUrlWithoutPadding(helloWorldDifferentCharsBytes)); - } - - @Test - public void testDecodeMime() { - final String helloWorldEncoded = "SGVsbG8gV29ybGQ="; - final String helloWorldTwoLinesEncoded = "SGVsbG8gV29ybGQNCk5ldyBMaW5lMg=="; - final String helloWorldTwoLinesAndNewLineEncoded = "SGVsbG8gV29ybGQNClNlY29uZCBMaW5lDQo="; - final String helloWorldDifferentCharsEncoded = "YDEyMzQ1Njc4OTAtPX4hQCMkJV4mKigpXyvRkdCBIuKEljs6P3F3ZXJ0eXVpb3B" - + "bXWFzZGZnaGprbDsnenhjdmJubSwuL1FXRVJUWVVJT1B7fXxBU0RGR0hKS0w6WlhDVkJOTTw+P9C50YTRj9GG0YvRh9GD0LLRgdC" - + "60LDQvNC10L/QuNC90YDRgtCz0L7RjNGI0LvQsdGJ0LTRjtC30LYu0YXRjdGKXNCZ0KTQr9Cm0KvQp9Cj0JLQodCa0JDQnNCV0J/" - + "QmNCd0KDQotCT0J7QrNCo0JvQkdCp0JTQrtCX0JYs0KXQrdCqLw0JDCcICg=="; + assertEquals(str, java8Base64.internalEncodeUrlWithoutPadding(bytes)); - assertArrayEquals(helloWorldBytes, java8Base64.internalDecodeMime(helloWorldEncoded)); - assertArrayEquals(helloWorldTwoLinesBytes, java8Base64.internalDecodeMime(helloWorldTwoLinesEncoded)); - assertArrayEquals(helloWorldTwoLinesAndNewLineBytes, - java8Base64.internalDecodeMime(helloWorldTwoLinesAndNewLineEncoded)); - assertArrayEquals(helloWorldDifferentCharsBytes, - java8Base64.internalDecodeMime(helloWorldDifferentCharsEncoded)); + assertEquals(helloWorldEncoded, commonsCodecBase64.internalEncodeUrlWithoutPadding(helloWorldBytes)); + assertEquals(helloWorldTwoLinesEncoded, + commonsCodecBase64.internalEncodeUrlWithoutPadding(helloWorldTwoLinesBytes)); + assertEquals(helloWorldTwoLinesAndNewLineEncoded, + commonsCodecBase64.internalEncodeUrlWithoutPadding(helloWorldTwoLinesAndNewLineBytes)); + assertEquals(helloWorldDifferentCharsEncoded, + commonsCodecBase64.internalEncodeUrlWithoutPadding(helloWorldDifferentCharsBytes)); + assertEquals(str, commonsCodecBase64.internalEncodeUrlWithoutPadding(bytes)); } - } diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/services/RSASha1SignatureServiceTest.java b/scribejava-core/src/test/java/com/github/scribejava/core/services/RSASha1SignatureServiceTest.java index 6808d7cfd..652f328e3 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/services/RSASha1SignatureServiceTest.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/services/RSASha1SignatureServiceTest.java @@ -1,11 +1,11 @@ package com.github.scribejava.core.services; -import com.github.scribejava.core.base64.Base64; import java.security.KeyFactory; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.spec.InvalidKeySpecException; import java.security.spec.PKCS8EncodedKeySpec; +import org.apache.commons.codec.binary.Base64; import static org.junit.Assert.assertEquals; import org.junit.Test; @@ -53,7 +53,7 @@ private static PrivateKey getPrivateKey() { try { final KeyFactory fac = KeyFactory.getInstance("RSA"); - final PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(Base64.decodeMime(str)); + final PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(Base64.decodeBase64(str)); return fac.generatePrivate(privKeySpec); } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { throw new RuntimeException(e); diff --git a/scribejava-java8/src/main/java/com/github/scribejava/java8/base64/Java8Base64.java b/scribejava-java8/src/main/java/com/github/scribejava/java8/base64/Java8Base64.java index d7f1832fb..eb391dcad 100644 --- a/scribejava-java8/src/main/java/com/github/scribejava/java8/base64/Java8Base64.java +++ b/scribejava-java8/src/main/java/com/github/scribejava/java8/base64/Java8Base64.java @@ -14,7 +14,4 @@ public String internalEncodeUrlWithoutPadding(byte[] bytes) { return BASE64_URL_ENCODER_WITHOUT_PADDING.encodeToString(bytes); } - public byte[] internalDecodeMime(String string) { - return java.util.Base64.getMimeDecoder().decode(string); - } } From 36c1c71c789e1d9336c683b688376e380ca61858 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Mon, 15 Feb 2021 11:03:24 +0300 Subject: [PATCH 434/481] add JAXB 3.0.0 implementation for Base64 encoding --- scribejava-core/pom.xml | 6 ++++ .../github/scribejava/core/base64/Base64.java | 3 ++ .../scribejava/core/base64/JaxbBase64.java | 29 +++++++++++++++++++ .../scribejava/core/base64/Base64Test.java | 17 +++++++++++ 4 files changed, 55 insertions(+) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/base64/JaxbBase64.java diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 570bccc02..a1d3db645 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -26,6 +26,12 @@ 1.15 true + + jakarta.xml.bind + jakarta.xml.bind-api + 3.0.0 + true + diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java index 06fc0e155..6e89741a2 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java @@ -25,6 +25,9 @@ private static Base64 createInstance() { if (CommonsCodecBase64.isAvailable()) { return new CommonsCodecBase64(); } + if (JaxbBase64.isAvailable()) { + return new JaxbBase64(); + } throw new IllegalStateException( "No Base64 implementation was provided. Java 8 Base64, Apache Commons Codec or JAXB is needed"); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/base64/JaxbBase64.java b/scribejava-core/src/main/java/com/github/scribejava/core/base64/JaxbBase64.java new file mode 100644 index 000000000..85e889501 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/base64/JaxbBase64.java @@ -0,0 +1,29 @@ +package com.github.scribejava.core.base64; + +import jakarta.xml.bind.DatatypeConverter; + +public class JaxbBase64 extends Base64 { + + @Override + protected String internalEncode(byte[] bytes) { + return DatatypeConverter.printBase64Binary(bytes); + } + + @Override + protected String internalEncodeUrlWithoutPadding(byte[] bytes) { + String string = DatatypeConverter.printBase64Binary(bytes); + while (string.endsWith("=")) { + string = string.substring(0, string.length() - 1); + } + return string.replace('+', '-').replace('/', '_'); + } + + static boolean isAvailable() { + try { + Class.forName("jakarta.xml.bind.DatatypeConverter", false, JaxbBase64.class.getClassLoader()); + return true; + } catch (ClassNotFoundException cnfE) { + return false; + } + } +} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/base64/Base64Test.java b/scribejava-core/src/test/java/com/github/scribejava/core/base64/Base64Test.java index 4a6dd4102..bd5734b18 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/base64/Base64Test.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/base64/Base64Test.java @@ -10,6 +10,7 @@ public class Base64Test { private Base64 java8Base64; private Base64 commonsCodecBase64; + private Base64 jaxbBase64; private byte[] helloWorldBytes; private byte[] helloWorldTwoLinesBytes; private byte[] helloWorldTwoLinesAndNewLineBytes; @@ -55,12 +56,14 @@ public void setUp() throws UnsupportedEncodingException { java8Base64 = new Java8Base64(); commonsCodecBase64 = new CommonsCodecBase64(); + jaxbBase64 = new JaxbBase64(); } @Test public void allImplementationsAreAvailable() { assertTrue(Java8Base64.isAvailable()); assertTrue(CommonsCodecBase64.isAvailable()); + assertTrue(JaxbBase64.isAvailable()); } @Test @@ -100,6 +103,12 @@ public void testEncode() { commonsCodecBase64.internalEncode(helloWorldTwoLinesAndNewLineBytes)); assertEquals(helloWorldDifferentCharsEncoded, commonsCodecBase64.internalEncode(helloWorldDifferentCharsBytes)); assertEquals(str, commonsCodecBase64.internalEncode(bytes)); + + assertEquals(helloWorldEncoded, jaxbBase64.internalEncode(helloWorldBytes)); + assertEquals(helloWorldTwoLinesEncoded, jaxbBase64.internalEncode(helloWorldTwoLinesBytes)); + assertEquals(helloWorldTwoLinesAndNewLineEncoded, jaxbBase64.internalEncode(helloWorldTwoLinesAndNewLineBytes)); + assertEquals(helloWorldDifferentCharsEncoded, jaxbBase64.internalEncode(helloWorldDifferentCharsBytes)); + assertEquals(str, jaxbBase64.internalEncode(bytes)); } @Test @@ -142,5 +151,13 @@ public void testEncodeUrlWithoutPadding() { assertEquals(helloWorldDifferentCharsEncoded, commonsCodecBase64.internalEncodeUrlWithoutPadding(helloWorldDifferentCharsBytes)); assertEquals(str, commonsCodecBase64.internalEncodeUrlWithoutPadding(bytes)); + + assertEquals(helloWorldEncoded, jaxbBase64.internalEncodeUrlWithoutPadding(helloWorldBytes)); + assertEquals(helloWorldTwoLinesEncoded, jaxbBase64.internalEncodeUrlWithoutPadding(helloWorldTwoLinesBytes)); + assertEquals(helloWorldTwoLinesAndNewLineEncoded, + jaxbBase64.internalEncodeUrlWithoutPadding(helloWorldTwoLinesAndNewLineBytes)); + assertEquals(helloWorldDifferentCharsEncoded, + jaxbBase64.internalEncodeUrlWithoutPadding(helloWorldDifferentCharsBytes)); + assertEquals(str, jaxbBase64.internalEncodeUrlWithoutPadding(bytes)); } } From 33e4b878365c6fe5e5d3939a9241591a26101a10 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sat, 20 Feb 2021 10:34:19 +0300 Subject: [PATCH 435/481] add Base64 implementation - JAXB v2.3.0 (the latest for JRE 7) --- scribejava-core/pom.xml | 6 ++++ .../github/scribejava/core/base64/Base64.java | 7 ++-- .../scribejava/core/base64/Jaxb230Base64.java | 32 +++++++++++++++++++ .../scribejava/core/base64/Base64Test.java | 18 +++++++++++ 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/base64/Jaxb230Base64.java diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index a1d3db645..71a12b309 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -32,6 +32,12 @@ 3.0.0 true + + javax.xml.bind + jaxb-api + 2.3.0 + true + diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java index 6e89741a2..18a8f01a0 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Base64.java @@ -22,12 +22,15 @@ private static Base64 createInstance() { if (Java8Base64.isAvailable()) { return new Java8Base64(); } - if (CommonsCodecBase64.isAvailable()) { - return new CommonsCodecBase64(); + if (Jaxb230Base64.isAvailable()) { + return new Jaxb230Base64(); } if (JaxbBase64.isAvailable()) { return new JaxbBase64(); } + if (CommonsCodecBase64.isAvailable()) { + return new CommonsCodecBase64(); + } throw new IllegalStateException( "No Base64 implementation was provided. Java 8 Base64, Apache Commons Codec or JAXB is needed"); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/base64/Jaxb230Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Jaxb230Base64.java new file mode 100644 index 000000000..c4ee4d799 --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Jaxb230Base64.java @@ -0,0 +1,32 @@ +package com.github.scribejava.core.base64; + +import javax.xml.bind.DatatypeConverter; + +/** + * JAXB v2.3.0 (the latest for JRE 7) + */ +public class Jaxb230Base64 extends Base64 { + + @Override + protected String internalEncode(byte[] bytes) { + return DatatypeConverter.printBase64Binary(bytes); + } + + @Override + protected String internalEncodeUrlWithoutPadding(byte[] bytes) { + String string = DatatypeConverter.printBase64Binary(bytes); + while (string.endsWith("=")) { + string = string.substring(0, string.length() - 1); + } + return string.replace('+', '-').replace('/', '_'); + } + + static boolean isAvailable() { + try { + Class.forName("javax.xml.bind.DatatypeConverter", false, Jaxb230Base64.class.getClassLoader()); + return true; + } catch (ClassNotFoundException cnfE) { + return false; + } + } +} diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/base64/Base64Test.java b/scribejava-core/src/test/java/com/github/scribejava/core/base64/Base64Test.java index bd5734b18..9236a29a9 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/base64/Base64Test.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/base64/Base64Test.java @@ -11,6 +11,7 @@ public class Base64Test { private Base64 java8Base64; private Base64 commonsCodecBase64; private Base64 jaxbBase64; + private Base64 jaxb230Base64; private byte[] helloWorldBytes; private byte[] helloWorldTwoLinesBytes; private byte[] helloWorldTwoLinesAndNewLineBytes; @@ -57,6 +58,7 @@ public void setUp() throws UnsupportedEncodingException { java8Base64 = new Java8Base64(); commonsCodecBase64 = new CommonsCodecBase64(); jaxbBase64 = new JaxbBase64(); + jaxb230Base64 = new Jaxb230Base64(); } @Test @@ -64,6 +66,7 @@ public void allImplementationsAreAvailable() { assertTrue(Java8Base64.isAvailable()); assertTrue(CommonsCodecBase64.isAvailable()); assertTrue(JaxbBase64.isAvailable()); + assertTrue(Jaxb230Base64.isAvailable()); } @Test @@ -109,6 +112,13 @@ public void testEncode() { assertEquals(helloWorldTwoLinesAndNewLineEncoded, jaxbBase64.internalEncode(helloWorldTwoLinesAndNewLineBytes)); assertEquals(helloWorldDifferentCharsEncoded, jaxbBase64.internalEncode(helloWorldDifferentCharsBytes)); assertEquals(str, jaxbBase64.internalEncode(bytes)); + + assertEquals(helloWorldEncoded, jaxb230Base64.internalEncode(helloWorldBytes)); + assertEquals(helloWorldTwoLinesEncoded, jaxb230Base64.internalEncode(helloWorldTwoLinesBytes)); + assertEquals(helloWorldTwoLinesAndNewLineEncoded, + jaxb230Base64.internalEncode(helloWorldTwoLinesAndNewLineBytes)); + assertEquals(helloWorldDifferentCharsEncoded, jaxb230Base64.internalEncode(helloWorldDifferentCharsBytes)); + assertEquals(str, jaxb230Base64.internalEncode(bytes)); } @Test @@ -159,5 +169,13 @@ public void testEncodeUrlWithoutPadding() { assertEquals(helloWorldDifferentCharsEncoded, jaxbBase64.internalEncodeUrlWithoutPadding(helloWorldDifferentCharsBytes)); assertEquals(str, jaxbBase64.internalEncodeUrlWithoutPadding(bytes)); + + assertEquals(helloWorldEncoded, jaxb230Base64.internalEncodeUrlWithoutPadding(helloWorldBytes)); + assertEquals(helloWorldTwoLinesEncoded, jaxb230Base64.internalEncodeUrlWithoutPadding(helloWorldTwoLinesBytes)); + assertEquals(helloWorldTwoLinesAndNewLineEncoded, + jaxb230Base64.internalEncodeUrlWithoutPadding(helloWorldTwoLinesAndNewLineBytes)); + assertEquals(helloWorldDifferentCharsEncoded, + jaxb230Base64.internalEncodeUrlWithoutPadding(helloWorldDifferentCharsBytes)); + assertEquals(str, jaxb230Base64.internalEncodeUrlWithoutPadding(bytes)); } } From 45ad5e422757b409523801fc95d015bfc61d1493 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 3 Mar 2021 11:06:29 +0300 Subject: [PATCH 436/481] add new dataset to Base64 test (all bytes from -127 to 128) --- .../scribejava/core/base64/Base64Test.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/scribejava-core/src/test/java/com/github/scribejava/core/base64/Base64Test.java b/scribejava-core/src/test/java/com/github/scribejava/core/base64/Base64Test.java index 9236a29a9..4d345b77d 100644 --- a/scribejava-core/src/test/java/com/github/scribejava/core/base64/Base64Test.java +++ b/scribejava-core/src/test/java/com/github/scribejava/core/base64/Base64Test.java @@ -17,6 +17,7 @@ public class Base64Test { private byte[] helloWorldTwoLinesAndNewLineBytes; private byte[] helloWorldDifferentCharsBytes; private byte[] bytes; + private byte[] allBytes; @Before public void setUp() throws UnsupportedEncodingException { @@ -55,6 +56,19 @@ public void setUp() throws UnsupportedEncodingException { 103, 73, -30, 120, -15, 104, -9, 110, -24, -127, 14, -57, -44, 67, 9, 80, 120, 42, 94, 107, -81, -109, 101, -1, 91}; + allBytes = new byte[]{-128, -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114, + -113, -112, -111, -110, -109, -108, -107, -106, -105, -104, -103, -102, -101, -100, -99, -98, -97, -96, -95, + -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84, -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, + -73, -72, -71, -70, -69, -68, -67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54, -53, + -52, -51, -50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39, -38, -37, -36, -35, -34, -33, -32, + -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, + -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, + 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, + 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, + 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, + 121, 122, 123, 124, 125, 126, 127}; + java8Base64 = new Java8Base64(); commonsCodecBase64 = new CommonsCodecBase64(); jaxbBase64 = new JaxbBase64(); @@ -93,12 +107,18 @@ public void testEncode() { + "wJ3juUsVtujV23SnH43iMggXT7m82STpPGam1hPfmqu2Z0niePFo927ogQ7H1EMJ" + "UHgqXmuvk2X/Ww=="; + final String allBytesStr = "gIGCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJmam5ydnp+goaKjpKWmp6ipqqusra6vsLGys7S1tre4ubq7vL2" + + "+v8DBwsPExcbHyMnKy8zNzs/Q0dLT1NXW19jZ2tvc3d7f4OHi4+Tl5ufo6err7O3u7/Dx8vP09fb3+Pn6+/z9/v8AAQIDBAUGBwg" + + "JCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlN" + + "UVVZXWFlaW1xdXl9gYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXp7fH1+fw=="; + assertEquals(helloWorldEncoded, java8Base64.internalEncode(helloWorldBytes)); assertEquals(helloWorldTwoLinesEncoded, java8Base64.internalEncode(helloWorldTwoLinesBytes)); assertEquals(helloWorldTwoLinesAndNewLineEncoded, java8Base64.internalEncode(helloWorldTwoLinesAndNewLineBytes)); assertEquals(helloWorldDifferentCharsEncoded, java8Base64.internalEncode(helloWorldDifferentCharsBytes)); assertEquals(str, java8Base64.internalEncode(bytes)); + assertEquals(allBytesStr, java8Base64.internalEncode(allBytes)); assertEquals(helloWorldEncoded, commonsCodecBase64.internalEncode(helloWorldBytes)); assertEquals(helloWorldTwoLinesEncoded, commonsCodecBase64.internalEncode(helloWorldTwoLinesBytes)); @@ -106,12 +126,14 @@ public void testEncode() { commonsCodecBase64.internalEncode(helloWorldTwoLinesAndNewLineBytes)); assertEquals(helloWorldDifferentCharsEncoded, commonsCodecBase64.internalEncode(helloWorldDifferentCharsBytes)); assertEquals(str, commonsCodecBase64.internalEncode(bytes)); + assertEquals(allBytesStr, commonsCodecBase64.internalEncode(allBytes)); assertEquals(helloWorldEncoded, jaxbBase64.internalEncode(helloWorldBytes)); assertEquals(helloWorldTwoLinesEncoded, jaxbBase64.internalEncode(helloWorldTwoLinesBytes)); assertEquals(helloWorldTwoLinesAndNewLineEncoded, jaxbBase64.internalEncode(helloWorldTwoLinesAndNewLineBytes)); assertEquals(helloWorldDifferentCharsEncoded, jaxbBase64.internalEncode(helloWorldDifferentCharsBytes)); assertEquals(str, jaxbBase64.internalEncode(bytes)); + assertEquals(allBytesStr, jaxbBase64.internalEncode(allBytes)); assertEquals(helloWorldEncoded, jaxb230Base64.internalEncode(helloWorldBytes)); assertEquals(helloWorldTwoLinesEncoded, jaxb230Base64.internalEncode(helloWorldTwoLinesBytes)); @@ -119,6 +141,7 @@ public void testEncode() { jaxb230Base64.internalEncode(helloWorldTwoLinesAndNewLineBytes)); assertEquals(helloWorldDifferentCharsEncoded, jaxb230Base64.internalEncode(helloWorldDifferentCharsBytes)); assertEquals(str, jaxb230Base64.internalEncode(bytes)); + assertEquals(allBytesStr, jaxb230Base64.internalEncode(allBytes)); } @Test @@ -145,6 +168,11 @@ public void testEncodeUrlWithoutPadding() { + "wJ3juUsVtujV23SnH43iMggXT7m82STpPGam1hPfmqu2Z0niePFo927ogQ7H1EMJ" + "UHgqXmuvk2X_Ww"; + final String allBytesStr = "gIGCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJmam5ydnp-goaKjpKWmp6ipqqusra6vsLGys7S1tre4ubq7vL2" + + "-v8DBwsPExcbHyMnKy8zNzs_Q0dLT1NXW19jZ2tvc3d7f4OHi4-Tl5ufo6err7O3u7_Dx8vP09fb3-Pn6-_z9_v8AAQIDBAUGBwg" + + "JCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4_QEFCQ0RFRkdISUpLTE1OT1BRUlN" + + "UVVZXWFlaW1xdXl9gYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXp7fH1-fw"; + assertEquals(helloWorldEncoded, java8Base64.internalEncodeUrlWithoutPadding(helloWorldBytes)); assertEquals(helloWorldTwoLinesEncoded, java8Base64.internalEncodeUrlWithoutPadding(helloWorldTwoLinesBytes)); assertEquals(helloWorldTwoLinesAndNewLineEncoded, @@ -152,6 +180,7 @@ public void testEncodeUrlWithoutPadding() { assertEquals(helloWorldDifferentCharsEncoded, java8Base64.internalEncodeUrlWithoutPadding(helloWorldDifferentCharsBytes)); assertEquals(str, java8Base64.internalEncodeUrlWithoutPadding(bytes)); + assertEquals(allBytesStr, java8Base64.internalEncodeUrlWithoutPadding(allBytes)); assertEquals(helloWorldEncoded, commonsCodecBase64.internalEncodeUrlWithoutPadding(helloWorldBytes)); assertEquals(helloWorldTwoLinesEncoded, @@ -161,6 +190,7 @@ public void testEncodeUrlWithoutPadding() { assertEquals(helloWorldDifferentCharsEncoded, commonsCodecBase64.internalEncodeUrlWithoutPadding(helloWorldDifferentCharsBytes)); assertEquals(str, commonsCodecBase64.internalEncodeUrlWithoutPadding(bytes)); + assertEquals(allBytesStr, commonsCodecBase64.internalEncodeUrlWithoutPadding(allBytes)); assertEquals(helloWorldEncoded, jaxbBase64.internalEncodeUrlWithoutPadding(helloWorldBytes)); assertEquals(helloWorldTwoLinesEncoded, jaxbBase64.internalEncodeUrlWithoutPadding(helloWorldTwoLinesBytes)); @@ -169,6 +199,7 @@ public void testEncodeUrlWithoutPadding() { assertEquals(helloWorldDifferentCharsEncoded, jaxbBase64.internalEncodeUrlWithoutPadding(helloWorldDifferentCharsBytes)); assertEquals(str, jaxbBase64.internalEncodeUrlWithoutPadding(bytes)); + assertEquals(allBytesStr, jaxbBase64.internalEncodeUrlWithoutPadding(allBytes)); assertEquals(helloWorldEncoded, jaxb230Base64.internalEncodeUrlWithoutPadding(helloWorldBytes)); assertEquals(helloWorldTwoLinesEncoded, jaxb230Base64.internalEncodeUrlWithoutPadding(helloWorldTwoLinesBytes)); @@ -177,5 +208,6 @@ public void testEncodeUrlWithoutPadding() { assertEquals(helloWorldDifferentCharsEncoded, jaxb230Base64.internalEncodeUrlWithoutPadding(helloWorldDifferentCharsBytes)); assertEquals(str, jaxb230Base64.internalEncodeUrlWithoutPadding(bytes)); + assertEquals(allBytesStr, jaxb230Base64.internalEncodeUrlWithoutPadding(allBytes)); } } From f5a6f0b1534e1859e145e978e25f770e1e13e1ca Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Thu, 4 Mar 2021 09:58:33 +0300 Subject: [PATCH 437/481] update dependencies --- pom.xml | 10 +++++----- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 4863ccee6..2f14c5538 100644 --- a/pom.xml +++ b/pom.xml @@ -60,13 +60,13 @@ junit junit - 4.13.1 + 4.13.2 test com.squareup.okhttp3 mockwebserver - 4.9.0 + 4.9.1 test @@ -100,12 +100,12 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.1.1 + 3.1.2 com.puppycrawl.tools checkstyle - 8.39 + 8.40 @@ -271,7 +271,7 @@ 7 - 6.30.0 + 6.31.0 diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 31eb57e39..76aae5023 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -23,7 +23,7 @@ com.linecorp.armeria armeria - 1.3.0 + 1.5.0 com.github.scribejava diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 50bf431bf..57a7b64e5 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 4.9.0 + 4.9.1 com.github.scribejava From 4e90348e66a7d73969600fa67a3ae11cb7149eca Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Fri, 12 Mar 2021 12:38:53 +0300 Subject: [PATCH 438/481] implement possibility to add extra parameters to Access Token Request (AccessTokenRequestParams#*ExtraParameters methods), https://github.com/scribejava/scribejava/issues/980 (thanks to https://github.com/pmorch) --- changelog | 3 ++ .../core/oauth/AccessTokenRequestParams.java | 34 +++++++++++++++++++ .../scribejava/core/oauth/OAuth20Service.java | 8 +++++ 3 files changed, 45 insertions(+) diff --git a/changelog b/changelog index bf5216de7..81d528a24 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,9 @@ * add ScopeBuilder to easily specify multiple scopes while requesting OAuth2.0 Access Tokens * make Base64 en/de-coding not dependent from java8 implementation (use three optional implementation (internal java 8+, Apache Commons Codec, JAXB) detected in runtime) (thanks to https://github.com/CodingFabian) + * implement possibility to add extra parameters to Access Token Request + (AccessTokenRequestParams#*ExtraParameters methods), https://github.com/scribejava/scribejava/issues/980 + (thanks to https://github.com/pmorch) [8.1.0] * add raw Response (with HTTP response code and body) as member to the OAuth2AccessTokenErrorResponse diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/AccessTokenRequestParams.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/AccessTokenRequestParams.java index 5ee5d42ef..d45377a56 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/AccessTokenRequestParams.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/AccessTokenRequestParams.java @@ -1,12 +1,18 @@ package com.github.scribejava.core.oauth; import com.github.scribejava.core.builder.ScopeBuilder; +import java.util.HashMap; +import java.util.Map; +/** + * not thread safe + */ public class AccessTokenRequestParams { private final String code; private String pkceCodeVerifier; private String scope; + private Map extraParameters; public AccessTokenRequestParams(String code) { this.code = code; @@ -31,6 +37,34 @@ public AccessTokenRequestParams scope(ScopeBuilder scope) { return this; } + public AccessTokenRequestParams addExtraParameters(Map extraParameters) { + if (extraParameters == null || extraParameters.isEmpty()) { + return this; + } + if (this.extraParameters == null) { + extraParameters = new HashMap<>(); + } + this.extraParameters.putAll(extraParameters); + return this; + } + + public AccessTokenRequestParams addExtraParameter(String name, String value) { + if (this.extraParameters == null) { + extraParameters = new HashMap<>(); + } + this.extraParameters.put(name, value); + return this; + } + + public AccessTokenRequestParams setExtraParameters(Map extraParameters) { + this.extraParameters = extraParameters; + return this; + } + + public Map getExtraParameters() { + return extraParameters; + } + public String getCode() { return code; } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 0e028fb3c..4b4bb6adb 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -140,6 +140,14 @@ protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) if (pkceCodeVerifier != null) { request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); } + + final Map extraParameters = params.getExtraParameters(); + if (extraParameters != null && !extraParameters.isEmpty()) { + for (Map.Entry extraParameter : extraParameters.entrySet()) { + request.addParameter(extraParameter.getKey(), extraParameter.getValue()); + } + } + logRequestWithParams("access token", request); return request; } From 49cf8a6f2a88b3c6398b6e7616bedc458f97c0e4 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Fri, 12 Mar 2021 12:44:48 +0300 Subject: [PATCH 439/481] update deps --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 2f14c5538..3c1109320 100644 --- a/pom.xml +++ b/pom.xml @@ -55,7 +55,7 @@ com.fasterxml.jackson.core jackson-databind - 2.12.1 + 2.12.2 junit @@ -105,7 +105,7 @@ com.puppycrawl.tools checkstyle - 8.40 + 8.41 @@ -271,7 +271,7 @@ 7 - 6.31.0 + 6.32.0 From ce678fbf0538065943da23be9a2969859cbf3d47 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 13 Apr 2021 14:48:01 +0300 Subject: [PATCH 440/481] update deps --- pom.xml | 8 ++--- .../github/scribejava/apis/ExampleUtils.java | 31 ++++++++++--------- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index 3c1109320..c9a04ee38 100644 --- a/pom.xml +++ b/pom.xml @@ -55,7 +55,7 @@ com.fasterxml.jackson.core jackson-databind - 2.12.2 + 2.12.3 junit @@ -76,7 +76,7 @@ org.apache.felix maven-bundle-plugin - 5.1.1 + 5.1.2 bundle-manifest @@ -105,7 +105,7 @@ com.puppycrawl.tools checkstyle - 8.41 + 8.41.1 @@ -271,7 +271,7 @@ 7 - 6.32.0 + 6.33.0 diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java index f5917bcda..5f60abcb1 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/ExampleUtils.java @@ -17,20 +17,7 @@ private ExampleUtils() { public static void turnOfSSl() { try { - final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() { - @Override - public X509Certificate[] getAcceptedIssuers() { - return null; - } - - @Override - public void checkClientTrusted(X509Certificate[] certs, String authType) { - } - - @Override - public void checkServerTrusted(X509Certificate[] certs, String authType) { - } - } + final TrustManager[] trustAllCerts = new TrustManager[]{new TrustAllCertsManager() }; final SSLContext sc = SSLContext.getInstance("SSL"); @@ -49,4 +36,20 @@ public boolean verify(String hostname, SSLSession session) { throw new RuntimeException(e); } } + + private static class TrustAllCertsManager implements X509TrustManager { + + @Override + public X509Certificate[] getAcceptedIssuers() { + return null; + } + + @Override + public void checkClientTrusted(X509Certificate[] certs, String authType) { + } + + @Override + public void checkServerTrusted(X509Certificate[] certs, String authType) { + } + } } diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 218401fe4..710839ace 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.asynchttpclient async-http-client - 2.12.2 + 2.12.3 com.github.scribejava diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 76aae5023..3cf2b2794 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -23,7 +23,7 @@ com.linecorp.armeria armeria - 1.5.0 + 1.6.0 com.github.scribejava From 4a2f4280f7357143770e7b119a0e25efc674e129 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 13 Apr 2021 19:17:09 +0300 Subject: [PATCH 441/481] prepare v8.2.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 83180de24..cfa482f90 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 8.1.0 + 8.2.0 ``` @@ -145,7 +145,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 8.1.0 + 8.2.0 ``` diff --git a/changelog b/changelog index 81d528a24..ee6336655 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[8.2.0] * add ScopeBuilder to easily specify multiple scopes while requesting OAuth2.0 Access Tokens * make Base64 en/de-coding not dependent from java8 implementation (use three optional implementation (internal java 8+, Apache Commons Codec, JAXB) detected in runtime) (thanks to https://github.com/CodingFabian) From ce4402bc607354fe41a0e1f0dcf37f824c3a08de Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 13 Apr 2021 19:18:25 +0300 Subject: [PATCH 442/481] [maven-release-plugin] prepare release scribejava-8.2.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- scribejava-java8/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index c9a04ee38..db2978831 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 8.1.1-SNAPSHOT + 8.2.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -36,7 +36,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-8.2.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index ecfeead2c..e0ca099eb 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.1.1-SNAPSHOT + 8.2.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 71a12b309..0730794bf 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.1.1-SNAPSHOT + 8.2.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 710839ace..d1a174281 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.1.1-SNAPSHOT + 8.2.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 006579c1d..45e2113c3 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.1.1-SNAPSHOT + 8.2.0 ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 3cf2b2794..7048bbd16 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.1.1-SNAPSHOT + 8.2.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 1507674fe..bdc15a132 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.1.1-SNAPSHOT + 8.2.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 57a7b64e5..fcce1cd32 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.1.1-SNAPSHOT + 8.2.0 ../pom.xml diff --git a/scribejava-java8/pom.xml b/scribejava-java8/pom.xml index b27d8c98e..4e9a12186 100644 --- a/scribejava-java8/pom.xml +++ b/scribejava-java8/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.1.1-SNAPSHOT + 8.2.0 ../pom.xml From 02cf695dbc12969470096ef80c0781a7713b514a Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 13 Apr 2021 19:18:30 +0300 Subject: [PATCH 443/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- scribejava-java8/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index db2978831..b117ac97f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 8.2.0 + 8.2.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -36,7 +36,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-8.2.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index e0ca099eb..ec3882485 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.2.0 + 8.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 0730794bf..bb4dd0886 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.2.0 + 8.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index d1a174281..104b7926a 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.2.0 + 8.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 45e2113c3..57b7f3960 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.2.0 + 8.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 7048bbd16..558fb2bab 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.2.0 + 8.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index bdc15a132..97e28ded3 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.2.0 + 8.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index fcce1cd32..7b899aa14 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.2.0 + 8.2.1-SNAPSHOT ../pom.xml diff --git a/scribejava-java8/pom.xml b/scribejava-java8/pom.xml index 4e9a12186..0ec2162de 100644 --- a/scribejava-java8/pom.xml +++ b/scribejava-java8/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.2.0 + 8.2.1-SNAPSHOT ../pom.xml From 78aac50e3c50c8af65037bb28c8f6199596fe5d0 Mon Sep 17 00:00:00 2001 From: Maria Besfamilnaya Date: Sat, 17 Apr 2021 01:20:09 +0300 Subject: [PATCH 444/481] add Instagram API (https://www.instagram.com/) --- README.md | 1 + .../github/scribejava/apis/InstagramApi.java | 67 +++++++++++++ .../InstagramAccessTokenErrorResponse.java | 86 +++++++++++++++++ .../InstagramAccessTokenJsonExtractor.java | 59 ++++++++++++ .../apis/instagram/InstagramService.java | 80 ++++++++++++++++ .../apis/examples/InstagramExample.java | 95 +++++++++++++++++++ .../scribejava/core/oauth/OAuth20Service.java | 2 +- 7 files changed, 389 insertions(+), 1 deletion(-) create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/InstagramApi.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenErrorResponse.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenJsonExtractor.java create mode 100644 scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramService.java create mode 100644 scribejava-apis/src/test/java/com/github/scribejava/apis/examples/InstagramExample.java diff --git a/README.md b/README.md index cfa482f90..a91a90860 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ ScribeJava support out-of-box several HTTP clients: * HeadHunter ХэдХантер (https://hh.ru/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HHExample.java) * HiOrg-Server (https://www.hiorg-server.de/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/HiOrgServerExample.java) * Imgur (http://imgur.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ImgurExample.java) +* Instagram (https://www.instagram.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/InstagramExample.java) * Kaixin 开心网 (http://www.kaixin001.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Kaixin20Example.java) * Kakao (https://kakao.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KakaoExample.java) * Keycloak (https://www.keycloak.org/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/KeycloakExample.java) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/InstagramApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/InstagramApi.java new file mode 100644 index 000000000..9d1aa8306 --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/InstagramApi.java @@ -0,0 +1,67 @@ +package com.github.scribejava.apis; + +import java.io.OutputStream; +import com.github.scribejava.apis.instagram.InstagramAccessTokenJsonExtractor; +import com.github.scribejava.apis.instagram.InstagramService; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.extractors.TokenExtractor; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; +import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; +import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; + +/** + * Instagram API + */ +public class InstagramApi extends DefaultApi20 { + + private static class InstanceHolder { + + private static final InstagramApi INSTANCE = new InstagramApi(); + } + + public static InstagramApi instance() { + return InstanceHolder.INSTANCE; + } + + @Override + public Verb getAccessTokenVerb() { + return Verb.POST; + } + + @Override + public String getAccessTokenEndpoint() { + return "https://api.instagram.com/oauth/access_token"; + } + + @Override + public String getRefreshTokenEndpoint() { + return "https://graph.instagram.com/refresh_access_token"; + } + + @Override + protected String getAuthorizationBaseUrl() { + return "https://api.instagram.com/oauth/authorize"; + } + + @Override + public TokenExtractor getAccessTokenExtractor() { + return InstagramAccessTokenJsonExtractor.instance(); + } + + @Override + public ClientAuthentication getClientAuthentication() { + return RequestBodyAuthenticationScheme.instance(); + } + + @Override + public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return new InstagramService(this, apiKey, apiSecret, callback, defaultScope, responseType, + debugStream, userAgent, httpClientConfig, httpClient); + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenErrorResponse.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenErrorResponse.java new file mode 100644 index 000000000..38fd07c4d --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenErrorResponse.java @@ -0,0 +1,86 @@ +package com.github.scribejava.apis.instagram; + +import java.io.IOException; +import java.util.Objects; +import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.model.Response; + +/** + * non standard Instagram replace for + * {@link com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse} + * + * examples:
    + * + * '{"error_type": "OAuthException", "code": 400, "error_message": "Missing required field client_id"}' + */ +public class InstagramAccessTokenErrorResponse extends OAuthException { + + private static final long serialVersionUID = -1277129766099856895L; + + private final String errorType; + private final int codeInt; + private final Response response; + + public InstagramAccessTokenErrorResponse(String errorType, int code, + String errorMessage, Response response) { + super(errorMessage); + this.errorType = errorType; + this.codeInt = code; + this.response = response; + } + + public String getErrorType() { + return errorType; + } + + public int getCodeInt() { + return codeInt; + } + + /** + * + * @return body of response + * @throws IOException IOException + * @deprecated use {@link #getResponse()} and then {@link Response#getBody()} + */ + @Deprecated + public String getRawResponse() throws IOException { + return response.getBody(); + } + + public Response getResponse() { + return response; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + InstagramAccessTokenErrorResponse that = (InstagramAccessTokenErrorResponse) o; + return codeInt == that.codeInt && Objects.equals(errorType, that.errorType) + && Objects.equals(response, that.response); + } + + @Override + public int hashCode() { + int hash = 5; + hash = 83 * hash + Objects.hashCode(response); + hash = 83 * hash + Objects.hashCode(getMessage()); + hash = 83 * hash + Objects.hashCode(errorType); + hash = 83 * hash + Objects.hashCode(codeInt); + return hash; + } + + @Override + public String toString() { + return "InstagramAccessTokenErrorResponse{" + + "errorType='" + errorType + '\'' + + ", codeInt=" + codeInt + + ", response=" + response + + '}'; + } +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenJsonExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenJsonExtractor.java new file mode 100644 index 000000000..3cca4337f --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenJsonExtractor.java @@ -0,0 +1,59 @@ +package com.github.scribejava.apis.instagram; + +import java.io.IOException; +import com.fasterxml.jackson.databind.JsonNode; +import com.github.scribejava.apis.facebook.FacebookAccessTokenJsonExtractor; +import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; +import com.github.scribejava.core.model.Response; + +/** + * non standard Facebook Extractor + */ +public class InstagramAccessTokenJsonExtractor extends OAuth2AccessTokenJsonExtractor { + + protected InstagramAccessTokenJsonExtractor() { + } + + private static class InstanceHolder { + + private static final InstagramAccessTokenJsonExtractor INSTANCE = new InstagramAccessTokenJsonExtractor(); + } + + public static InstagramAccessTokenJsonExtractor instance() { + return InstanceHolder.INSTANCE; + } + + /** + * Non standard error message. Could be Instagram or Facebook specific. + * Usually Instagram type is used for getting access tokens. Facebook type is used for + * refreshing tokens. + * + * examples:
    + * + * Instagram specific: + * '{"error_type": "OAuthException", "code": 400, "error_message": "Missing required field client_id"}' + * + * Facebook specific: + * '{"error":{"message":"Error validating application. Invalid application + * ID.","type":"OAuthException","code":101,"fbtrace_id":"CvDR+X4WWIx"}}' + * + * @param response response + */ + @Override + public void generateError(Response response) throws IOException { + final JsonNode errorNode = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER + .readTree(response.getBody()); + JsonNode error = errorNode.get("error"); + if (error != null) { + FacebookAccessTokenJsonExtractor.instance().generateError(response); + } else { + throw new InstagramAccessTokenErrorResponse( + errorNode.get("error_type").asText(), + errorNode.get("code").asInt(), + errorNode.get("error_message").asText(), + response + ); + } + } + +} diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramService.java new file mode 100644 index 000000000..c1814fb8d --- /dev/null +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramService.java @@ -0,0 +1,80 @@ +package com.github.scribejava.apis.instagram; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.concurrent.ExecutionException; +import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.core.httpclient.HttpClient; +import com.github.scribejava.core.httpclient.HttpClientConfig; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthConstants; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +public class InstagramService extends OAuth20Service { + + private static final String LONG_LIVED_ACCESS_TOKEN_ENDPOINT = "https://graph.instagram.com/access_token"; + + public InstagramService(DefaultApi20 api, String apiKey, String apiSecret, String callback, + String defaultScope, String responseType, OutputStream debugStream, String userAgent, + HttpClientConfig httpClientConfig, HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, + userAgent, httpClientConfig, httpClient); + } + + /** + * Refresh a long-lived Instagram User Access Token that is at least 24 hours old but has not expired. + * Refreshed tokens are valid for 60 days from the date at which they are refreshed. + * + * @param accessToken long-lived access token + * @param scope (not used) + * @return refresh token request + */ + @Override + protected OAuthRequest createRefreshTokenRequest(String accessToken, String scope) { + if (accessToken == null || accessToken.isEmpty()) { + throw new IllegalArgumentException("The refreshToken cannot be null or empty"); + } + final OAuthRequest request = new OAuthRequest(Verb.GET, getApi().getRefreshTokenEndpoint()); + + request.addParameter(OAuthConstants.GRANT_TYPE, "ig_refresh_token"); + request.addParameter(OAuthConstants.ACCESS_TOKEN, accessToken); + + logRequestWithParams("refresh token", request); + + return request; + } + + /** + * Get long-lived access token. + * + * Initial accessToken is valid for 1 hour so one can get long-lived access token. + * Long-lived access token is valid for 60 days. + * + * @param accessToken short-lived access token + * @return long-lived access token with filled expireIn and refreshToken + */ + public OAuth2AccessToken getLongLivedAccessToken(OAuth2AccessToken accessToken) + throws InterruptedException, ExecutionException, IOException { + String shortLivedAccessToken = accessToken.getAccessToken(); + OAuthRequest request = createLongLivedAccessTokenRequest(shortLivedAccessToken); + return sendAccessTokenRequestSync(request); + } + + private OAuthRequest createLongLivedAccessTokenRequest(String shortLivedAccessToken) { + final OAuthRequest request = new OAuthRequest(Verb.GET, LONG_LIVED_ACCESS_TOKEN_ENDPOINT); + + getApi().getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); + + request.addParameter(OAuthConstants.GRANT_TYPE, "ig_exchange_token"); + request.addParameter(OAuthConstants.ACCESS_TOKEN, shortLivedAccessToken); + + if (isDebug()) { + log("created long-lived access token request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); + } + return request; + } +} diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/InstagramExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/InstagramExample.java new file mode 100644 index 000000000..aa4c2c3cd --- /dev/null +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/InstagramExample.java @@ -0,0 +1,95 @@ +package com.github.scribejava.apis.examples; + +import java.io.IOException; +import java.util.Random; +import java.util.Scanner; +import java.util.concurrent.ExecutionException; +import com.github.scribejava.apis.InstagramApi; +import com.github.scribejava.apis.instagram.InstagramService; +import com.github.scribejava.core.builder.ServiceBuilder; +import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.Response; +import com.github.scribejava.core.model.Verb; +import com.github.scribejava.core.oauth.OAuth20Service; + +public class InstagramExample { + + private static final String NETWORK_NAME = "Instagram"; + private static final String PROTECTED_RESOURCE_URL = + "https://graph.instagram.com/me/media?fields=id,caption,media_type,media_url,username"; + + private InstagramExample() { + } + + @SuppressWarnings("PMD.SystemPrintln") + public static void main(String... args) throws IOException, InterruptedException, ExecutionException { + // Replace these with your client id and secret + final String clientId = "client-id"; + final String clientSecret = "client-secret"; + final String secretState = "secret" + new Random().nextInt(999_999); + final OAuth20Service service = new ServiceBuilder(clientId) + .apiSecret(clientSecret) + .defaultScope("user_profile,user_media") + .callback("http://example.com") + .build(InstagramApi.instance()); + + final Scanner in = new Scanner(System.in, "UTF-8"); + + System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ==="); + System.out.println(); + + // Obtain the Authorization URL + System.out.println("Fetching the Authorization URL..."); + final String authorizationUrl = service.getAuthorizationUrl(secretState); + System.out.println("Got the Authorization URL!"); + System.out.println("Now go and authorize ScribeJava here:"); + System.out.println(authorizationUrl); + System.out.println("And paste the authorization code here"); + System.out.print(">>"); + final String code = in.nextLine(); + System.out.println(); + + System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'."); + System.out.print(">>"); + final String value = in.nextLine(); + if (secretState.equals(value)) { + System.out.println("State value does match!"); + } else { + System.out.println("Ooops, state value does not match!"); + System.out.println("Expected = " + secretState); + System.out.println("Got = " + value); + System.out.println(); + } + + System.out.println("Trading the Authorization Code for an Access Token..."); + final OAuth2AccessToken accessToken = service.getAccessToken(code); + System.out.println("Got the Access Token!"); + System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')"); + System.out.println(); + + // Now let's go and ask for a protected resource! + System.out.println("Now we're going to access a protected resource..."); + final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); + service.signRequest(accessToken, request); + try (Response response = service.execute(request)) { + System.out.println("Got it! Lets see what we found..."); + System.out.println(); + System.out.println(response.getCode()); + System.out.println(response.getBody()); + } + System.out.println(); + System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); + + InstagramService instagramService = (InstagramService) service; + System.out.println("Now let's exchange our short-lived token to long-lived access token..."); + OAuth2AccessToken longLivedAccessToken = instagramService.getLongLivedAccessToken(accessToken); + System.out.println("Got the Access Token!"); + System.out.println("(The access token raw response looks like this: " + longLivedAccessToken.getRawResponse() + "')"); + + System.out.println("Now it's time to refresh long-lived token..."); + OAuth2AccessToken refreshAccessToken = service.refreshAccessToken(longLivedAccessToken.getAccessToken()); + System.out.println("Got the refreshed Access Token!"); + System.out.println("(The refreshed access token raw response looks like this: " + refreshAccessToken.getRawResponse() + "')"); + } +} diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index 4b4bb6adb..d7fa0a32c 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -657,7 +657,7 @@ public OAuth2AccessToken pollAccessTokenDeviceAuthorizationGrant(DeviceAuthoriza } } - private void logRequestWithParams(String requestDescription, OAuthRequest request) { + protected void logRequestWithParams(String requestDescription, OAuthRequest request) { if (isDebug()) { log("created " + requestDescription + " request with body params [%s], query string params [%s]", request.getBodyParams().asFormUrlEncodedString(), From 9c8e4c12df64fc15a9d7fb0335156e918977a39a Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Mon, 19 Apr 2021 11:13:49 +0300 Subject: [PATCH 445/481] * add Instagram (https://www.instagram.com/) API (thanks to https://github.com/faent) * add getErrorMessage method to FacebookAccessTokenErrorResponse. Should be used instead of general getMessage method from the parent Exception --- changelog | 5 + .../github/scribejava/apis/FacebookApi.java | 3 - .../github/scribejava/apis/InstagramApi.java | 26 ++-- .../FacebookAccessTokenErrorResponse.java | 64 +++----- .../InstagramAccessTokenErrorResponse.java | 80 +++++----- .../InstagramAccessTokenJsonExtractor.java | 34 ++-- .../apis/instagram/InstagramService.java | 146 ++++++++++-------- .../apis/polar/PolarOAuthService.java | 4 +- .../apis/examples/InstagramExample.java | 32 ++-- .../FacebookAccessTokenJsonExtractorTest.java | 2 +- .../DeviceAuthorizationJsonExtractor.java | 11 -- .../OAuth2AccessTokenJsonExtractor.java | 11 -- .../model/OAuth2AccessTokenErrorResponse.java | 39 +---- .../core/model/OAuthResponseException.java | 44 ++++++ 14 files changed, 237 insertions(+), 264 deletions(-) create mode 100644 scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthResponseException.java diff --git a/changelog b/changelog index ee6336655..1ea8f699e 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,8 @@ +[SNAPSHOT] + * add Instagram (https://www.instagram.com/) API (thanks to https://github.com/faent) + * add getErrorMessage method to FacebookAccessTokenErrorResponse. Should be used instead of general getMessage method + from the parent Exception + [8.2.0] * add ScopeBuilder to easily specify multiple scopes while requesting OAuth2.0 Access Tokens * make Base64 en/de-coding not dependent from java8 implementation (use three optional implementation diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java index 9c3ee7a46..d688248d6 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/FacebookApi.java @@ -13,9 +13,6 @@ import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; -/** - * Facebook API - */ public class FacebookApi extends DefaultApi20 { private final String version; diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/InstagramApi.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/InstagramApi.java index 9d1aa8306..85e408113 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/InstagramApi.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/InstagramApi.java @@ -8,16 +8,13 @@ import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuth20Service; import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication; import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme; -/** - * Instagram API - */ public class InstagramApi extends DefaultApi20 { + public static final String LONG_LIVED_ACCESS_TOKEN_ENDPOINT = "https://graph.instagram.com/access_token"; + private static class InstanceHolder { private static final InstagramApi INSTANCE = new InstagramApi(); @@ -27,11 +24,6 @@ public static InstagramApi instance() { return InstanceHolder.INSTANCE; } - @Override - public Verb getAccessTokenVerb() { - return Verb.POST; - } - @Override public String getAccessTokenEndpoint() { return "https://api.instagram.com/oauth/access_token"; @@ -49,19 +41,19 @@ protected String getAuthorizationBaseUrl() { @Override public TokenExtractor getAccessTokenExtractor() { - return InstagramAccessTokenJsonExtractor.instance(); + return InstagramAccessTokenJsonExtractor.instance(); } @Override public ClientAuthentication getClientAuthentication() { - return RequestBodyAuthenticationScheme.instance(); + return RequestBodyAuthenticationScheme.instance(); } @Override - public OAuth20Service createService(String apiKey, String apiSecret, String callback, String defaultScope, - String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, - HttpClient httpClient) { - return new InstagramService(this, apiKey, apiSecret, callback, defaultScope, responseType, - debugStream, userAgent, httpClientConfig, httpClient); + public InstagramService createService(String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + return new InstagramService(this, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, + userAgent, httpClientConfig, httpClient); } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java index 36cc4a504..ea5053931 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/facebook/FacebookAccessTokenErrorResponse.java @@ -1,6 +1,6 @@ package com.github.scribejava.apis.facebook; -import com.github.scribejava.core.exceptions.OAuthException; +import com.github.scribejava.core.model.OAuthResponseException; import com.github.scribejava.core.model.Response; import java.io.IOException; import java.util.Objects; @@ -16,39 +16,27 @@ * '{"error":{"message":"Error validating application. Invalid application * ID.","type":"OAuthException","code":101,"fbtrace_id":"CvDR+X4WWIx"}}' */ -public class FacebookAccessTokenErrorResponse extends OAuthException { +public class FacebookAccessTokenErrorResponse extends OAuthResponseException { private static final long serialVersionUID = -1277129766099856895L; + private final String errorMessage; private final String type; private final int codeInt; private final String fbtraceId; - private final Response response; - public FacebookAccessTokenErrorResponse(String message, String type, int code, String fbtraceId, - Response response) { - super(message); + public FacebookAccessTokenErrorResponse(String errorMessage, String type, int code, String fbtraceId, + Response response) + throws IOException { + super(response); + this.errorMessage = errorMessage; this.type = type; this.codeInt = code; this.fbtraceId = fbtraceId; - this.response = response; } - /** - * - * @param message message - * @param type type - * @param code code - * @param fbtraceId fbtraceId - * @param rawResponse rawResponse - * @deprecated use {@link #FacebookAccessTokenErrorResponse(java.lang.String, java.lang.String, - * int, java.lang.String, com.github.scribejava.core.model.Response) - * } - */ - @Deprecated - public FacebookAccessTokenErrorResponse(String message, String type, int code, String fbtraceId, - String rawResponse) { - this(message, type, code, fbtraceId, new Response(-1, null, null, rawResponse)); + public String getErrorMessage() { + return errorMessage; } public String getType() { @@ -63,26 +51,10 @@ public String getFbtraceId() { return fbtraceId; } - /** - * - * @return body of response - * @throws IOException IOException - * @deprecated use {@link #getResponse()} and then {@link Response#getBody()} - */ - @Deprecated - public String getRawResponse() throws IOException { - return response.getBody(); - } - - public Response getResponse() { - return response; - } - @Override public int hashCode() { - int hash = 5; - hash = 83 * hash + Objects.hashCode(response); - hash = 83 * hash + Objects.hashCode(getMessage()); + int hash = super.hashCode(); + hash = 83 * hash + Objects.hashCode(errorMessage); hash = 83 * hash + Objects.hashCode(type); hash = 83 * hash + Objects.hashCode(codeInt); hash = 83 * hash + Objects.hashCode(fbtraceId); @@ -100,11 +72,13 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final FacebookAccessTokenErrorResponse other = (FacebookAccessTokenErrorResponse) obj; - if (!Objects.equals(response, other.getResponse())) { + if (!super.equals(obj)) { return false; } - if (!Objects.equals(getMessage(), other.getMessage())) { + + final FacebookAccessTokenErrorResponse other = (FacebookAccessTokenErrorResponse) obj; + + if (!Objects.equals(errorMessage, other.getErrorMessage())) { return false; } if (!Objects.equals(type, other.getType())) { @@ -119,7 +93,7 @@ public boolean equals(Object obj) { @Override public String toString() { return "FacebookAccessTokenErrorResponse{'type'='" + type + "', 'codeInt'='" + codeInt - + "', 'fbtraceId'='" + fbtraceId + "', 'response'='" + response - + "', 'message'='" + getMessage() + "'}"; + + "', 'fbtraceId'='" + fbtraceId + "', 'response'='" + getResponse() + + "', 'errorMessage'='" + errorMessage + "'}"; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenErrorResponse.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenErrorResponse.java index 38fd07c4d..90e8ef92a 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenErrorResponse.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenErrorResponse.java @@ -1,31 +1,32 @@ package com.github.scribejava.apis.instagram; +import com.github.scribejava.core.model.OAuthResponseException; import java.io.IOException; import java.util.Objects; -import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.model.Response; /** - * non standard Instagram replace for - * {@link com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse} + * non standard Instagram replace for {@link com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse} * * examples:
    * * '{"error_type": "OAuthException", "code": 400, "error_message": "Missing required field client_id"}' */ -public class InstagramAccessTokenErrorResponse extends OAuthException { +public class InstagramAccessTokenErrorResponse extends OAuthResponseException { - private static final long serialVersionUID = -1277129766099856895L; + private static final long serialVersionUID = -1277129706699856895L; private final String errorType; - private final int codeInt; + private final int code; + private final String errorMessage; private final Response response; - public InstagramAccessTokenErrorResponse(String errorType, int code, - String errorMessage, Response response) { - super(errorMessage); + public InstagramAccessTokenErrorResponse(String errorType, int code, String errorMessage, Response response) + throws IOException { + super(response); this.errorType = errorType; - this.codeInt = code; + this.code = code; + this.errorMessage = errorMessage; this.response = response; } @@ -33,54 +34,51 @@ public String getErrorType() { return errorType; } - public int getCodeInt() { - return codeInt; + public int getCode() { + return code; } - /** - * - * @return body of response - * @throws IOException IOException - * @deprecated use {@link #getResponse()} and then {@link Response#getBody()} - */ - @Deprecated - public String getRawResponse() throws IOException { - return response.getBody(); - } - - public Response getResponse() { - return response; + public String getErrorMessage() { + return errorMessage; } @Override - public boolean equals(Object o) { - if (this == o) { - return true; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; } - if (o == null || getClass() != o.getClass()) { - return false; + if (!super.equals(obj)) { + return false; + } + + final InstagramAccessTokenErrorResponse that = (InstagramAccessTokenErrorResponse) obj; + if (!Objects.equals(errorMessage, that.getErrorMessage())) { + return false; } - InstagramAccessTokenErrorResponse that = (InstagramAccessTokenErrorResponse) o; - return codeInt == that.codeInt && Objects.equals(errorType, that.errorType) - && Objects.equals(response, that.response); + return code == that.code && Objects.equals(errorType, that.errorType) + && Objects.equals(response, that.response); } @Override public int hashCode() { - int hash = 5; + int hash = super.hashCode(); hash = 83 * hash + Objects.hashCode(response); - hash = 83 * hash + Objects.hashCode(getMessage()); + hash = 83 * hash + Objects.hashCode(errorMessage); hash = 83 * hash + Objects.hashCode(errorType); - hash = 83 * hash + Objects.hashCode(codeInt); + hash = 83 * hash + Objects.hashCode(code); return hash; } @Override public String toString() { - return "InstagramAccessTokenErrorResponse{" + - "errorType='" + errorType + '\'' + - ", codeInt=" + codeInt + - ", response=" + response + - '}'; + return "InstagramAccessTokenErrorResponse{" + + "errorType='" + errorType + + "', code=" + code + + "', errorMessage='" + errorMessage + + "', response=" + response + + '}'; } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenJsonExtractor.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenJsonExtractor.java index 3cca4337f..8f30b2e96 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenJsonExtractor.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenJsonExtractor.java @@ -7,7 +7,7 @@ import com.github.scribejava.core.model.Response; /** - * non standard Facebook Extractor + * non standard Instagram Extractor */ public class InstagramAccessTokenJsonExtractor extends OAuth2AccessTokenJsonExtractor { @@ -24,36 +24,32 @@ public static InstagramAccessTokenJsonExtractor instance() { } /** - * Non standard error message. Could be Instagram or Facebook specific. - * Usually Instagram type is used for getting access tokens. Facebook type is used for - * refreshing tokens. + * Non standard error message. Could be Instagram or Facebook specific. Usually Instagram type is used for getting + * access tokens. Facebook type is used for refreshing tokens. * * examples:
    * - * Instagram specific: - * '{"error_type": "OAuthException", "code": 400, "error_message": "Missing required field client_id"}' + * Instagram specific: '{"error_type": "OAuthException", "code": 400, "error_message": "Missing required field + * client_id"}' * - * Facebook specific: - * '{"error":{"message":"Error validating application. Invalid application + * Facebook specific: '{"error":{"message":"Error validating application. Invalid application * ID.","type":"OAuthException","code":101,"fbtrace_id":"CvDR+X4WWIx"}}' * * @param response response */ @Override public void generateError(Response response) throws IOException { - final JsonNode errorNode = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER - .readTree(response.getBody()); - JsonNode error = errorNode.get("error"); + final JsonNode errorNode = OAuth2AccessTokenJsonExtractor.OBJECT_MAPPER.readTree(response.getBody()); + final JsonNode error = errorNode.get("error"); if (error != null) { - FacebookAccessTokenJsonExtractor.instance().generateError(response); + FacebookAccessTokenJsonExtractor.instance().generateError(response); } else { - throw new InstagramAccessTokenErrorResponse( - errorNode.get("error_type").asText(), - errorNode.get("code").asInt(), - errorNode.get("error_message").asText(), - response - ); + throw new InstagramAccessTokenErrorResponse( + errorNode.get("error_type").asText(), + errorNode.get("code").asInt(), + errorNode.get("error_message").asText(), + response + ); } } - } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramService.java index c1814fb8d..03f652867 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramService.java @@ -1,80 +1,102 @@ package com.github.scribejava.apis.instagram; +import com.github.scribejava.apis.InstagramApi; import java.io.IOException; import java.io.OutputStream; import java.util.concurrent.ExecutionException; -import com.github.scribejava.core.builder.api.DefaultApi20; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuth2AccessToken; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.OAuthConstants; import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth20Service; +import java.util.concurrent.Future; public class InstagramService extends OAuth20Service { - private static final String LONG_LIVED_ACCESS_TOKEN_ENDPOINT = "https://graph.instagram.com/access_token"; - - public InstagramService(DefaultApi20 api, String apiKey, String apiSecret, String callback, - String defaultScope, String responseType, OutputStream debugStream, String userAgent, - HttpClientConfig httpClientConfig, HttpClient httpClient) { - super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, - userAgent, httpClientConfig, httpClient); - } - - /** - * Refresh a long-lived Instagram User Access Token that is at least 24 hours old but has not expired. - * Refreshed tokens are valid for 60 days from the date at which they are refreshed. - * - * @param accessToken long-lived access token - * @param scope (not used) - * @return refresh token request - */ - @Override - protected OAuthRequest createRefreshTokenRequest(String accessToken, String scope) { - if (accessToken == null || accessToken.isEmpty()) { - throw new IllegalArgumentException("The refreshToken cannot be null or empty"); + public InstagramService(InstagramApi api, String apiKey, String apiSecret, String callback, String defaultScope, + String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, + HttpClient httpClient) { + super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, + httpClient); } - final OAuthRequest request = new OAuthRequest(Verb.GET, getApi().getRefreshTokenEndpoint()); - - request.addParameter(OAuthConstants.GRANT_TYPE, "ig_refresh_token"); - request.addParameter(OAuthConstants.ACCESS_TOKEN, accessToken); - - logRequestWithParams("refresh token", request); - - return request; - } - - /** - * Get long-lived access token. - * - * Initial accessToken is valid for 1 hour so one can get long-lived access token. - * Long-lived access token is valid for 60 days. - * - * @param accessToken short-lived access token - * @return long-lived access token with filled expireIn and refreshToken - */ - public OAuth2AccessToken getLongLivedAccessToken(OAuth2AccessToken accessToken) - throws InterruptedException, ExecutionException, IOException { - String shortLivedAccessToken = accessToken.getAccessToken(); - OAuthRequest request = createLongLivedAccessTokenRequest(shortLivedAccessToken); - return sendAccessTokenRequestSync(request); - } - - private OAuthRequest createLongLivedAccessTokenRequest(String shortLivedAccessToken) { - final OAuthRequest request = new OAuthRequest(Verb.GET, LONG_LIVED_ACCESS_TOKEN_ENDPOINT); - - getApi().getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); - - request.addParameter(OAuthConstants.GRANT_TYPE, "ig_exchange_token"); - request.addParameter(OAuthConstants.ACCESS_TOKEN, shortLivedAccessToken); - - if (isDebug()) { - log("created long-lived access token request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); + + /** + * Refresh a long-lived Instagram User Access Token that is at least 24 hours old but has not expired. Refreshed + * tokens are valid for 60 days from the date at which they are refreshed. + * + * @param accessToken long-lived access token + * @param scope (not used) + * @return refresh token request + */ + @Override + protected OAuthRequest createRefreshTokenRequest(String accessToken, String scope) { + if (accessToken == null || accessToken.isEmpty()) { + throw new IllegalArgumentException("The accessToken cannot be null or empty"); + } + final OAuthRequest request = new OAuthRequest(Verb.GET, getApi().getRefreshTokenEndpoint()); + + request.addParameter(OAuthConstants.GRANT_TYPE, "ig_refresh_token"); + request.addParameter(OAuthConstants.ACCESS_TOKEN, accessToken); + + logRequestWithParams("refresh token", request); + + return request; + } + + public Future getLongLivedAccessTokenAsync(OAuth2AccessToken accessToken) { + return getLongLivedAccessToken(accessToken.getAccessToken(), null); + } + + public Future getLongLivedAccessTokenAsync(String shortLivedAccessToken) { + return getLongLivedAccessToken(shortLivedAccessToken, null); + } + + public Future getLongLivedAccessToken(String shortLivedAccessToken, + OAuthAsyncRequestCallback callback) { + return sendAccessTokenRequestAsync(createLongLivedAccessTokenRequest(shortLivedAccessToken), callback); + } + + public Future getLongLivedAccessToken(OAuth2AccessToken accessToken, + OAuthAsyncRequestCallback callback) { + return getLongLivedAccessToken(accessToken.getAccessToken(), callback); + } + + /** + * Get long-lived access token. + * + * Initial accessToken is valid for 1 hour so one can get long-lived access token. Long-lived access token is valid + * for 60 days. + * + * @param accessToken short-lived access token + * @return long-lived access token with filled expireIn and refreshToken + */ + public OAuth2AccessToken getLongLivedAccessToken(OAuth2AccessToken accessToken) + throws InterruptedException, ExecutionException, IOException { + return getLongLivedAccessToken(accessToken.getAccessToken()); + } + + public OAuth2AccessToken getLongLivedAccessToken(String shortLivedAccessToken) + throws InterruptedException, ExecutionException, IOException { + final OAuthRequest request = createLongLivedAccessTokenRequest(shortLivedAccessToken); + return sendAccessTokenRequestSync(request); + } + + private OAuthRequest createLongLivedAccessTokenRequest(String shortLivedAccessToken) { + final OAuthRequest request = new OAuthRequest(Verb.GET, InstagramApi.LONG_LIVED_ACCESS_TOKEN_ENDPOINT); + + getApi().getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); + + request.addParameter(OAuthConstants.GRANT_TYPE, "ig_exchange_token"); + request.addParameter(OAuthConstants.ACCESS_TOKEN, shortLivedAccessToken); + + if (isDebug()) { + log("created long-lived access token request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); + } + return request; } - return request; - } } diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuthService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuthService.java index e0b0af6f1..c016d6ac7 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuthService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/polar/PolarOAuthService.java @@ -1,6 +1,6 @@ package com.github.scribejava.apis.polar; -import com.github.scribejava.core.builder.api.DefaultApi20; +import com.github.scribejava.apis.PolarAPI; import com.github.scribejava.core.httpclient.HttpClient; import com.github.scribejava.core.httpclient.HttpClientConfig; import com.github.scribejava.core.model.OAuthConstants; @@ -13,7 +13,7 @@ public class PolarOAuthService extends OAuth20Service { - public PolarOAuthService(DefaultApi20 api, String apiKey, String apiSecret, String callback, String defaultScope, + public PolarOAuthService(PolarAPI api, String apiKey, String apiSecret, String callback, String defaultScope, String responseType, OutputStream debugStream, String userAgent, HttpClientConfig httpClientConfig, HttpClient httpClient) { super(api, apiKey, apiSecret, callback, defaultScope, responseType, debugStream, userAgent, httpClientConfig, diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/InstagramExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/InstagramExample.java index aa4c2c3cd..9694ba909 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/InstagramExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/InstagramExample.java @@ -16,8 +16,8 @@ public class InstagramExample { private static final String NETWORK_NAME = "Instagram"; - private static final String PROTECTED_RESOURCE_URL = - "https://graph.instagram.com/me/media?fields=id,caption,media_type,media_url,username"; + private static final String PROTECTED_RESOURCE_URL + = "https://graph.instagram.com/me/media?fields=id,caption,media_type,media_url,username"; private InstagramExample() { } @@ -29,10 +29,10 @@ public static void main(String... args) throws IOException, InterruptedException final String clientSecret = "client-secret"; final String secretState = "secret" + new Random().nextInt(999_999); final OAuth20Service service = new ServiceBuilder(clientId) - .apiSecret(clientSecret) - .defaultScope("user_profile,user_media") - .callback("http://example.com") - .build(InstagramApi.instance()); + .apiSecret(clientSecret) + .defaultScope("user_profile,user_media") + .callback("http://example.com") + .build(InstagramApi.instance()); final Scanner in = new Scanner(System.in, "UTF-8"); @@ -81,15 +81,17 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println(); System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)"); - InstagramService instagramService = (InstagramService) service; - System.out.println("Now let's exchange our short-lived token to long-lived access token..."); - OAuth2AccessToken longLivedAccessToken = instagramService.getLongLivedAccessToken(accessToken); - System.out.println("Got the Access Token!"); - System.out.println("(The access token raw response looks like this: " + longLivedAccessToken.getRawResponse() + "')"); + final InstagramService instagramService = (InstagramService) service; + System.out.println("Now let's exchange our short-lived token to long-lived access token..."); + final OAuth2AccessToken longLivedAccessToken = instagramService.getLongLivedAccessToken(accessToken); + System.out.println("Got the Access Token!"); + System.out.println("(The access token raw response looks like this: " + longLivedAccessToken.getRawResponse() + + "')"); - System.out.println("Now it's time to refresh long-lived token..."); - OAuth2AccessToken refreshAccessToken = service.refreshAccessToken(longLivedAccessToken.getAccessToken()); - System.out.println("Got the refreshed Access Token!"); - System.out.println("(The refreshed access token raw response looks like this: " + refreshAccessToken.getRawResponse() + "')"); + System.out.println("Now it's time to refresh long-lived token..."); + final OAuth2AccessToken refreshAccessToken = service.refreshAccessToken(longLivedAccessToken.getAccessToken()); + System.out.println("Got the refreshed Access Token!"); + System.out.println("(The refreshed access token raw response looks like this: " + + refreshAccessToken.getRawResponse() + "')"); } } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java index 45b68353b..240f08b81 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/facebook/FacebookAccessTokenJsonExtractorTest.java @@ -29,7 +29,7 @@ public void run() throws Throwable { } }); - assertEquals("This authorization code has been used.", fateR.getMessage()); + assertEquals("This authorization code has been used.", fateR.getErrorMessage()); assertEquals("OAuthException", fateR.getType()); assertEquals(100, fateR.getCodeInt()); assertEquals("DtxvtGRaxbB", fateR.getFbtraceId()); diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/DeviceAuthorizationJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/DeviceAuthorizationJsonExtractor.java index 0dc0ce931..5b4fa248b 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/DeviceAuthorizationJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/DeviceAuthorizationJsonExtractor.java @@ -28,17 +28,6 @@ public DeviceAuthorization extract(Response response) throws IOException { return createDeviceAuthorization(response.getBody()); } - /** - * - * @param rawResponse rawResponse - * @throws java.io.IOException IOException - * @deprecated use {@link #generateError(com.github.scribejava.core.model.Response) } - */ - @Deprecated - public void generateError(String rawResponse) throws IOException { - generateError(new Response(-1, null, null, rawResponse)); - } - public void generateError(Response response) throws IOException { OAuth2AccessTokenJsonExtractor.instance().generateError(response); } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java index 982c7e499..b9bfd6cba 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractor.java @@ -39,17 +39,6 @@ public OAuth2AccessToken extract(Response response) throws IOException { return createToken(body); } - /** - * - * @param rawResponse rawResponse - * @throws java.io.IOException IOException - * @deprecated use {@link #generateError(com.github.scribejava.core.model.Response) } - */ - @Deprecated - public void generateError(String rawResponse) throws IOException { - generateError(new Response(-1, null, null, rawResponse)); - } - /** * Related documentation: https://tools.ietf.org/html/rfc6749#section-5.2 * diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java index c64a3d005..5c4a65a19 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessTokenErrorResponse.java @@ -1,6 +1,5 @@ package com.github.scribejava.core.model; -import com.github.scribejava.core.exceptions.OAuthException; import com.github.scribejava.core.oauth2.OAuth2Error; import java.io.IOException; @@ -9,39 +8,20 @@ /** * Representing "5.2. Error Response" */ -public class OAuth2AccessTokenErrorResponse extends OAuthException { +public class OAuth2AccessTokenErrorResponse extends OAuthResponseException { private static final long serialVersionUID = 2309424849700276816L; private final OAuth2Error error; private final String errorDescription; private final URI errorUri; - private final Response response; public OAuth2AccessTokenErrorResponse(OAuth2Error error, String errorDescription, URI errorUri, Response rawResponse) throws IOException { - super(rawResponse.getBody()); + super(rawResponse); this.error = error; this.errorDescription = errorDescription; this.errorUri = errorUri; - this.response = rawResponse; - } - - /** - * - * @param error error - * @param errorDescription errorDescription - * @param errorUri errorUri - * @param rawResponse rawResponse - * @throws java.io.IOException IOException - * @deprecated use {@link #OAuth2AccessTokenErrorResponse(com.github.scribejava.core.oauth2.OAuth2Error, - * java.lang.String, java.net.URI, com.github.scribejava.core.model.Response) - * } - */ - @Deprecated - public OAuth2AccessTokenErrorResponse(OAuth2Error error, String errorDescription, URI errorUri, - String rawResponse) throws IOException { - this(error, errorDescription, errorUri, new Response(-1, null, null, rawResponse)); } public OAuth2Error getError() { @@ -56,19 +36,4 @@ public URI getErrorUri() { return errorUri; } - /** - * - * @return body of response - * @throws IOException IOException - * @deprecated use {@link #getResponse()} and then {@link Response#getBody()} - */ - @Deprecated - public String getRawResponse() throws IOException { - return response.getBody(); - } - - public Response getResponse() { - return response; - } - } diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthResponseException.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthResponseException.java new file mode 100644 index 000000000..51b46960e --- /dev/null +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthResponseException.java @@ -0,0 +1,44 @@ +package com.github.scribejava.core.model; + +import com.github.scribejava.core.exceptions.OAuthException; +import java.io.IOException; +import java.util.Objects; + +public class OAuthResponseException extends OAuthException { + + private static final long serialVersionUID = 1309424849700276816L; + + private final Response response; + + public OAuthResponseException(Response rawResponse) throws IOException { + super(rawResponse.getBody()); + this.response = rawResponse; + } + + public Response getResponse() { + return response; + } + + @Override + public int hashCode() { + int hash = 5; + hash = 29 * hash + Objects.hashCode(response); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final OAuthResponseException other = (OAuthResponseException) obj; + return Objects.equals(this.response, other.response); + } + +} From fac51a866c225f2dfa915f4d28770090d4d9545a Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Mon, 19 Apr 2021 13:19:50 +0300 Subject: [PATCH 446/481] reorder methods in OAuth20Service, group them, comment groups --- .../scribejava/core/oauth/OAuth20Service.java | 319 +++++++++--------- 1 file changed, 164 insertions(+), 155 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java index d7fa0a32c..82052e351 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth20Service.java @@ -40,6 +40,108 @@ public OAuth20Service(DefaultApi20 api, String apiKey, String apiSecret, String this.defaultScope = defaultScope; } + // ===== common OAuth methods ===== + /** + * {@inheritDoc} + */ + @Override + public String getVersion() { + return VERSION; + } + + public void signRequest(String accessToken, OAuthRequest request) { + api.getBearerSignature().signRequest(accessToken, request); + } + + public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { + signRequest(accessToken == null ? null : accessToken.getAccessToken(), request); + } + + /** + * Returns the URL where you should redirect your users to authenticate your application. + * + * @return the URL where you should redirect your users + */ + public String getAuthorizationUrl() { + return createAuthorizationUrlBuilder().build(); + } + + public String getAuthorizationUrl(String state) { + return createAuthorizationUrlBuilder() + .state(state) + .build(); + } + + /** + * Returns the URL where you should redirect your users to authenticate your application. + * + * @param additionalParams any additional GET params to add to the URL + * @return the URL where you should redirect your users + */ + public String getAuthorizationUrl(Map additionalParams) { + return createAuthorizationUrlBuilder() + .additionalParams(additionalParams) + .build(); + } + + public String getAuthorizationUrl(PKCE pkce) { + return createAuthorizationUrlBuilder() + .pkce(pkce) + .build(); + } + + public AuthorizationUrlBuilder createAuthorizationUrlBuilder() { + return new AuthorizationUrlBuilder(this); + } + + public DefaultApi20 getApi() { + return api; + } + + public OAuth2Authorization extractAuthorization(String redirectLocation) { + final OAuth2Authorization authorization = new OAuth2Authorization(); + int end = redirectLocation.indexOf('#'); + if (end == -1) { + end = redirectLocation.length(); + } + for (String param : redirectLocation.substring(redirectLocation.indexOf('?') + 1, end).split("&")) { + final String[] keyValue = param.split("="); + if (keyValue.length == 2) { + try { + switch (keyValue[0]) { + case "code": + authorization.setCode(URLDecoder.decode(keyValue[1], "UTF-8")); + break; + case "state": + authorization.setState(URLDecoder.decode(keyValue[1], "UTF-8")); + break; + default: //just ignore any other param; + } + } catch (UnsupportedEncodingException ueE) { + throw new IllegalStateException("jvm without UTF-8, really?", ueE); + } + } + } + return authorization; + } + + public String getResponseType() { + return responseType; + } + + public String getDefaultScope() { + return defaultScope; + } + + protected void logRequestWithParams(String requestDescription, OAuthRequest request) { + if (isDebug()) { + log("created " + requestDescription + " request with body params [%s], query string params [%s]", + request.getBodyParams().asFormUrlEncodedString(), + request.getQueryStringParams().asFormUrlEncodedString()); + } + } + + // ===== common AccessToken request methods ===== //protected to facilitate mocking protected OAuth2AccessToken sendAccessTokenRequestSync(OAuthRequest request) throws IOException, InterruptedException, ExecutionException { @@ -83,6 +185,41 @@ public OAuth2AccessToken convert(Response response) throws IOException { }); } + // ===== get AccessToken authorisation code flow methods ===== + protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) { + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); + + api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); + + request.addParameter(OAuthConstants.CODE, params.getCode()); + final String callback = getCallback(); + if (callback != null) { + request.addParameter(OAuthConstants.REDIRECT_URI, callback); + } + final String scope = params.getScope(); + if (scope != null) { + request.addParameter(OAuthConstants.SCOPE, scope); + } else if (defaultScope != null) { + request.addParameter(OAuthConstants.SCOPE, defaultScope); + } + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); + + final String pkceCodeVerifier = params.getPkceCodeVerifier(); + if (pkceCodeVerifier != null) { + request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); + } + + final Map extraParameters = params.getExtraParameters(); + if (extraParameters != null && !extraParameters.isEmpty()) { + for (Map.Entry extraParameter : extraParameters.entrySet()) { + request.addParameter(extraParameter.getKey(), extraParameter.getValue()); + } + } + + logRequestWithParams("access token", request); + return request; + } + public Future getAccessTokenAsync(String code) { return getAccessToken(AccessTokenRequestParams.create(code), null); } @@ -118,37 +255,26 @@ public Future getAccessToken(String code, return getAccessToken(AccessTokenRequestParams.create(code), callback); } - protected OAuthRequest createAccessTokenRequest(AccessTokenRequestParams params) { - final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); + // ===== refresh AccessToken methods ===== + protected OAuthRequest createRefreshTokenRequest(String refreshToken, String scope) { + if (refreshToken == null || refreshToken.isEmpty()) { + throw new IllegalArgumentException("The refreshToken cannot be null or empty"); + } + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint()); api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); - request.addParameter(OAuthConstants.CODE, params.getCode()); - final String callback = getCallback(); - if (callback != null) { - request.addParameter(OAuthConstants.REDIRECT_URI, callback); - } - final String scope = params.getScope(); if (scope != null) { request.addParameter(OAuthConstants.SCOPE, scope); } else if (defaultScope != null) { request.addParameter(OAuthConstants.SCOPE, defaultScope); } - request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); - final String pkceCodeVerifier = params.getPkceCodeVerifier(); - if (pkceCodeVerifier != null) { - request.addParameter(PKCE.PKCE_CODE_VERIFIER_PARAM, pkceCodeVerifier); - } + request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); - final Map extraParameters = params.getExtraParameters(); - if (extraParameters != null && !extraParameters.isEmpty()) { - for (Map.Entry extraParameter : extraParameters.entrySet()) { - request.addParameter(extraParameter.getKey(), extraParameter.getValue()); - } - } + logRequestWithParams("refresh token", request); - logRequestWithParams("access token", request); return request; } @@ -186,13 +312,11 @@ public Future refreshAccessToken(String refreshToken, String return sendAccessTokenRequestAsync(request, callback); } - protected OAuthRequest createRefreshTokenRequest(String refreshToken, String scope) { - if (refreshToken == null || refreshToken.isEmpty()) { - throw new IllegalArgumentException("The refreshToken cannot be null or empty"); - } - final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint()); - - api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); + // ===== get AccessToken password grant flow methods ===== + protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, String password, String scope) { + final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); + request.addParameter(OAuthConstants.USERNAME, username); + request.addParameter(OAuthConstants.PASSWORD, password); if (scope != null) { request.addParameter(OAuthConstants.SCOPE, scope); @@ -200,10 +324,11 @@ protected OAuthRequest createRefreshTokenRequest(String refreshToken, String sco request.addParameter(OAuthConstants.SCOPE, defaultScope); } - request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken); - request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN); + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.PASSWORD); - logRequestWithParams("refresh token", request); + api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); + + logRequestWithParams("access token password grant", request); return request; } @@ -253,22 +378,20 @@ public Future getAccessTokenPasswordGrantAsync(String usernam return sendAccessTokenRequestAsync(request, callback); } - protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, String password, String scope) { + // ===== get AccessToken client credentials flow methods ===== + protected OAuthRequest createAccessTokenClientCredentialsGrantRequest(String scope) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - request.addParameter(OAuthConstants.USERNAME, username); - request.addParameter(OAuthConstants.PASSWORD, password); + + api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); if (scope != null) { request.addParameter(OAuthConstants.SCOPE, scope); } else if (defaultScope != null) { request.addParameter(OAuthConstants.SCOPE, defaultScope); } + request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.CLIENT_CREDENTIALS); - request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.PASSWORD); - - api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); - - logRequestWithParams("access token password grant", request); + logRequestWithParams("access token client credentials grant", request); return request; } @@ -316,80 +439,7 @@ public Future getAccessTokenClientCredentialsGrant(String sco return sendAccessTokenRequestAsync(request, callback); } - protected OAuthRequest createAccessTokenClientCredentialsGrantRequest(String scope) { - final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); - - api.getClientAuthentication().addClientAuthentication(request, getApiKey(), getApiSecret()); - - if (scope != null) { - request.addParameter(OAuthConstants.SCOPE, scope); - } else if (defaultScope != null) { - request.addParameter(OAuthConstants.SCOPE, defaultScope); - } - request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.CLIENT_CREDENTIALS); - - logRequestWithParams("access token client credentials grant", request); - - return request; - } - - /** - * {@inheritDoc} - */ - @Override - public String getVersion() { - return VERSION; - } - - public void signRequest(String accessToken, OAuthRequest request) { - api.getBearerSignature().signRequest(accessToken, request); - } - - public void signRequest(OAuth2AccessToken accessToken, OAuthRequest request) { - signRequest(accessToken == null ? null : accessToken.getAccessToken(), request); - } - - /** - * Returns the URL where you should redirect your users to authenticate your application. - * - * @return the URL where you should redirect your users - */ - public String getAuthorizationUrl() { - return createAuthorizationUrlBuilder().build(); - } - - public String getAuthorizationUrl(String state) { - return createAuthorizationUrlBuilder() - .state(state) - .build(); - } - - /** - * Returns the URL where you should redirect your users to authenticate your application. - * - * @param additionalParams any additional GET params to add to the URL - * @return the URL where you should redirect your users - */ - public String getAuthorizationUrl(Map additionalParams) { - return createAuthorizationUrlBuilder() - .additionalParams(additionalParams) - .build(); - } - - public String getAuthorizationUrl(PKCE pkce) { - return createAuthorizationUrlBuilder() - .pkce(pkce) - .build(); - } - - public AuthorizationUrlBuilder createAuthorizationUrlBuilder() { - return new AuthorizationUrlBuilder(this); - } - - public DefaultApi20 getApi() { - return api; - } - + // ===== revoke AccessToken methods ===== protected OAuthRequest createRevokeTokenRequest(String tokenToRevoke, TokenTypeHint tokenTypeHint) { final OAuthRequest request = new OAuthRequest(Verb.POST, api.getRevokeTokenEndpoint()); @@ -450,41 +500,7 @@ private void checkForErrorRevokeToken(Response response) throws IOException { } } - public OAuth2Authorization extractAuthorization(String redirectLocation) { - final OAuth2Authorization authorization = new OAuth2Authorization(); - int end = redirectLocation.indexOf('#'); - if (end == -1) { - end = redirectLocation.length(); - } - for (String param : redirectLocation.substring(redirectLocation.indexOf('?') + 1, end).split("&")) { - final String[] keyValue = param.split("="); - if (keyValue.length == 2) { - try { - switch (keyValue[0]) { - case "code": - authorization.setCode(URLDecoder.decode(keyValue[1], "UTF-8")); - break; - case "state": - authorization.setState(URLDecoder.decode(keyValue[1], "UTF-8")); - break; - default: //just ignore any other param; - } - } catch (UnsupportedEncodingException ueE) { - throw new IllegalStateException("jvm without UTF-8, really?", ueE); - } - } - } - return authorization; - } - - public String getResponseType() { - return responseType; - } - - public String getDefaultScope() { - return defaultScope; - } - + // ===== device Authorisation codes methods ===== protected OAuthRequest createDeviceAuthorizationCodesRequest(String scope) { final OAuthRequest request = new OAuthRequest(Verb.POST, api.getDeviceAuthorizationEndpoint()); request.addParameter(OAuthConstants.CLIENT_ID, getApiKey()); @@ -566,6 +582,7 @@ public Future getDeviceAuthorizationCodesAsync(String scope return getDeviceAuthorizationCodes(scope, null); } + // ===== get AccessToken Device Authorisation grant flow methods ===== protected OAuthRequest createAccessTokenDeviceAuthorizationGrantRequest(DeviceAuthorization deviceAuthorization) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); request.addParameter(OAuthConstants.GRANT_TYPE, "urn:ietf:params:oauth:grant-type:device_code"); @@ -656,12 +673,4 @@ public OAuth2AccessToken pollAccessTokenDeviceAuthorizationGrant(DeviceAuthoriza Thread.sleep(intervalMillis); } } - - protected void logRequestWithParams(String requestDescription, OAuthRequest request) { - if (isDebug()) { - log("created " + requestDescription + " request with body params [%s], query string params [%s]", - request.getBodyParams().asFormUrlEncodedString(), - request.getQueryStringParams().asFormUrlEncodedString()); - } - } } From b6d5d8417eb57e52aab389858d19734dc09cd738 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Mon, 19 Apr 2021 14:13:48 +0300 Subject: [PATCH 447/481] prepare v8.3.0 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a91a90860..27d3a3e32 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 8.2.0 + 8.3.0 ``` @@ -146,7 +146,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 8.2.0 + 8.3.0 ``` diff --git a/changelog b/changelog index 1ea8f699e..b469257b6 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[8.3.0] * add Instagram (https://www.instagram.com/) API (thanks to https://github.com/faent) * add getErrorMessage method to FacebookAccessTokenErrorResponse. Should be used instead of general getMessage method from the parent Exception From 1e1571e56694872959222b5e0c78aee1d8910243 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Mon, 19 Apr 2021 14:15:06 +0300 Subject: [PATCH 448/481] [maven-release-plugin] prepare release scribejava-8.3.0 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- scribejava-java8/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index b117ac97f..054ef33bb 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 8.2.1-SNAPSHOT + 8.3.0 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -36,7 +36,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-8.3.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index ec3882485..a29509a4b 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.2.1-SNAPSHOT + 8.3.0 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index bb4dd0886..f49ec30fb 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.2.1-SNAPSHOT + 8.3.0 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 104b7926a..706c46aed 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.2.1-SNAPSHOT + 8.3.0 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 57b7f3960..4128374c1 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.2.1-SNAPSHOT + 8.3.0 ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 558fb2bab..4872949dd 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.2.1-SNAPSHOT + 8.3.0 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 97e28ded3..a80cfa93f 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.2.1-SNAPSHOT + 8.3.0 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 7b899aa14..88a4ade95 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.2.1-SNAPSHOT + 8.3.0 ../pom.xml diff --git a/scribejava-java8/pom.xml b/scribejava-java8/pom.xml index 0ec2162de..2df10aee0 100644 --- a/scribejava-java8/pom.xml +++ b/scribejava-java8/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.2.1-SNAPSHOT + 8.3.0 ../pom.xml From 0142ceb93648047256d57e0056554f161816c97d Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Mon, 19 Apr 2021 14:15:15 +0300 Subject: [PATCH 449/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- scribejava-java8/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 054ef33bb..decaba8f8 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 8.3.0 + 8.3.1-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -36,7 +36,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-8.3.0 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index a29509a4b..86bd17b0e 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.0 + 8.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index f49ec30fb..1bb47d717 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.0 + 8.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 706c46aed..180e770f0 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.0 + 8.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 4128374c1..5ade17de5 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.0 + 8.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 4872949dd..87cd6c803 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.0 + 8.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index a80cfa93f..a92bd3ddb 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.0 + 8.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 88a4ade95..61b64ea00 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.0 + 8.3.1-SNAPSHOT ../pom.xml diff --git a/scribejava-java8/pom.xml b/scribejava-java8/pom.xml index 2df10aee0..66f6d3928 100644 --- a/scribejava-java8/pom.xml +++ b/scribejava-java8/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.0 + 8.3.1-SNAPSHOT ../pom.xml From e10771853ab55641378415af7cd1582bad670f2c Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 11 May 2021 15:38:13 +0300 Subject: [PATCH 450/481] * fix java.lang.NoClassDefFoundError for non-java8 runtimes (e.g. Android 7.1.1) (thanks to https://github.com/ChristopherGittner) --- changelog | 4 ++++ .../core/base64/CommonsCodecBase64.java | 16 ++++++++++++---- .../scribejava/core/base64/Java8Base64.java | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/changelog b/changelog index b469257b6..c0d51f34d 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,7 @@ +[SNAPSHOT] + * fix java.lang.NoClassDefFoundError for non-java8 runtimes (e.g. Android 7.1.1) + (thanks to https://github.com/ChristopherGittner) + [8.3.0] * add Instagram (https://www.instagram.com/) API (thanks to https://github.com/faent) * add getErrorMessage method to FacebookAccessTokenErrorResponse. Should be used instead of general getMessage method diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/base64/CommonsCodecBase64.java b/scribejava-core/src/main/java/com/github/scribejava/core/base64/CommonsCodecBase64.java index 196a6c4f0..bb172d720 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/base64/CommonsCodecBase64.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/base64/CommonsCodecBase64.java @@ -2,10 +2,18 @@ public class CommonsCodecBase64 extends Base64 { - private static final org.apache.commons.codec.binary.Base64 BASE64_ENCODER - = new org.apache.commons.codec.binary.Base64(); - private static final org.apache.commons.codec.binary.Base64 BASE64_URL_ENCODER_WITHOUT_PADDING - = new org.apache.commons.codec.binary.Base64(0, null, true); + private static final org.apache.commons.codec.binary.Base64 BASE64_ENCODER; + private static final org.apache.commons.codec.binary.Base64 BASE64_URL_ENCODER_WITHOUT_PADDING; + + static { + if (isAvailable()) { + BASE64_ENCODER = new org.apache.commons.codec.binary.Base64(); + BASE64_URL_ENCODER_WITHOUT_PADDING = new org.apache.commons.codec.binary.Base64(0, null, true); + } else { + BASE64_ENCODER = null; + BASE64_URL_ENCODER_WITHOUT_PADDING = null; + } + } @Override protected String internalEncode(byte[] bytes) { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/base64/Java8Base64.java b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Java8Base64.java index a5cea8755..8e4c6c990 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/base64/Java8Base64.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/base64/Java8Base64.java @@ -3,7 +3,7 @@ public class Java8Base64 extends Base64 { private static final com.github.scribejava.java8.base64.Java8Base64 JAVA8_BASE64 - = new com.github.scribejava.java8.base64.Java8Base64(); + = isAvailable() ? new com.github.scribejava.java8.base64.Java8Base64() : null; @Override protected String internalEncode(byte[] bytes) { From 744a547b1123c97f8f580e5d3a90896c2599240b Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 11 May 2021 16:08:17 +0300 Subject: [PATCH 451/481] update deps --- pmd.xml | 5 +---- pom.xml | 6 +++--- scribejava-core/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/pmd.xml b/pmd.xml index 7b5314710..5d93d340b 100644 --- a/pmd.xml +++ b/pmd.xml @@ -17,7 +17,6 @@ - @@ -34,8 +33,6 @@ - - @@ -48,6 +45,7 @@ + @@ -91,7 +89,6 @@ - diff --git a/pom.xml b/pom.xml index decaba8f8..812db228f 100644 --- a/pom.xml +++ b/pom.xml @@ -105,7 +105,7 @@ com.puppycrawl.tools checkstyle - 8.41.1 + 8.42 @@ -271,7 +271,7 @@ 7 - 6.33.0 + 6.34.0 @@ -288,7 +288,7 @@ org.apache.maven.plugins maven-gpg-plugin - 1.6 + 3.0.1 sign-artifacts diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 1bb47d717..53ac49b1e 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -29,7 +29,7 @@ jakarta.xml.bind jakarta.xml.bind-api - 3.0.0 + 3.0.1 true diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 87cd6c803..183841b3c 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -23,7 +23,7 @@ com.linecorp.armeria armeria - 1.6.0 + 1.7.2 com.github.scribejava From 82e0af898470f383196eece535275210c6c75d3d Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 11 May 2021 16:24:19 +0300 Subject: [PATCH 452/481] prepare v8.3.1 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 27d3a3e32..ef4083367 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 8.3.0 + 8.3.1 ``` @@ -146,7 +146,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 8.3.0 + 8.3.1 ``` diff --git a/changelog b/changelog index c0d51f34d..1b02de3ff 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[8.3.1] * fix java.lang.NoClassDefFoundError for non-java8 runtimes (e.g. Android 7.1.1) (thanks to https://github.com/ChristopherGittner) From b6fd7423cf2b7ee80f3ca1040d8c35986b657ed2 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 11 May 2021 16:25:50 +0300 Subject: [PATCH 453/481] [maven-release-plugin] prepare release scribejava-8.3.1 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- scribejava-java8/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 812db228f..205cb54ae 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 8.3.1-SNAPSHOT + 8.3.1 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -36,7 +36,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - HEAD + scribejava-8.3.1 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 86bd17b0e..2c6af49f7 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.1-SNAPSHOT + 8.3.1 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 53ac49b1e..bcdd78d4f 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.1-SNAPSHOT + 8.3.1 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 180e770f0..6b9f3d588 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.1-SNAPSHOT + 8.3.1 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 5ade17de5..17f3886b7 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.1-SNAPSHOT + 8.3.1 ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 183841b3c..8142c8f7a 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.1-SNAPSHOT + 8.3.1 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index a92bd3ddb..1f782e777 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.1-SNAPSHOT + 8.3.1 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 61b64ea00..28f2de496 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.1-SNAPSHOT + 8.3.1 ../pom.xml diff --git a/scribejava-java8/pom.xml b/scribejava-java8/pom.xml index 66f6d3928..5218f340f 100644 --- a/scribejava-java8/pom.xml +++ b/scribejava-java8/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.1-SNAPSHOT + 8.3.1 ../pom.xml From 2706674ddfa7c08a6e4500d4b031bc4a5bd4ff87 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 11 May 2021 16:25:56 +0300 Subject: [PATCH 454/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- scribejava-java8/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 205cb54ae..6d8a51983 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 8.3.1 + 8.3.2-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -36,7 +36,7 @@ scm:git:git://github.com/scribejava/scribejava.git scm:git:git@github.com:scribejava/scribejava.git https://github.com/scribejava/scribejava - scribejava-8.3.1 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 2c6af49f7..a9566dce7 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.1 + 8.3.2-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index bcdd78d4f..7b5414eba 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.1 + 8.3.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 6b9f3d588..fb6828ed5 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.1 + 8.3.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 17f3886b7..cb3f0ed72 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.1 + 8.3.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 8142c8f7a..f8d08eaf9 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.1 + 8.3.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 1f782e777..7aa41c3d0 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.1 + 8.3.2-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 28f2de496..dc6778772 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.1 + 8.3.2-SNAPSHOT ../pom.xml diff --git a/scribejava-java8/pom.xml b/scribejava-java8/pom.xml index 5218f340f..d8e7c74bd 100644 --- a/scribejava-java8/pom.xml +++ b/scribejava-java8/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.1 + 8.3.2-SNAPSHOT ../pom.xml From 124745961e999ccede90e2348c6012f8d335eb8a Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 3 Aug 2021 11:48:35 +0300 Subject: [PATCH 455/481] Create FUNDING.yml --- .github/FUNDING.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 000000000..cb518bff4 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: ['https://paypal.me/kullfar'] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] From 2ec12afcea7fcf298991b6a5cf38b02da11cc302 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 13 Apr 2022 10:53:53 +0300 Subject: [PATCH 456/481] Update donate.md add new link --- donate.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/donate.md b/donate.md index ee6a1a6e7..729221908 100644 --- a/donate.md +++ b/donate.md @@ -1,8 +1,12 @@ You can now help ScribeJava not only by Pull Requests. -You can use [https://paypal.me/kullfar](https://paypal.me/kullfar) directly +You can use [https://www.paypal.com/paypalme/algr453](https://www.paypal.com/paypalme/algr453) directly. -or try donation button from PayPal: [![Donate with PayPal button](https://www.paypalobjects.com/en_US/RU/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=E3XAUM2ET2R3Y&source=url) +

    Donation button for monthly donations or donations by card (VISA, MasterCard, etc) may not be working, but you can try... +...or try donation button from PayPal: [![Donate with PayPal button](https://www.paypalobjects.com/en_US/RU/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=E3XAUM2ET2R3Y&source=url) + +or old link [https://paypal.me/kullfar](https://paypal.me/kullfar) +
    Thanks in advance! From 95abfdfa149f504063439b705b8bc6fede62faf8 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 13 Apr 2022 11:01:45 +0300 Subject: [PATCH 457/481] Update donate.md remove collapse element. It doesn't work with images --- donate.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/donate.md b/donate.md index 729221908..4dcb6724d 100644 --- a/donate.md +++ b/donate.md @@ -2,11 +2,12 @@ You can now help ScribeJava not only by Pull Requests. You can use [https://www.paypal.com/paypalme/algr453](https://www.paypal.com/paypalme/algr453) directly. -
    Donation button for monthly donations or donations by card (VISA, MasterCard, etc) may not be working, but you can try... -...or try donation button from PayPal: [![Donate with PayPal button](https://www.paypalobjects.com/en_US/RU/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=E3XAUM2ET2R3Y&source=url) + +Donation button for monthly donations or donations by card (VISA, MasterCard, etc) may not be working, but you can try... + +donation button from PayPal: [![Donate with PayPal button](https://www.paypalobjects.com/en_US/RU/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=E3XAUM2ET2R3Y&source=url) or old link [https://paypal.me/kullfar](https://paypal.me/kullfar) -
    Thanks in advance! From ab666c1af946b197a1cfca14867a9c84636729af Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 13 Apr 2022 11:08:34 +0300 Subject: [PATCH 458/481] Update donate.md make image works in collapsible section --- donate.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/donate.md b/donate.md index 4dcb6724d..829e9a635 100644 --- a/donate.md +++ b/donate.md @@ -2,12 +2,12 @@ You can now help ScribeJava not only by Pull Requests. You can use [https://www.paypal.com/paypalme/algr453](https://www.paypal.com/paypalme/algr453) directly. +
    Donation button for monthly donations or donations by card (VISA, MasterCard, etc) may not be working, but you can try... -Donation button for monthly donations or donations by card (VISA, MasterCard, etc) may not be working, but you can try... - -donation button from PayPal: [![Donate with PayPal button](https://www.paypalobjects.com/en_US/RU/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=E3XAUM2ET2R3Y&source=url) +Donation button from PayPal: [![Donate with PayPal button](https://www.paypalobjects.com/en_US/RU/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=E3XAUM2ET2R3Y&source=url) or old link [https://paypal.me/kullfar](https://paypal.me/kullfar) +
    Thanks in advance! From 3a07d71f50b4f00bfda5fbae0eb765e612529ad9 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 13 Apr 2022 11:09:47 +0300 Subject: [PATCH 459/481] Update FUNDING.yml update paypal link --- .github/FUNDING.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index cb518bff4..0a2df9277 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username -custom: ['https://paypal.me/kullfar'] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] +custom: ['https://www.paypal.com/paypalme/algr453'] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] From 4d7a88e6eb86655a31a2e62a35f9801c8d90ea8b Mon Sep 17 00:00:00 2001 From: "David (javalin.io)" Date: Sat, 4 Jun 2022 11:56:51 +0200 Subject: [PATCH 460/481] [readme] Change variable naming in example This is a more common convention, which is also used in your own examples: https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Google20Example.java#L27-L35 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ef4083367..cd8b818ce 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,8 @@ Who said OAuth/OAuth2 was difficult? Configuring ScribeJava is __so easy your grandma can do it__! check it out: ```java -OAuthService service = new ServiceBuilder(YOUR_API_KEY) - .apiSecret(YOUR_API_SECRET) +OAuthService service = new ServiceBuilder(YOUR_CLIENT_ID) + .apiSecret(YOUR_CLIENT_SECRET) .build(LinkedInApi20.instance()); ``` From 4dff94d322794d7f52503ebea4542d346113cc37 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Fri, 26 Aug 2022 12:36:27 +0300 Subject: [PATCH 461/481] fix javadoc to fix build under openJDK 18.0.2 --- .../com/github/scribejava/core/model/OAuth2AccessToken.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java index 00d5b1636..f02bc57c6 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuth2AccessToken.java @@ -5,11 +5,9 @@ /** * Represents an OAuth 2 Access token. - *

    * http://tools.ietf.org/html/rfc6749#section-5.1 * * @see OAuth 2 Access Token Specification - *

    */ public class OAuth2AccessToken extends Token { From 1fc8d4c22fa03d9dea74b38f5a4fb9fd2c0a70eb Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Fri, 9 Sep 2022 10:49:07 +0300 Subject: [PATCH 462/481] disable ParenPad checkstyle rule due to the bug in the NetBeans (nb-javac) "try with resources formatting adding extra space" https://github.com/apache/netbeans/issues/3720 Let's make our life easier, just skip this check temporarily --- checkstyle.xml | 4 +++- .../com/github/scribejava/core/oauth/OAuth10aService.java | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/checkstyle.xml b/checkstyle.xml index c9b0fac9b..f7efbad65 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -96,7 +96,9 @@ - + diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java index 89fd279b1..f48308b2e 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuth10aService.java @@ -39,7 +39,7 @@ public OAuth1RequestToken getRequestToken() throws IOException, InterruptedExcep final OAuthRequest request = prepareRequestTokenRequest(); log("sending request..."); - try (Response response = execute(request)) { + try ( Response response = execute(request)) { if (isDebug()) { final String body = response.getBody(); log("response status code: %s", response.getCode()); @@ -105,7 +105,7 @@ public OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, String log("obtaining access token from %s", api.getAccessTokenEndpoint()); } final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier); - try (Response response = execute(request)) { + try ( Response response = execute(request)) { return api.getAccessTokenExtractor().extract(response); } } From 083b5f37b3d30e725f0b5962c5033a4a05ecf986 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Mon, 12 Sep 2022 13:17:09 +0300 Subject: [PATCH 463/481] mark Response as transient in Serializable classes and small fixes in javadocs --- .../apis/instagram/InstagramAccessTokenErrorResponse.java | 2 +- .../com/github/scribejava/apis/instagram/InstagramService.java | 3 +++ .../github/scribejava/core/httpclient/jdk/JDKHttpFuture.java | 2 ++ .../github/scribejava/core/model/OAuthResponseException.java | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenErrorResponse.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenErrorResponse.java index 90e8ef92a..bae3454a2 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenErrorResponse.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramAccessTokenErrorResponse.java @@ -19,7 +19,7 @@ public class InstagramAccessTokenErrorResponse extends OAuthResponseException { private final String errorType; private final int code; private final String errorMessage; - private final Response response; + private final transient Response response; public InstagramAccessTokenErrorResponse(String errorType, int code, String errorMessage, Response response) throws IOException { diff --git a/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramService.java b/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramService.java index 03f652867..5de1f3782 100644 --- a/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramService.java +++ b/scribejava-apis/src/main/java/com/github/scribejava/apis/instagram/InstagramService.java @@ -72,6 +72,9 @@ public Future getLongLivedAccessToken(OAuth2AccessToken acces * * @param accessToken short-lived access token * @return long-lived access token with filled expireIn and refreshToken + * @throws java.lang.InterruptedException + * @throws java.util.concurrent.ExecutionException + * @throws java.io.IOException */ public OAuth2AccessToken getLongLivedAccessToken(OAuth2AccessToken accessToken) throws InterruptedException, ExecutionException, IOException { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java index 1922d3aef..c4443cc87 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpFuture.java @@ -8,6 +8,8 @@ /** * Fake Future. Just to have Future API for the default JDK Http client. It's NOT Async in any way. Just facade.
    * That's it. Sync execution with Async methods. This class does NOT provide any async executions. + * + * @param */ public class JDKHttpFuture implements Future { diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthResponseException.java b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthResponseException.java index 51b46960e..5b6da25cf 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthResponseException.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthResponseException.java @@ -8,7 +8,7 @@ public class OAuthResponseException extends OAuthException { private static final long serialVersionUID = 1309424849700276816L; - private final Response response; + private final transient Response response; public OAuthResponseException(Response rawResponse) throws IOException { super(rawResponse.getBody()); From 8496a4e5b9c91df9fead056d8b3989babdce147c Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 13 Sep 2022 12:44:22 +0300 Subject: [PATCH 464/481] use in tests slf4j-simple instead of nop --- scribejava-httpclient-ahc/pom.xml | 6 ++++++ scribejava-httpclient-armeria/pom.xml | 6 ++++++ scribejava-httpclient-ning/pom.xml | 8 +++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index fb6828ed5..04c2f8b06 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -20,6 +20,12 @@ scribejava-core ${project.version}
    + + org.slf4j + slf4j-simple + 2.0.0 + test + org.asynchttpclient async-http-client diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index f8d08eaf9..fbd805576 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -20,6 +20,12 @@ scribejava-core ${project.version} + + org.slf4j + slf4j-simple + 2.0.0 + test + com.linecorp.armeria armeria diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 7aa41c3d0..a9de86702 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -8,7 +8,7 @@ 8.3.2-SNAPSHOT ../pom.xml - + com.github.scribejava scribejava-httpclient-ning ScribeJava Ning Async Http Client support @@ -20,6 +20,12 @@ scribejava-core ${project.version} + + org.slf4j + slf4j-simple + 2.0.0 + test + com.ning async-http-client From 2d4ee532022c35f7f3630fb5675c3d5999b63976 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 14 Sep 2022 11:01:23 +0300 Subject: [PATCH 465/481] fix ERRORs in build log due to the bug in the maven javadoc plugin (just update it) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6d8a51983..f8983b172 100644 --- a/pom.xml +++ b/pom.xml @@ -184,7 +184,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.2.0 + 3.4.1 ${java.home}/bin/javadoc UTF-8 From 23e02ed605556dcc7ca9c3acccefb10c6c65c8f0 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 14 Sep 2022 11:06:36 +0300 Subject: [PATCH 466/481] add changelog record about changes in the current SNAPSHOT --- changelog | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/changelog b/changelog index 1b02de3ff..0be0ed4b2 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,7 @@ +[SNAPSHOT] + * minor fixes and enhances + * update dependencies + [8.3.1] * fix java.lang.NoClassDefFoundError for non-java8 runtimes (e.g. Android 7.1.1) (thanks to https://github.com/ChristopherGittner) From 197c6a780eafb176a0d6d8c641bad560016efeec Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Thu, 15 Sep 2022 10:03:08 +0300 Subject: [PATCH 467/481] Update jackson to fix security warning --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f8983b172..d4505581f 100644 --- a/pom.xml +++ b/pom.xml @@ -55,7 +55,7 @@ com.fasterxml.jackson.core jackson-databind - 2.12.3 + 2.13.4 junit From f8f9587bb87848e263c83a106819af97fd43d29b Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Fri, 16 Sep 2022 11:24:10 +0300 Subject: [PATCH 468/481] update dependencies --- pom.xml | 20 ++++++++++---------- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index d4505581f..b678ae06d 100644 --- a/pom.xml +++ b/pom.xml @@ -66,7 +66,7 @@ com.squareup.okhttp3 mockwebserver - 4.9.1 + 4.10.0 test @@ -76,7 +76,7 @@ org.apache.felix maven-bundle-plugin - 5.1.2 + 5.1.8 bundle-manifest @@ -90,7 +90,7 @@ org.apache.maven.plugins maven-jar-plugin - 3.2.0 + 3.2.2 ${project.build.outputDirectory}/META-INF/MANIFEST.MF @@ -100,7 +100,7 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.1.2 + 3.2.0 com.puppycrawl.tools @@ -125,19 +125,19 @@ org.apache.maven.plugins maven-clean-plugin - 3.1.0 + 3.2.0 org.apache.maven.plugins maven-install-plugin - 2.5.2 + 3.0.1
    maven-compiler-plugin - 3.8.1 + 3.10.1 UTF-8 ${java.release} @@ -149,7 +149,7 @@ maven-deploy-plugin - 2.8.2 + 3.0.0 default-deploy @@ -163,7 +163,7 @@ org.apache.maven.plugins maven-resources-plugin - 3.2.0 + 3.3.0 UTF-8 @@ -225,7 +225,7 @@ org.apache.maven.plugins maven-pmd-plugin - 3.14.0 + 3.16.0 net.sourceforge.pmd diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index cb3f0ed72..7e1ba089b 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -28,7 +28,7 @@ org.apache.httpcomponents httpasyncclient - 4.1.4 + 4.1.5 com.github.scribejava diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index fbd805576..97b28e17f 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -29,7 +29,7 @@ com.linecorp.armeria armeria - 1.7.2 + 1.18.0 com.github.scribejava diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index dc6778772..d80798116 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -23,7 +23,7 @@ com.squareup.okhttp3 okhttp - 4.9.1 + 4.10.0 com.github.scribejava From d30eb248b82a30cd8404c2bf20c13e6a4a3020d4 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Fri, 16 Sep 2022 11:55:12 +0300 Subject: [PATCH 469/481] move some tests from blocked Facebook to vk.com to simplify release testing --- ...le.java => VkontakteAsyncApacheExample.java} | 17 +++++++++-------- ...mple.java => VkontakteAsyncNingExample.java} | 17 +++++++++-------- .../VkontakteClientCredentialsGrantExample.java | 2 +- .../apis/examples/VkontakteExample.java | 4 ++-- .../examples/VkontakteExternalHttpExample.java | 6 +++--- 5 files changed, 24 insertions(+), 22 deletions(-) rename scribejava-apis/src/test/java/com/github/scribejava/apis/examples/{FacebookAsyncApacheExample.java => VkontakteAsyncApacheExample.java} (89%) rename scribejava-apis/src/test/java/com/github/scribejava/apis/examples/{FacebookAsyncNingExample.java => VkontakteAsyncNingExample.java} (90%) diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteAsyncApacheExample.java similarity index 89% rename from scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java rename to scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteAsyncApacheExample.java index 29d8dba96..392348b2b 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncApacheExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteAsyncApacheExample.java @@ -3,7 +3,7 @@ import java.util.Random; import java.util.Scanner; import java.util.concurrent.ExecutionException; -import com.github.scribejava.apis.FacebookApi; +import com.github.scribejava.apis.VkontakteApi; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; @@ -13,12 +13,13 @@ import com.github.scribejava.httpclient.apache.ApacheHttpClientConfig; import java.io.IOException; -public class FacebookAsyncApacheExample { +public class VkontakteAsyncApacheExample { - private static final String NETWORK_NAME = "Facebook"; - private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v3.2/me"; + private static final String NETWORK_NAME = "vk.com"; + private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/users.get?v=" + + VkontakteApi.VERSION; - private FacebookAsyncApacheExample() { + private VkontakteAsyncApacheExample() { } @SuppressWarnings("PMD.SystemPrintln") @@ -28,11 +29,11 @@ public static void main(String... args) throws InterruptedException, ExecutionEx final String clientSecret = "your client secret"; final String secretState = "secret" + new Random().nextInt(999_999); - try (OAuth20Service service = new ServiceBuilder(clientId) + try ( OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .callback("http://www.example.com/oauth_callback/") .httpClientConfig(ApacheHttpClientConfig.defaultConfig()) - .build(FacebookApi.instance())) { + .build(VkontakteApi.instance())) { final Scanner in = new Scanner(System.in, "UTF-8"); System.out.println("=== " + NETWORK_NAME + "'s Async OAuth Workflow ==="); @@ -73,7 +74,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - try (Response response = service.execute(request)) { + try ( Response response = service.execute(request)) { System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getCode()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteAsyncNingExample.java similarity index 90% rename from scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java rename to scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteAsyncNingExample.java index 29c52cbad..bfb80d1a9 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookAsyncNingExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteAsyncNingExample.java @@ -5,7 +5,7 @@ import java.util.Random; import java.util.Scanner; import java.util.concurrent.ExecutionException; -import com.github.scribejava.apis.FacebookApi; +import com.github.scribejava.apis.VkontakteApi; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth2AccessToken; import com.github.scribejava.core.model.OAuthRequest; @@ -14,12 +14,13 @@ import com.github.scribejava.core.oauth.OAuth20Service; import java.io.IOException; -public class FacebookAsyncNingExample { +public class VkontakteAsyncNingExample { - private static final String NETWORK_NAME = "Facebook"; - private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/v3.2/me"; + private static final String NETWORK_NAME = "vk.com"; + private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/users.get?v=" + + VkontakteApi.VERSION; - private FacebookAsyncNingExample() { + private VkontakteAsyncNingExample() { } @SuppressWarnings("PMD.SystemPrintln") @@ -36,11 +37,11 @@ public static void main(String... args) throws InterruptedException, ExecutionEx .setReadTimeout(1_000) .build()); - try (OAuth20Service service = new ServiceBuilder(clientId) + try ( OAuth20Service service = new ServiceBuilder(clientId) .apiSecret(clientSecret) .callback("http://www.example.com/oauth_callback/") .httpClientConfig(clientConfig) - .build(FacebookApi.instance())) { + .build(VkontakteApi.instance())) { final Scanner in = new Scanner(System.in, "UTF-8"); System.out.println("=== " + NETWORK_NAME + "'s Async OAuth Workflow ==="); @@ -81,7 +82,7 @@ public static void main(String... args) throws InterruptedException, ExecutionEx System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - try (Response response = service.execute(request)) { + try ( Response response = service.execute(request)) { System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getCode()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java index 2b6e2d4f7..3e4d2d363 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteClientCredentialsGrantExample.java @@ -9,7 +9,7 @@ public class VkontakteClientCredentialsGrantExample { - private static final String NETWORK_NAME = "Vkontakte.ru"; + private static final String NETWORK_NAME = "vk.com>"; private VkontakteClientCredentialsGrantExample() { } diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java index baa4dae91..ca1a698bf 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExample.java @@ -15,7 +15,7 @@ public class VkontakteExample { - private static final String NETWORK_NAME = "Vkontakte.ru"; + private static final String NETWORK_NAME = "vk.com"; private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/users.get?v=" + VkontakteApi.VERSION; @@ -66,7 +66,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - try (Response response = service.execute(request)) { + try ( Response response = service.execute(request)) { System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getCode()); diff --git a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java index 7f9e0c969..fe5340294 100644 --- a/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java +++ b/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/VkontakteExternalHttpExample.java @@ -16,7 +16,7 @@ public class VkontakteExternalHttpExample { - private static final String NETWORK_NAME = "Vkontakte.ru"; + private static final String NETWORK_NAME = "vk.com"; private static final String PROTECTED_RESOURCE_URL = "https://api.vk.com/method/users.get?v=" + VkontakteApi.VERSION; @@ -37,7 +37,7 @@ public static void main(String... args) throws IOException, InterruptedException .setReadTimeout(1_000) .build(); //wrap it - try (DefaultAsyncHttpClient ahcHttpClient = new DefaultAsyncHttpClient(httpClientConfig)) { + try ( DefaultAsyncHttpClient ahcHttpClient = new DefaultAsyncHttpClient(httpClientConfig)) { //wrap it final AhcHttpClient wrappedAHCHttpClient = new AhcHttpClient(ahcHttpClient); @@ -74,7 +74,7 @@ public static void main(String... args) throws IOException, InterruptedException System.out.println("Now we're going to access a protected resource..."); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); service.signRequest(accessToken, request); - try (Response response = service.execute(request)) { + try ( Response response = service.execute(request)) { System.out.println("Got it! Lets see what we found..."); System.out.println(); System.out.println(response.getCode()); From 12c6b05b2839414bdaab1c3a70d9bc2d305f751a Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Mon, 19 Sep 2022 19:12:18 +0300 Subject: [PATCH 470/481] throw Throwable from callback (it got lost before) --- .../AbstractAsyncOnlyHttpClient.java | 75 ++++++++++++++++--- 1 file changed, 66 insertions(+), 9 deletions(-) diff --git a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java index 48917eb60..10b3d5faa 100644 --- a/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java +++ b/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/AbstractAsyncOnlyHttpClient.java @@ -1,6 +1,6 @@ package com.github.scribejava.core.httpclient; -import com.github.scribejava.core.model.OAuthRequest; +import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.Response; import com.github.scribejava.core.model.Verb; import java.io.File; @@ -14,8 +14,17 @@ public abstract class AbstractAsyncOnlyHttpClient implements HttpClient { public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, byte[] bodyContents) throws InterruptedException, ExecutionException, IOException { - return executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, null, - (OAuthRequest.ResponseConverter) null).get(); + final OAuthAsyncRequestThrowableHolderCallback oAuthAsyncRequestThrowableHolderCallback + = new OAuthAsyncRequestThrowableHolderCallback(); + + final Response response = executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, + oAuthAsyncRequestThrowableHolderCallback, null).get(); + + final Throwable throwable = oAuthAsyncRequestThrowableHolderCallback.getThrowable(); + if (throwable != null) { + throw new ExecutionException(throwable); + } + return response; } @Override @@ -23,23 +32,71 @@ public Response execute(String userAgent, Map headers, Verb http com.github.scribejava.core.httpclient.multipart.MultipartPayload bodyContents) throws InterruptedException, ExecutionException, IOException { - return executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, null, - (OAuthRequest.ResponseConverter) null).get(); + final OAuthAsyncRequestThrowableHolderCallback oAuthAsyncRequestThrowableHolderCallback + = new OAuthAsyncRequestThrowableHolderCallback(); + + final Response response = executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, + oAuthAsyncRequestThrowableHolderCallback, null).get(); + + final Throwable throwable = oAuthAsyncRequestThrowableHolderCallback.getThrowable(); + if (throwable != null) { + throw new ExecutionException(throwable); + } + + return response; } @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, String bodyContents) throws InterruptedException, ExecutionException, IOException { - return executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, null, - (OAuthRequest.ResponseConverter) null).get(); + final OAuthAsyncRequestThrowableHolderCallback oAuthAsyncRequestThrowableHolderCallback + = new OAuthAsyncRequestThrowableHolderCallback(); + + final Response response = executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, + oAuthAsyncRequestThrowableHolderCallback, null).get(); + + final Throwable throwable = oAuthAsyncRequestThrowableHolderCallback.getThrowable(); + if (throwable != null) { + throw new ExecutionException(throwable); + } + + return response; } @Override public Response execute(String userAgent, Map headers, Verb httpVerb, String completeUrl, File bodyContents) throws InterruptedException, ExecutionException, IOException { - return executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, null, - (OAuthRequest.ResponseConverter) null).get(); + final OAuthAsyncRequestThrowableHolderCallback oAuthAsyncRequestThrowableHolderCallback + = new OAuthAsyncRequestThrowableHolderCallback(); + + final Response response = executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, + oAuthAsyncRequestThrowableHolderCallback, null).get(); + + final Throwable throwable = oAuthAsyncRequestThrowableHolderCallback.getThrowable(); + if (throwable != null) { + throw new ExecutionException(throwable); + } + + return response; + } + + private class OAuthAsyncRequestThrowableHolderCallback implements OAuthAsyncRequestCallback { + + private Throwable throwable; + + @Override + public void onCompleted(Response response) { + } + + @Override + public void onThrowable(Throwable t) { + throwable = t; + } + + public Throwable getThrowable() { + return throwable; + } } } From 23890ecc89b1b08e6475eccbd0d931a6fcfaf51e Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 20 Sep 2022 12:09:11 +0300 Subject: [PATCH 471/481] set netty version in tests to run armeria examples (it requires newer netty version, than one comes by default) --- scribejava-apis/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index a9566dce7..bf8298172 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -50,6 +50,12 @@ ${project.version} test + + io.netty + netty-resolver + 4.1.81.Final + test + From 0f05e63e4c5d1740ad7862d398394ca03645888e Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 20 Sep 2022 12:15:20 +0300 Subject: [PATCH 472/481] remove old unused exclude element from checkstyle's config --- pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pom.xml b/pom.xml index b678ae06d..5e940b98f 100644 --- a/pom.xml +++ b/pom.xml @@ -208,7 +208,6 @@ validate validate - main/java/com/github/scribejava/core/java8/* ${basedir}/src From 8cb3790de9ce117d19deb1ed000a536726b34472 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Fri, 7 Oct 2022 19:17:35 +0300 Subject: [PATCH 473/481] update github urls in pom.xml --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 5e940b98f..03fc143b8 100644 --- a/pom.xml +++ b/pom.xml @@ -33,8 +33,8 @@ - scm:git:git://github.com/scribejava/scribejava.git - scm:git:git@github.com:scribejava/scribejava.git + scm:git:https://github.com/scribejava/scribejava + scm:git:https://github.com/scribejava/scribejava https://github.com/scribejava/scribejava HEAD From bda9ac69301cb961d536c8b4b69bd35819894ffe Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 21 Sep 2022 11:55:42 +0300 Subject: [PATCH 474/481] prepare v8.3.2 --- README.md | 4 ++-- changelog | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ef4083367..cf827a808 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 8.3.1 + 8.3.2 ``` @@ -146,7 +146,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 8.3.1 + 8.3.2 ``` diff --git a/changelog b/changelog index 0be0ed4b2..e50ae4ac6 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ -[SNAPSHOT] +[8.3.2] * minor fixes and enhances * update dependencies + * while using async HTTP client, you could miss some Throwables, now they will be thrown [8.3.1] * fix java.lang.NoClassDefFoundError for non-java8 runtimes (e.g. Android 7.1.1) From 466f37c6faf5a9a2de9c87ae1bce71b617a6185b Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Fri, 7 Oct 2022 19:23:18 +0300 Subject: [PATCH 475/481] [maven-release-plugin] prepare release scribejava-8.3.2 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- scribejava-java8/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 03fc143b8..fd271bdb0 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 8.3.2-SNAPSHOT + 8.3.2 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -36,7 +36,7 @@ scm:git:https://github.com/scribejava/scribejava scm:git:https://github.com/scribejava/scribejava https://github.com/scribejava/scribejava - HEAD + scribejava-8.3.2 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index bf8298172..232195b0e 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.2-SNAPSHOT + 8.3.2 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 7b5414eba..95d8ba4a3 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.2-SNAPSHOT + 8.3.2 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 04c2f8b06..369a3a33b 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.2-SNAPSHOT + 8.3.2 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 7e1ba089b..45e805048 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.2-SNAPSHOT + 8.3.2 ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 97b28e17f..ff8b9398b 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.2-SNAPSHOT + 8.3.2 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index a9de86702..8eb71bf36 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.2-SNAPSHOT + 8.3.2 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index d80798116..8ad92a707 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.2-SNAPSHOT + 8.3.2 ../pom.xml diff --git a/scribejava-java8/pom.xml b/scribejava-java8/pom.xml index d8e7c74bd..edf1ddc95 100644 --- a/scribejava-java8/pom.xml +++ b/scribejava-java8/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.2-SNAPSHOT + 8.3.2 ../pom.xml From fcd3f46ee27bac14984ce500cd6b344273eb0b09 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Fri, 7 Oct 2022 19:24:29 +0300 Subject: [PATCH 476/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- scribejava-java8/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index fd271bdb0..cb7383ac8 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 8.3.2 + 8.3.3-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -36,7 +36,7 @@ scm:git:https://github.com/scribejava/scribejava scm:git:https://github.com/scribejava/scribejava https://github.com/scribejava/scribejava - scribejava-8.3.2 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 232195b0e..0162c0442 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.2 + 8.3.3-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 95d8ba4a3..a6a76e9b7 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.2 + 8.3.3-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 369a3a33b..69eeed503 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.2 + 8.3.3-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 45e805048..32fe5a3c8 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.2 + 8.3.3-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index ff8b9398b..5906c70d1 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.2 + 8.3.3-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 8eb71bf36..7ae81ea08 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.2 + 8.3.3-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 8ad92a707..a8952a93b 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.2 + 8.3.3-SNAPSHOT ../pom.xml diff --git a/scribejava-java8/pom.xml b/scribejava-java8/pom.xml index edf1ddc95..37a0c1388 100644 --- a/scribejava-java8/pom.xml +++ b/scribejava-java8/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.2 + 8.3.3-SNAPSHOT ../pom.xml From 77e0b8db7ae4f6337c2bb53d6c7d3f2e6805be9a Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 15 Nov 2022 17:32:04 +0300 Subject: [PATCH 477/481] update dependencies, including security updates in libraries --- changelog | 3 +++ pom.xml | 10 +++++----- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 4 ++-- scribejava-httpclient-ning/pom.xml | 2 +- 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/changelog b/changelog index e50ae4ac6..468003681 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +[SNAPSHOT] + * update dependencies, including security updates in libraries + [8.3.2] * minor fixes and enhances * update dependencies diff --git a/pom.xml b/pom.xml index cb7383ac8..64476229a 100644 --- a/pom.xml +++ b/pom.xml @@ -55,7 +55,7 @@ com.fasterxml.jackson.core jackson-databind - 2.13.4 + 2.14.0 junit @@ -90,7 +90,7 @@ org.apache.maven.plugins maven-jar-plugin - 3.2.2 + 3.3.0 ${project.build.outputDirectory}/META-INF/MANIFEST.MF @@ -105,7 +105,7 @@ com.puppycrawl.tools checkstyle - 8.42 + 10.4 @@ -224,7 +224,7 @@ org.apache.maven.plugins maven-pmd-plugin - 3.16.0 + 3.19.0 net.sourceforge.pmd @@ -270,7 +270,7 @@ 7 - 6.34.0 + 6.51.0 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index 0162c0442..ed2530193 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -53,7 +53,7 @@ io.netty netty-resolver - 4.1.81.Final + 4.1.84.Final test diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index a6a76e9b7..429c424f7 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -29,7 +29,7 @@ jakarta.xml.bind jakarta.xml.bind-api - 3.0.1 + 4.0.0 true diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 69eeed503..eaf6a40f5 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -23,7 +23,7 @@ org.slf4j slf4j-simple - 2.0.0 + 2.0.3 test diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 5906c70d1..754531885 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -23,13 +23,13 @@ org.slf4j slf4j-simple - 2.0.0 + 2.0.3 test com.linecorp.armeria armeria - 1.18.0 + 1.20.2 com.github.scribejava diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 7ae81ea08..d4a1de13f 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -23,7 +23,7 @@ org.slf4j slf4j-simple - 2.0.0 + 2.0.3 test From 763a959f7b05ba5b9d3dabb39c8cd6511299c419 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 15 Nov 2022 18:24:27 +0300 Subject: [PATCH 478/481] [maven-release-plugin] prepare release scribejava-8.3.3 --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- scribejava-java8/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 64476229a..b438813a2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 8.3.3-SNAPSHOT + 8.3.3 ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -36,7 +36,7 @@ scm:git:https://github.com/scribejava/scribejava scm:git:https://github.com/scribejava/scribejava https://github.com/scribejava/scribejava - HEAD + scribejava-8.3.3 diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index ed2530193..e0899df6b 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.3-SNAPSHOT + 8.3.3 ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 429c424f7..237d120c8 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.3-SNAPSHOT + 8.3.3 ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index eaf6a40f5..91bbdf24e 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.3-SNAPSHOT + 8.3.3 ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index 32fe5a3c8..bfe1b5efc 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.3-SNAPSHOT + 8.3.3 ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index 754531885..d01d73561 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.3-SNAPSHOT + 8.3.3 ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index d4a1de13f..303e8b45d 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.3-SNAPSHOT + 8.3.3 ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index a8952a93b..6c6ac6e60 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.3-SNAPSHOT + 8.3.3 ../pom.xml diff --git a/scribejava-java8/pom.xml b/scribejava-java8/pom.xml index 37a0c1388..27da11d77 100644 --- a/scribejava-java8/pom.xml +++ b/scribejava-java8/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.3-SNAPSHOT + 8.3.3 ../pom.xml From 314d431b10a6be586668a3e1e755545a5f6a28e2 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 15 Nov 2022 18:30:57 +0300 Subject: [PATCH 479/481] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- scribejava-apis/pom.xml | 2 +- scribejava-core/pom.xml | 2 +- scribejava-httpclient-ahc/pom.xml | 2 +- scribejava-httpclient-apache/pom.xml | 2 +- scribejava-httpclient-armeria/pom.xml | 2 +- scribejava-httpclient-ning/pom.xml | 2 +- scribejava-httpclient-okhttp/pom.xml | 2 +- scribejava-java8/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index b438813a2..b484b6a71 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.scribejava scribejava pom - 8.3.3 + 8.3.4-SNAPSHOT ScribeJava OAuth Library The best OAuth library out there https://github.com/scribejava/scribejava @@ -36,7 +36,7 @@ scm:git:https://github.com/scribejava/scribejava scm:git:https://github.com/scribejava/scribejava https://github.com/scribejava/scribejava - scribejava-8.3.3 + HEAD diff --git a/scribejava-apis/pom.xml b/scribejava-apis/pom.xml index e0899df6b..4e51bb8b5 100644 --- a/scribejava-apis/pom.xml +++ b/scribejava-apis/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.3 + 8.3.4-SNAPSHOT ../pom.xml diff --git a/scribejava-core/pom.xml b/scribejava-core/pom.xml index 237d120c8..d5fbfc488 100644 --- a/scribejava-core/pom.xml +++ b/scribejava-core/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.3 + 8.3.4-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ahc/pom.xml b/scribejava-httpclient-ahc/pom.xml index 91bbdf24e..fabd225c3 100644 --- a/scribejava-httpclient-ahc/pom.xml +++ b/scribejava-httpclient-ahc/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.3 + 8.3.4-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-apache/pom.xml b/scribejava-httpclient-apache/pom.xml index bfe1b5efc..1dc9dd53c 100644 --- a/scribejava-httpclient-apache/pom.xml +++ b/scribejava-httpclient-apache/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.3 + 8.3.4-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-armeria/pom.xml b/scribejava-httpclient-armeria/pom.xml index d01d73561..54e58c619 100644 --- a/scribejava-httpclient-armeria/pom.xml +++ b/scribejava-httpclient-armeria/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.3 + 8.3.4-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-ning/pom.xml b/scribejava-httpclient-ning/pom.xml index 303e8b45d..39696d698 100644 --- a/scribejava-httpclient-ning/pom.xml +++ b/scribejava-httpclient-ning/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.3 + 8.3.4-SNAPSHOT ../pom.xml diff --git a/scribejava-httpclient-okhttp/pom.xml b/scribejava-httpclient-okhttp/pom.xml index 6c6ac6e60..59bc2bffc 100644 --- a/scribejava-httpclient-okhttp/pom.xml +++ b/scribejava-httpclient-okhttp/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.3 + 8.3.4-SNAPSHOT ../pom.xml diff --git a/scribejava-java8/pom.xml b/scribejava-java8/pom.xml index 27da11d77..b75f6d2de 100644 --- a/scribejava-java8/pom.xml +++ b/scribejava-java8/pom.xml @@ -5,7 +5,7 @@ com.github.scribejava scribejava - 8.3.3 + 8.3.4-SNAPSHOT ../pom.xml From 9112e0b9c4eafc521299f68b1fda96b4f304c6e3 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 25 Jan 2023 19:24:36 +0300 Subject: [PATCH 480/481] update changelog and README.md to reflect already released v8.3.3 --- README.md | 4 ++-- changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cf827a808..7abc0854a 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ You can pull ScribeJava from the central maven repository, just add these to you com.github.scribejava scribejava-apis - 8.3.2 + 8.3.3 ``` @@ -146,7 +146,7 @@ And in case you need just core classes (that's it, without any external API (FB, com.github.scribejava scribejava-core - 8.3.2 + 8.3.3 ``` diff --git a/changelog b/changelog index 468003681..e962e073b 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,4 @@ -[SNAPSHOT] +[8.3.3] * update dependencies, including security updates in libraries [8.3.2] From 8970e8eeb0aff840d0b223890e9c392ee19218f7 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Fri, 23 Feb 2024 16:11:39 +0300 Subject: [PATCH 481/481] Update donate.md --- donate.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/donate.md b/donate.md index 829e9a635..99d3686dc 100644 --- a/donate.md +++ b/donate.md @@ -2,16 +2,9 @@ You can now help ScribeJava not only by Pull Requests. You can use [https://www.paypal.com/paypalme/algr453](https://www.paypal.com/paypalme/algr453) directly. -
    Donation button for monthly donations or donations by card (VISA, MasterCard, etc) may not be working, but you can try... - -Donation button from PayPal: [![Donate with PayPal button](https://www.paypalobjects.com/en_US/RU/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=E3XAUM2ET2R3Y&source=url) - -or old link [https://paypal.me/kullfar](https://paypal.me/kullfar) -
    - Thanks in advance! -ps.If you can't for any reason use above methods, let me know, we will find the way out. +ps.If you can't for any reason use above method, let me know, we will find the way out. Hall of fame "Donors" (in alphabetical order, if you don't want to be here, just put a note along with the donation):
    1.Douglas Ross from USA