From 43ce7ed67a58882294f78337ce6c267346aa2562 Mon Sep 17 00:00:00 2001 From: Petr Kopotev Date: Thu, 7 May 2020 13:22:17 +0300 Subject: [PATCH 01/67] 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 788389b8cb9addfce956f051f9f6d645cc03d329 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 10 Nov 2020 12:13:36 +0300 Subject: [PATCH 02/67] [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 03/67] 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 04/67] 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 05/67] 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 06/67] 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 07/67] 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 08/67] 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 09/67] 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 10/67] [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 11/67] [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 12/67] 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 13/67] 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 14/67] 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 15/67] 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 16/67] 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 17/67] 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 18/67] 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 19/67] 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 20/67] 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 21/67] 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 22/67] 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 23/67] 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 24/67] 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 25/67] 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 26/67] 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 27/67] 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 28/67] [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 29/67] [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 30/67] 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 31/67] * 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 32/67] 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 33/67] 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 34/67] [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 35/67] [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 36/67] * 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 37/67] 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 38/67] 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 39/67] [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 40/67] [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 41/67] 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 42/67] 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 43/67] 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 44/67] 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 45/67] 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 46/67] [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 47/67] 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 48/67] 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 49/67] 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 50/67] 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 51/67] 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 52/67] 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 53/67] 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 54/67] 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 55/67] 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 56/67] 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 57/67] 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 58/67] 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 59/67] 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 60/67] 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 61/67] [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 62/67] [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 63/67] 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 64/67] [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 65/67] [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 66/67] 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 67/67] 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